aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.mailmap2
-rw-r--r--Documentation/ABI/testing/sysfs-class-mtd51
-rw-r--r--Documentation/CodingStyle16
-rw-r--r--Documentation/DocBook/mtdnand.tmpl2
-rw-r--r--Documentation/arm/OMAP/DSS46
-rw-r--r--Documentation/devicetree/bindings/mtd/gpmi-nand.txt33
-rw-r--r--Documentation/devicetree/bindings/mtd/mxc-nand.txt19
-rw-r--r--Documentation/filesystems/Locking3
-rw-r--r--Documentation/filesystems/proc.txt23
-rw-r--r--Documentation/filesystems/vfs.txt4
-rw-r--r--Documentation/sysctl/fs.txt7
-rw-r--r--Documentation/vm/pagemap.txt2
-rw-r--r--Documentation/vm/slub.txt2
-rw-r--r--Documentation/x86/efi-stub.txt65
-rw-r--r--arch/alpha/include/asm/posix_types.h3
-rw-r--r--arch/alpha/kernel/signal.c20
-rw-r--r--arch/arm/boot/dts/db8500.dtsi204
-rw-r--r--arch/arm/boot/dts/imx27.dtsi9
-rw-r--r--arch/arm/boot/dts/snowball.dts32
-rw-r--r--arch/arm/configs/u8500_defconfig1
-rw-r--r--arch/arm/include/asm/posix_types.h3
-rw-r--r--arch/arm/kernel/signal.c49
-rw-r--r--arch/arm/kernel/smp.c8
-rw-r--r--arch/arm/mach-ep93xx/snappercl15.c4
-rw-r--r--arch/arm/mach-ep93xx/ts72xx.c3
-rw-r--r--arch/arm/mach-exynos/mach-nuri.c26
-rw-r--r--arch/arm/mach-exynos/mach-origen.c24
-rw-r--r--arch/arm/mach-exynos/mach-smdkv310.c28
-rw-r--r--arch/arm/mach-exynos/mach-universal_c210.c26
-rw-r--r--arch/arm/mach-imx/imx27-dt.c1
-rw-r--r--arch/arm/mach-ixp4xx/ixdp425-setup.c4
-rw-r--r--arch/arm/mach-nomadik/board-nhk8815.c2
-rw-r--r--arch/arm/mach-omap1/board-fsample.c3
-rw-r--r--arch/arm/mach-omap1/board-h2.c3
-rw-r--r--arch/arm/mach-omap1/board-h3.c3
-rw-r--r--arch/arm/mach-omap1/board-perseus2.c3
-rw-r--r--arch/arm/mach-omap2/display.c196
-rw-r--r--arch/arm/mach-omap2/gpmc.c184
-rw-r--r--arch/arm/mach-orion5x/ts78xx-setup.c3
-rw-r--r--arch/arm/mach-pxa/balloon3.c3
-rw-r--r--arch/arm/mach-pxa/em-x270.c3
-rw-r--r--arch/arm/mach-pxa/palmtx.c3
-rw-r--r--arch/arm/mach-s3c24xx/mach-smdk2416.c27
-rw-r--r--arch/arm/mach-s3c64xx/mach-anw6410.c25
-rw-r--r--arch/arm/mach-s3c64xx/mach-crag6410.c25
-rw-r--r--arch/arm/mach-s3c64xx/mach-hmt.c24
-rw-r--r--arch/arm/mach-s3c64xx/mach-mini6410.c92
-rw-r--r--arch/arm/mach-s3c64xx/mach-real6410.c90
-rw-r--r--arch/arm/mach-s3c64xx/mach-smartq5.c26
-rw-r--r--arch/arm/mach-s3c64xx/mach-smartq7.c26
-rw-r--r--arch/arm/mach-s3c64xx/mach-smdk6410.c25
-rw-r--r--arch/arm/mach-s5p64x0/mach-smdk6440.c24
-rw-r--r--arch/arm/mach-s5p64x0/mach-smdk6450.c24
-rw-r--r--arch/arm/mach-s5pc100/mach-smdkc100.c27
-rw-r--r--arch/arm/mach-s5pv210/mach-aquila.c36
-rw-r--r--arch/arm/mach-s5pv210/mach-goni.c26
-rw-r--r--arch/arm/mach-s5pv210/mach-smdkv210.c24
-rw-r--r--arch/arm/mach-ux500/board-mop500-uib.c4
-rw-r--r--arch/arm/mach-ux500/board-mop500.c32
-rw-r--r--arch/arm/mach-ux500/board-mop500.h4
-rw-r--r--arch/arm/mach-ux500/cpu-db8500.c25
-rw-r--r--arch/arm/plat-omap/include/plat/gpmc.h11
-rw-r--r--arch/arm/plat-samsung/include/plat/fb.h11
-rw-r--r--arch/avr32/include/asm/posix_types.h3
-rw-r--r--arch/avr32/kernel/entry-avr32b.S4
-rw-r--r--arch/avr32/kernel/signal.c43
-rw-r--r--arch/blackfin/include/asm/posix_types.h3
-rw-r--r--arch/blackfin/include/asm/thread_info.h2
-rw-r--r--arch/blackfin/kernel/signal.c69
-rw-r--r--arch/blackfin/kernel/trace.c32
-rw-r--r--arch/blackfin/mach-bf561/boards/acvilon.c3
-rw-r--r--arch/blackfin/mach-common/entry.S2
-rw-r--r--arch/c6x/kernel/signal.c45
-rw-r--r--arch/cris/arch-v10/kernel/signal.c34
-rw-r--r--arch/cris/arch-v32/kernel/signal.c36
-rw-r--r--arch/cris/include/asm/posix_types.h3
-rw-r--r--arch/cris/kernel/ptrace.c2
-rw-r--r--arch/frv/include/asm/posix_types.h3
-rw-r--r--arch/frv/include/asm/thread_info.h16
-rw-r--r--arch/frv/kernel/entry.S29
-rw-r--r--arch/frv/kernel/signal.c59
-rw-r--r--arch/h8300/include/asm/posix_types.h3
-rw-r--r--arch/h8300/kernel/signal.c30
-rw-r--r--arch/hexagon/kernel/signal.c50
-rw-r--r--arch/ia64/include/asm/posix_types.h3
-rw-r--r--arch/ia64/include/asm/thread_info.h18
-rw-r--r--arch/ia64/kernel/perfmon.c10
-rw-r--r--arch/ia64/kernel/process.c2
-rw-r--r--arch/ia64/kernel/signal.c34
-rw-r--r--arch/ia64/kernel/sys_ia64.c19
-rw-r--r--arch/m32r/include/asm/posix_types.h3
-rw-r--r--arch/m32r/kernel/signal.c34
-rw-r--r--arch/m68k/include/asm/posix_types.h3
-rw-r--r--arch/m68k/kernel/signal.c29
-rw-r--r--arch/microblaze/include/asm/thread_info.h18
-rw-r--r--arch/microblaze/kernel/signal.c41
-rw-r--r--arch/mips/alchemy/devboards/db1200.c3
-rw-r--r--arch/mips/alchemy/devboards/db1300.c3
-rw-r--r--arch/mips/alchemy/devboards/db1550.c3
-rw-r--r--arch/mips/include/asm/posix_types.h5
-rw-r--r--arch/mips/include/asm/stat.h6
-rw-r--r--arch/mips/kernel/signal-common.h2
-rw-r--r--arch/mips/kernel/signal.c40
-rw-r--r--arch/mips/kernel/signal32.c2
-rw-r--r--arch/mips/kernel/signal_n32.c1
-rw-r--r--arch/mips/pnx833x/common/platform.c6
-rw-r--r--arch/mips/rb532/devices.c1
-rw-r--r--arch/mn10300/include/asm/posix_types.h3
-rw-r--r--arch/mn10300/kernel/signal.c41
-rw-r--r--arch/openrisc/kernel/signal.c42
-rw-r--r--arch/parisc/include/asm/posix_types.h3
-rw-r--r--arch/parisc/include/asm/stat.h4
-rw-r--r--arch/parisc/include/asm/thread_info.h2
-rw-r--r--arch/parisc/kernel/entry.S4
-rw-r--r--arch/parisc/kernel/signal.c49
-rw-r--r--arch/parisc/kernel/signal32.c2
-rw-r--r--arch/powerpc/include/asm/posix_types.h3
-rw-r--r--arch/powerpc/include/asm/stat.h4
-rw-r--r--arch/powerpc/include/asm/thread_info.h18
-rw-r--r--arch/powerpc/kernel/signal.c38
-rw-r--r--arch/powerpc/kernel/signal.h3
-rw-r--r--arch/powerpc/kernel/signal_32.c4
-rw-r--r--arch/powerpc/kernel/signal_64.c4
-rw-r--r--arch/powerpc/mm/mmu_context_nohash.c11
-rw-r--r--arch/s390/include/asm/posix_types.h3
-rw-r--r--arch/s390/kernel/compat_signal.c12
-rw-r--r--arch/s390/kernel/entry.h2
-rw-r--r--arch/s390/kernel/signal.c49
-rw-r--r--arch/score/kernel/signal.c42
-rw-r--r--arch/sh/boards/mach-migor/setup.c1
-rw-r--r--arch/sh/include/asm/posix_types_32.h2
-rw-r--r--arch/sh/include/asm/posix_types_64.h2
-rw-r--r--arch/sh/include/asm/thread_info.h19
-rw-r--r--arch/sh/kernel/signal_32.c45
-rw-r--r--arch/sh/kernel/signal_64.c49
-rw-r--r--arch/sh/kernel/smp.c7
-rw-r--r--arch/sparc/include/asm/posix_types.h5
-rw-r--r--arch/sparc/include/asm/thread_info_32.h3
-rw-r--r--arch/sparc/include/asm/thread_info_64.h18
-rw-r--r--arch/sparc/kernel/signal32.c27
-rw-r--r--arch/sparc/kernel/signal_32.c41
-rw-r--r--arch/sparc/kernel/signal_64.c36
-rw-r--r--arch/sparc/kernel/sys_sparc_64.c11
-rw-r--r--arch/tile/include/asm/compat.h1
-rw-r--r--arch/tile/include/asm/thread_info.h18
-rw-r--r--arch/tile/kernel/compat_signal.c3
-rw-r--r--arch/tile/kernel/process.c2
-rw-r--r--arch/tile/kernel/signal.c42
-rw-r--r--arch/um/include/shared/frame_kern.h3
-rw-r--r--arch/um/kernel/process.c5
-rw-r--r--arch/um/kernel/reboot.c13
-rw-r--r--arch/um/kernel/signal.c37
-rw-r--r--arch/um/kernel/trap.c24
-rw-r--r--arch/unicore32/kernel/signal.c49
-rw-r--r--arch/x86/Kconfig2
-rw-r--r--arch/x86/boot/compressed/eboot.c87
-rw-r--r--arch/x86/boot/compressed/eboot.h6
-rw-r--r--arch/x86/ia32/ia32_signal.c2
-rw-r--r--arch/x86/include/asm/ftrace.h2
-rw-r--r--arch/x86/include/asm/posix_types_32.h3
-rw-r--r--arch/x86/include/asm/sighandling.h2
-rw-r--r--arch/x86/include/asm/thread_info.h18
-rw-r--r--arch/x86/kernel/cpu/common.c8
-rw-r--r--arch/x86/kernel/entry_32.S13
-rw-r--r--arch/x86/kernel/entry_64.S44
-rw-r--r--arch/x86/kernel/ftrace.c102
-rw-r--r--arch/x86/kernel/nmi.c6
-rw-r--r--arch/x86/kernel/ptrace.c6
-rw-r--r--arch/x86/kernel/signal.c62
-rw-r--r--arch/x86/kernel/traps.c8
-rw-r--r--arch/x86/syscalls/syscall_32.tbl1
-rw-r--r--arch/x86/syscalls/syscall_64.tbl2
-rw-r--r--arch/x86/um/signal.c2
-rw-r--r--arch/xtensa/kernel/signal.c26
-rw-r--r--drivers/base/soc.c2
-rw-r--r--drivers/gpu/drm/cirrus/cirrus_drv.c19
-rw-r--r--drivers/gpu/drm/cirrus/cirrus_drv.h2
-rw-r--r--drivers/gpu/drm/cirrus/cirrus_ttm.c5
-rw-r--r--drivers/gpu/drm/drm_edid.c11
-rw-r--r--drivers/gpu/drm/i810/i810_dma.c4
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h3
-rw-r--r--drivers/gpu/drm/i915/i915_gem_dmabuf.c61
-rw-r--r--drivers/gpu/drm/mgag200/mgag200_drv.c19
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drv.h3
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_prime.c45
-rw-r--r--drivers/gpu/drm/radeon/evergreen.c382
-rw-r--r--drivers/gpu/drm/radeon/evergreend.h11
-rw-r--r--drivers/gpu/drm/radeon/ni.c360
-rw-r--r--drivers/gpu/drm/radeon/nid.h11
-rw-r--r--drivers/gpu/drm/radeon/r600.c199
-rw-r--r--drivers/gpu/drm/radeon/r600d.h2
-rw-r--r--drivers/gpu/drm/radeon/radeon.h8
-rw-r--r--drivers/gpu/drm/radeon/radeon_cs.c31
-rw-r--r--drivers/gpu/drm/radeon/radeon_prime.c44
-rw-r--r--drivers/gpu/drm/radeon/rv770.c274
-rw-r--r--drivers/gpu/drm/radeon/rv770d.h4
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c1
-rw-r--r--drivers/gpu/drm/udl/udl_fb.c13
-rw-r--r--drivers/gpu/drm/udl/udl_gem.c25
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_gmr.c2
-rw-r--r--drivers/message/fusion/mptbase.c12
-rw-r--r--drivers/message/fusion/mptctl.c4
-rw-r--r--drivers/mfd/db8500-prcmu.c1
-rw-r--r--drivers/mtd/Kconfig2
-rw-r--r--drivers/mtd/bcm63xxpart.c41
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c18
-rw-r--r--drivers/mtd/cmdlinepart.c2
-rw-r--r--drivers/mtd/devices/block2mtd.c7
-rw-r--r--drivers/mtd/devices/docg3.c40
-rw-r--r--drivers/mtd/devices/m25p80.c5
-rw-r--r--drivers/mtd/devices/spear_smi.c14
-rw-r--r--drivers/mtd/lpddr/qinfo_probe.c2
-rw-r--r--drivers/mtd/maps/Kconfig2
-rw-r--r--drivers/mtd/maps/intel_vr_nor.c13
-rw-r--r--drivers/mtd/maps/pci.c13
-rw-r--r--drivers/mtd/maps/scb2_flash.c15
-rw-r--r--drivers/mtd/maps/wr_sbc82xx_flash.c2
-rw-r--r--drivers/mtd/mtdcore.c57
-rw-r--r--drivers/mtd/mtdpart.c14
-rw-r--r--drivers/mtd/nand/Kconfig42
-rw-r--r--drivers/mtd/nand/alauda.c4
-rw-r--r--drivers/mtd/nand/atmel_nand.c14
-rw-r--r--drivers/mtd/nand/au1550nd.c2
-rw-r--r--drivers/mtd/nand/bcm_umi_bch.c14
-rw-r--r--drivers/mtd/nand/bcm_umi_nand.c9
-rw-r--r--drivers/mtd/nand/bf5xx_nand.c4
-rw-r--r--drivers/mtd/nand/cafe_nand.c35
-rw-r--r--drivers/mtd/nand/cs553x_nand.c1
-rw-r--r--drivers/mtd/nand/denali.c38
-rw-r--r--drivers/mtd/nand/docg4.c22
-rw-r--r--drivers/mtd/nand/fsl_elbc_nand.c37
-rw-r--r--drivers/mtd/nand/fsl_ifc_nand.c47
-rw-r--r--drivers/mtd/nand/fsmc_nand.c26
-rw-r--r--drivers/mtd/nand/gpmi-nand/bch-regs.h42
-rw-r--r--drivers/mtd/nand/gpmi-nand/gpmi-lib.c27
-rw-r--r--drivers/mtd/nand/gpmi-nand/gpmi-nand.c184
-rw-r--r--drivers/mtd/nand/gpmi-nand/gpmi-nand.h6
-rw-r--r--drivers/mtd/nand/h1910.c1
-rw-r--r--drivers/mtd/nand/jz4740_nand.c6
-rw-r--r--drivers/mtd/nand/mpc5121_nfc.c1
-rw-r--r--drivers/mtd/nand/mxc_nand.c636
-rw-r--r--drivers/mtd/nand/nand_base.c233
-rw-r--r--drivers/mtd/nand/nand_bbt.c1
-rw-r--r--drivers/mtd/nand/nand_ids.c6
-rw-r--r--drivers/mtd/nand/nandsim.c28
-rw-r--r--drivers/mtd/nand/omap2.c253
-rw-r--r--drivers/mtd/nand/pasemi_nand.c1
-rw-r--r--drivers/mtd/nand/plat_nand.c28
-rw-r--r--drivers/mtd/nand/pxa3xx_nand.c6
-rw-r--r--drivers/mtd/nand/r852.c22
-rw-r--r--drivers/mtd/nand/sh_flctl.c8
-rw-r--r--drivers/mtd/nand/sm_common.c9
-rw-r--r--drivers/mtd/onenand/onenand_base.c6
-rw-r--r--drivers/pinctrl/pinctrl-nomadik.c20
-rw-r--r--drivers/platform/x86/acer-wmi.c24
-rw-r--r--drivers/platform/x86/apple-gmux.c4
-rw-r--r--drivers/platform/x86/dell-laptop.c308
-rw-r--r--drivers/platform/x86/fujitsu-tablet.c34
-rw-r--r--drivers/platform/x86/hdaps.c2
-rw-r--r--drivers/platform/x86/hp-wmi.c10
-rw-r--r--drivers/platform/x86/ideapad-laptop.c9
-rw-r--r--drivers/platform/x86/sony-laptop.c1498
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c2
-rw-r--r--drivers/platform/x86/toshiba_acpi.c141
-rw-r--r--drivers/platform/x86/xo1-rfkill.c13
-rw-r--r--drivers/rapidio/Kconfig14
-rw-r--r--drivers/rapidio/devices/Makefile3
-rw-r--r--drivers/rapidio/devices/tsi721.c211
-rw-r--r--drivers/rapidio/devices/tsi721.h105
-rw-r--r--drivers/rapidio/devices/tsi721_dma.c823
-rw-r--r--drivers/rapidio/rio.c81
-rw-r--r--drivers/tty/amiserial.c14
-rw-r--r--drivers/tty/cyclades.c2
-rw-r--r--drivers/tty/n_r3964.c11
-rw-r--r--drivers/tty/pty.c25
-rw-r--r--drivers/tty/serial/crisv10.c8
-rw-r--r--drivers/tty/synclink.c4
-rw-r--r--drivers/tty/synclink_gt.c4
-rw-r--r--drivers/tty/synclinkmp.c4
-rw-r--r--drivers/tty/tty_io.c67
-rw-r--r--drivers/tty/tty_ldisc.c67
-rw-r--r--drivers/tty/tty_mutex.c71
-rw-r--r--drivers/tty/tty_port.c6
-rw-r--r--drivers/video/Kconfig35
-rw-r--r--drivers/video/Makefile3
-rw-r--r--drivers/video/auo_k1900fb.c198
-rw-r--r--drivers/video/auo_k1901fb.c251
-rw-r--r--drivers/video/auo_k190x.c1046
-rw-r--r--drivers/video/auo_k190x.h129
-rw-r--r--drivers/video/bfin_adv7393fb.c43
-rw-r--r--drivers/video/cobalt_lcdfb.c45
-rw-r--r--drivers/video/ep93xx-fb.c32
-rw-r--r--drivers/video/exynos/exynos_dp_core.c69
-rw-r--r--drivers/video/exynos/exynos_dp_core.h3
-rw-r--r--drivers/video/exynos/exynos_dp_reg.c45
-rw-r--r--drivers/video/exynos/exynos_dp_reg.h29
-rw-r--r--drivers/video/exynos/exynos_mipi_dsi.c49
-rw-r--r--drivers/video/exynos/exynos_mipi_dsi_common.c36
-rw-r--r--drivers/video/exynos/s6e8ax0.c15
-rw-r--r--drivers/video/fb_defio.c6
-rw-r--r--drivers/video/fbsysfs.c2
-rw-r--r--drivers/video/fsl-diu-fb.c1
-rw-r--r--drivers/video/intelfb/intelfbdrv.c2
-rw-r--r--drivers/video/mb862xx/mb862xx-i2c.c2
-rw-r--r--drivers/video/mb862xx/mb862xxfbdrv.c2
-rw-r--r--drivers/video/mbx/mbxfb.c2
-rw-r--r--drivers/video/mxsfb.c13
-rw-r--r--drivers/video/omap/Kconfig8
-rw-r--r--drivers/video/omap2/displays/panel-acx565akm.c7
-rw-r--r--drivers/video/omap2/displays/panel-generic-dpi.c107
-rw-r--r--drivers/video/omap2/displays/panel-n8x0.c8
-rw-r--r--drivers/video/omap2/displays/panel-taal.c88
-rw-r--r--drivers/video/omap2/displays/panel-tfp410.c76
-rw-r--r--drivers/video/omap2/displays/panel-tpo-td043mtea1.c22
-rw-r--r--drivers/video/omap2/dss/Kconfig13
-rw-r--r--drivers/video/omap2/dss/apply.c134
-rw-r--r--drivers/video/omap2/dss/core.c255
-rw-r--r--drivers/video/omap2/dss/dispc.c747
-rw-r--r--drivers/video/omap2/dss/dispc.h72
-rw-r--r--drivers/video/omap2/dss/display.c49
-rw-r--r--drivers/video/omap2/dss/dpi.c75
-rw-r--r--drivers/video/omap2/dss/dsi.c404
-rw-r--r--drivers/video/omap2/dss/dss.c65
-rw-r--r--drivers/video/omap2/dss/dss.h151
-rw-r--r--drivers/video/omap2/dss/dss_features.c30
-rw-r--r--drivers/video/omap2/dss/dss_features.h5
-rw-r--r--drivers/video/omap2/dss/hdmi.c443
-rw-r--r--drivers/video/omap2/dss/hdmi_panel.c236
-rw-r--r--drivers/video/omap2/dss/manager.c19
-rw-r--r--drivers/video/omap2/dss/overlay.c16
-rw-r--r--drivers/video/omap2/dss/rfbi.c84
-rw-r--r--drivers/video/omap2/dss/sdi.c63
-rw-r--r--drivers/video/omap2/dss/ti_hdmi.h32
-rw-r--r--drivers/video/omap2/dss/ti_hdmi_4xxx_ip.c480
-rw-r--r--drivers/video/omap2/dss/ti_hdmi_4xxx_ip.h161
-rw-r--r--drivers/video/omap2/dss/venc.c133
-rw-r--r--drivers/video/omap2/omapfb/omapfb-ioctl.c17
-rw-r--r--drivers/video/omap2/omapfb/omapfb-main.c12
-rw-r--r--drivers/video/omap2/omapfb/omapfb.h1
-rw-r--r--drivers/video/omap2/vrfb.c4
-rw-r--r--drivers/video/pxa3xx-gcu.c5
-rw-r--r--drivers/video/s3c-fb.c148
-rw-r--r--drivers/video/sh_mobile_hdmi.c219
-rw-r--r--drivers/video/sis/init.h45
-rw-r--r--drivers/video/sis/sis_main.c41
-rw-r--r--drivers/video/skeletonfb.c2
-rw-r--r--drivers/video/smscufx.c4
-rw-r--r--drivers/video/udlfb.c2
-rw-r--r--drivers/video/via/viafbdev.c34
-rw-r--r--fs/9p/vfs_inode_dotl.c24
-rw-r--r--fs/affs/affs.h8
-rw-r--r--fs/aio.c10
-rw-r--r--fs/attr.c5
-rw-r--r--fs/binfmt_elf.c8
-rw-r--r--fs/binfmt_flat.c8
-rw-r--r--fs/btrfs/acl.c4
-rw-r--r--fs/btrfs/backref.c495
-rw-r--r--fs/btrfs/backref.h3
-rw-r--r--fs/btrfs/btrfs_inode.h50
-rw-r--r--fs/btrfs/check-integrity.c584
-rw-r--r--fs/btrfs/ctree.c861
-rw-r--r--fs/btrfs/ctree.h78
-rw-r--r--fs/btrfs/delayed-inode.c8
-rw-r--r--fs/btrfs/delayed-ref.c10
-rw-r--r--fs/btrfs/delayed-ref.h24
-rw-r--r--fs/btrfs/disk-io.c57
-rw-r--r--fs/btrfs/disk-io.h1
-rw-r--r--fs/btrfs/export.c15
-rw-r--r--fs/btrfs/extent-tree.c23
-rw-r--r--fs/btrfs/extent_io.c168
-rw-r--r--fs/btrfs/extent_io.h8
-rw-r--r--fs/btrfs/file.c78
-rw-r--r--fs/btrfs/free-space-cache.c52
-rw-r--r--fs/btrfs/inode.c317
-rw-r--r--fs/btrfs/ioctl.c50
-rw-r--r--fs/btrfs/ioctl.h33
-rw-r--r--fs/btrfs/ordered-data.c165
-rw-r--r--fs/btrfs/ordered-data.h13
-rw-r--r--fs/btrfs/print-tree.c3
-rw-r--r--fs/btrfs/reada.c5
-rw-r--r--fs/btrfs/scrub.c65
-rw-r--r--fs/btrfs/super.c117
-rw-r--r--fs/btrfs/transaction.c59
-rw-r--r--fs/btrfs/tree-log.c35
-rw-r--r--fs/btrfs/ulist.c38
-rw-r--r--fs/btrfs/ulist.h15
-rw-r--r--fs/btrfs/volumes.c306
-rw-r--r--fs/btrfs/volumes.h52
-rw-r--r--fs/btrfs/xattr.c1
-rw-r--r--fs/buffer.c2
-rw-r--r--fs/ceph/export.c32
-rw-r--r--fs/ceph/snap.c2
-rw-r--r--fs/compat.c43
-rw-r--r--fs/dcache.c20
-rw-r--r--fs/ecryptfs/inode.c48
-rw-r--r--fs/eventfd.c12
-rw-r--r--fs/eventpoll.c4
-rw-r--r--fs/exec.c4
-rw-r--r--fs/exportfs/expfs.c33
-rw-r--r--fs/ext4/Kconfig2
-rw-r--r--fs/ext4/balloc.c41
-rw-r--r--fs/ext4/bitmap.c83
-rw-r--r--fs/ext4/dir.c12
-rw-r--r--fs/ext4/ext4.h130
-rw-r--r--fs/ext4/ext4_extents.h24
-rw-r--r--fs/ext4/ext4_jbd2.c9
-rw-r--r--fs/ext4/ext4_jbd2.h7
-rw-r--r--fs/ext4/extents.c91
-rw-r--r--fs/ext4/file.c2
-rw-r--r--fs/ext4/ialloc.c81
-rw-r--r--fs/ext4/inode.c119
-rw-r--r--fs/ext4/ioctl.c19
-rw-r--r--fs/ext4/mballoc.c30
-rw-r--r--fs/ext4/mmp.c44
-rw-r--r--fs/ext4/namei.c445
-rw-r--r--fs/ext4/resize.c71
-rw-r--r--fs/ext4/super.c253
-rw-r--r--fs/ext4/xattr.c92
-rw-r--r--fs/ext4/xattr.h4
-rw-r--r--fs/fat/dir.c4
-rw-r--r--fs/fat/fat.h6
-rw-r--r--fs/fat/fatent.c21
-rw-r--r--fs/fat/inode.c63
-rw-r--r--fs/fcntl.c42
-rw-r--r--fs/file_table.c17
-rw-r--r--fs/fuse/file.c4
-rw-r--r--fs/fuse/inode.c17
-rw-r--r--fs/gfs2/export.c17
-rw-r--r--fs/hpfs/alloc.c14
-rw-r--r--fs/hpfs/anode.c43
-rw-r--r--fs/hpfs/buffer.c1
-rw-r--r--fs/hpfs/dir.c2
-rw-r--r--fs/hpfs/dnode.c10
-rw-r--r--fs/hpfs/ea.c60
-rw-r--r--fs/hpfs/hpfs.h289
-rw-r--r--fs/hpfs/hpfs_fn.h23
-rw-r--r--fs/hpfs/inode.c2
-rw-r--r--fs/hpfs/map.c20
-rw-r--r--fs/hpfs/namei.c2
-rw-r--r--fs/hpfs/super.c4
-rw-r--r--fs/inode.c124
-rw-r--r--fs/internal.h3
-rw-r--r--fs/isofs/export.c13
-rw-r--r--fs/jbd2/Kconfig2
-rw-r--r--fs/jbd2/commit.c70
-rw-r--r--fs/jbd2/journal.c132
-rw-r--r--fs/jbd2/recovery.c126
-rw-r--r--fs/jbd2/revoke.c27
-rw-r--r--fs/jbd2/transaction.c4
-rw-r--r--fs/jffs2/jffs2_fs_sb.h11
-rw-r--r--fs/jffs2/nodemgmt.c42
-rw-r--r--fs/jffs2/os-linux.h7
-rw-r--r--fs/jffs2/readinode.c19
-rw-r--r--fs/jffs2/super.c38
-rw-r--r--fs/jffs2/wbuf.c55
-rw-r--r--fs/jffs2/xattr.c23
-rw-r--r--fs/jffs2/xattr.h2
-rw-r--r--fs/lockd/clntlock.c13
-rw-r--r--fs/lockd/svc.c148
-rw-r--r--fs/locks.c5
-rw-r--r--fs/namei.c177
-rw-r--r--fs/namespace.c142
-rw-r--r--fs/ncpfs/file.c6
-rw-r--r--fs/ncpfs/ncp_fs_sb.h10
-rw-r--r--fs/nfs/callback.c13
-rw-r--r--fs/nfs/dir.c56
-rw-r--r--fs/nfs/file.c77
-rw-r--r--fs/nfsd/auth.c2
-rw-r--r--fs/nfsd/export.c181
-rw-r--r--fs/nfsd/fault_inject.c1
-rw-r--r--fs/nfsd/idmap.h8
-rw-r--r--fs/nfsd/netns.h6
-rw-r--r--fs/nfsd/nfs4callback.c5
-rw-r--r--fs/nfsd/nfs4idmap.c113
-rw-r--r--fs/nfsd/nfs4recover.c4
-rw-r--r--fs/nfsd/nfs4state.c538
-rw-r--r--fs/nfsd/nfs4xdr.c62
-rw-r--r--fs/nfsd/nfsctl.c67
-rw-r--r--fs/nfsd/nfsfh.c2
-rw-r--r--fs/nfsd/nfssvc.c31
-rw-r--r--fs/nfsd/state.h1
-rw-r--r--fs/nfsd/vfs.c2
-rw-r--r--fs/nfsd/xdr4.h6
-rw-r--r--fs/nilfs2/file.c24
-rw-r--r--fs/nilfs2/ioctl.c8
-rw-r--r--fs/nilfs2/namei.c22
-rw-r--r--fs/nls/Kconfig157
-rw-r--r--fs/nls/Makefile11
-rw-r--r--fs/nls/mac-celtic.c602
-rw-r--r--fs/nls/mac-centeuro.c532
-rw-r--r--fs/nls/mac-croatian.c602
-rw-r--r--fs/nls/mac-cyrillic.c497
-rw-r--r--fs/nls/mac-gaelic.c567
-rw-r--r--fs/nls/mac-greek.c497
-rw-r--r--fs/nls/mac-iceland.c602
-rw-r--r--fs/nls/mac-inuit.c532
-rw-r--r--fs/nls/mac-roman.c637
-rw-r--r--fs/nls/mac-romanian.c602
-rw-r--r--fs/nls/mac-turkish.c602
-rw-r--r--fs/notify/fsnotify.c12
-rw-r--r--fs/ntfs/file.c4
-rw-r--r--fs/ocfs2/blockcheck.c42
-rw-r--r--fs/ocfs2/dlm/dlmast.c2
-rw-r--r--fs/ocfs2/dlm/dlmcommon.h6
-rw-r--r--fs/ocfs2/dlm/dlmdomain.c2
-rw-r--r--fs/ocfs2/export.c19
-rw-r--r--fs/ocfs2/inode.c13
-rw-r--r--fs/ocfs2/ioctl.c31
-rw-r--r--fs/ocfs2/move_extents.c6
-rw-r--r--fs/ocfs2/namei.c5
-rw-r--r--fs/ocfs2/symlink.c115
-rw-r--r--fs/ocfs2/symlink.h2
-rw-r--r--fs/open.c76
-rw-r--r--fs/pipe.c9
-rw-r--r--fs/pnode.c4
-rw-r--r--fs/proc/array.c147
-rw-r--r--fs/proc/base.c81
-rw-r--r--fs/proc/internal.h3
-rw-r--r--fs/proc/task_mmu.c82
-rw-r--r--fs/proc/task_nommu.c2
-rw-r--r--fs/proc_namespace.c4
-rw-r--r--fs/read_write.c7
-rw-r--r--fs/readdir.c33
-rw-r--r--fs/reiserfs/inode.c30
-rw-r--r--fs/reiserfs/journal.c15
-rw-r--r--fs/reiserfs/reiserfs.h12
-rw-r--r--fs/reiserfs/resize.c1
-rw-r--r--fs/reiserfs/super.c74
-rw-r--r--fs/select.c4
-rw-r--r--fs/signalfd.c7
-rw-r--r--fs/splice.c6
-rw-r--r--fs/statfs.c5
-rw-r--r--fs/sync.c5
-rw-r--r--fs/ubifs/dir.c11
-rw-r--r--fs/udf/namei.c14
-rw-r--r--fs/utimes.c5
-rw-r--r--fs/xattr.c20
-rw-r--r--fs/xfs/kmem.c10
-rw-r--r--fs/xfs/kmem.h21
-rw-r--r--fs/xfs/xfs_export.c23
-rw-r--r--fs/xfs/xfs_file.c7
-rw-r--r--fs/xfs/xfs_log.c2
-rw-r--r--fs/xfs/xfs_log_priv.h2
-rw-r--r--fs/xfs/xfs_trans.c2
-rw-r--r--fs/xfs/xfs_trans.h2
-rw-r--r--include/asm-generic/bitsperlong.h4
-rw-r--r--include/asm-generic/posix_types.h4
-rw-r--r--include/drm/drm_mem_util.h4
-rw-r--r--include/linux/Kbuild1
-rw-r--r--include/linux/compat.h3
-rw-r--r--include/linux/cpu.h1
-rw-r--r--include/linux/cred.h10
-rw-r--r--include/linux/dmaengine.h12
-rw-r--r--include/linux/errno.h1
-rw-r--r--include/linux/eventfd.h2
-rw-r--r--include/linux/exportfs.h4
-rw-r--r--include/linux/fb.h1
-rw-r--r--include/linux/fs.h22
-rw-r--r--include/linux/fsnotify_backend.h2
-rw-r--r--include/linux/interrupt.h4
-rw-r--r--include/linux/ipc_namespace.h42
-rw-r--r--include/linux/jbd2.h59
-rw-r--r--include/linux/jbd_common.h2
-rw-r--r--include/linux/kcmp.h17
-rw-r--r--include/linux/kernel.h1
-rw-r--r--include/linux/kexec.h75
-rw-r--r--include/linux/key.h4
-rw-r--r--include/linux/kmod.h34
-rw-r--r--include/linux/lglock.h179
-rw-r--r--include/linux/lockd/bind.h4
-rw-r--r--include/linux/mm.h2
-rw-r--r--include/linux/msdos_fs.h3
-rw-r--r--include/linux/mtd/gpmi-nand.h8
-rw-r--r--include/linux/mtd/mtd.h11
-rw-r--r--include/linux/mtd/nand.h25
-rw-r--r--include/linux/nfsd/export.h13
-rw-r--r--include/linux/prctl.h6
-rw-r--r--include/linux/rio.h47
-rw-r--r--include/linux/rio_drv.h9
-rw-r--r--include/linux/sched.h28
-rw-r--r--include/linux/security.h40
-rw-r--r--include/linux/signal.h5
-rw-r--r--include/linux/slab.h2
-rw-r--r--include/linux/sunrpc/svc.h2
-rw-r--r--include/linux/sunrpc/svcauth.h13
-rw-r--r--include/linux/sunrpc/svcauth_gss.h1
-rw-r--r--include/linux/syscalls.h2
-rw-r--r--include/linux/task_work.h33
-rw-r--r--include/linux/thread_info.h19
-rw-r--r--include/linux/tracehook.h13
-rw-r--r--include/linux/tty.h23
-rw-r--r--include/linux/types.h2
-rw-r--r--include/video/auo_k190xfb.h106
-rw-r--r--include/video/exynos_dp.h2
-rw-r--r--include/video/exynos_mipi_dsim.h1
-rw-r--r--include/video/omapdss.h47
-rw-r--r--include/video/sh_mobile_hdmi.h12
-rw-r--r--init/Kconfig11
-rw-r--r--init/do_mounts.c14
-rw-r--r--init/do_mounts_initrd.c10
-rw-r--r--init/do_mounts_md.c12
-rw-r--r--init/do_mounts_rd.c13
-rw-r--r--init/initramfs.c16
-rw-r--r--ipc/mq_sysctl.c49
-rw-r--r--ipc/mqueue.c292
-rw-r--r--ipc/shm.c7
-rw-r--r--kernel/Makefile7
-rw-r--r--kernel/cpu.c44
-rw-r--r--kernel/cpu_pm.c16
-rw-r--r--kernel/cred.c9
-rw-r--r--kernel/exit.c13
-rw-r--r--kernel/fork.c11
-rw-r--r--kernel/irq/manage.c80
-rw-r--r--kernel/kcmp.c196
-rw-r--r--kernel/kmod.c30
-rw-r--r--kernel/lglock.c89
-rw-r--r--kernel/pid_namespace.c13
-rw-r--r--kernel/resource.c4
-rw-r--r--kernel/signal.c59
-rw-r--r--kernel/sys.c213
-rw-r--r--kernel/sys_ni.c3
-rw-r--r--kernel/task_work.c84
-rw-r--r--lib/vsprintf.c289
-rw-r--r--mm/cleancache.c6
-rw-r--r--mm/filemap.c69
-rw-r--r--mm/filemap_xip.c4
-rw-r--r--mm/internal.h4
-rw-r--r--mm/mmap.c54
-rw-r--r--mm/mremap.c26
-rw-r--r--mm/nommu.c35
-rw-r--r--mm/process_vm_access.c16
-rw-r--r--mm/shmem.c6
-rw-r--r--mm/slub.c23
-rw-r--r--mm/util.c30
-rw-r--r--net/bluetooth/rfcomm/tty.c4
-rw-r--r--net/sched/sch_atm.c2
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_wrap.c61
-rw-r--r--net/sunrpc/auth_gss/svcauth_gss.c127
-rw-r--r--net/sunrpc/rpcb_clnt.c12
-rw-r--r--net/sunrpc/svc.c23
-rw-r--r--net/sunrpc/svc_xprt.c4
-rw-r--r--net/sunrpc/svcauth_unix.c19
-rwxr-xr-xscripts/checkpatch.pl20
-rw-r--r--security/apparmor/lsm.c15
-rw-r--r--security/capability.c3
-rw-r--r--security/commoncap.c17
-rw-r--r--security/keys/compat.c2
-rw-r--r--security/keys/internal.h2
-rw-r--r--security/keys/keyctl.c77
-rw-r--r--security/keys/process_keys.c20
-rw-r--r--security/keys/request_key.c13
-rw-r--r--security/security.c51
-rw-r--r--security/selinux/hooks.c15
-rw-r--r--security/selinux/selinuxfs.c36
-rw-r--r--security/smack/smack_lsm.c15
-rw-r--r--sound/pci/rme9652/hdspm.c7
-rw-r--r--sound/soc/fsl/imx-ssi.c6
-rw-r--r--sound/soc/sh/fsi.c25
-rw-r--r--sound/usb/pcm.c3
-rw-r--r--tools/testing/selftests/Makefile2
-rw-r--r--tools/testing/selftests/kcmp/Makefile29
-rw-r--r--tools/testing/selftests/kcmp/kcmp_test.c94
-rw-r--r--tools/testing/selftests/mqueue/.gitignore2
-rw-r--r--tools/testing/selftests/mqueue/Makefile10
-rw-r--r--tools/testing/selftests/mqueue/mq_open_tests.c492
-rw-r--r--tools/testing/selftests/mqueue/mq_perf_tests.c741
-rw-r--r--usr/Kconfig10
667 files changed, 28207 insertions, 10168 deletions
diff --git a/.mailmap b/.mailmap
index 9b0d0267a3c3..2909c33bc54e 100644
--- a/.mailmap
+++ b/.mailmap
@@ -113,3 +113,5 @@ Uwe Kleine-König <Uwe.Kleine-Koenig@digi.com>
113Valdis Kletnieks <Valdis.Kletnieks@vt.edu> 113Valdis Kletnieks <Valdis.Kletnieks@vt.edu>
114Takashi YOSHII <takashi.yoshii.zj@renesas.com> 114Takashi YOSHII <takashi.yoshii.zj@renesas.com>
115Yusuke Goda <goda.yusuke@renesas.com> 115Yusuke Goda <goda.yusuke@renesas.com>
116Gustavo Padovan <gustavo@las.ic.unicamp.br>
117Gustavo Padovan <padovan@profusion.mobi>
diff --git a/Documentation/ABI/testing/sysfs-class-mtd b/Documentation/ABI/testing/sysfs-class-mtd
index 4d55a1888981..db1ad7e34fc3 100644
--- a/Documentation/ABI/testing/sysfs-class-mtd
+++ b/Documentation/ABI/testing/sysfs-class-mtd
@@ -123,3 +123,54 @@ Description:
123 half page, or a quarter page). 123 half page, or a quarter page).
124 124
125 In the case of ECC NOR, it is the ECC block size. 125 In the case of ECC NOR, it is the ECC block size.
126
127What: /sys/class/mtd/mtdX/ecc_strength
128Date: April 2012
129KernelVersion: 3.4
130Contact: linux-mtd@lists.infradead.org
131Description:
132 Maximum number of bit errors that the device is capable of
133 correcting within each region covering an ecc step. This will
134 always be a non-negative integer. Note that some devices will
135 have multiple ecc steps within each writesize region.
136
137 In the case of devices lacking any ECC capability, it is 0.
138
139What: /sys/class/mtd/mtdX/bitflip_threshold
140Date: April 2012
141KernelVersion: 3.4
142Contact: linux-mtd@lists.infradead.org
143Description:
144 This allows the user to examine and adjust the criteria by which
145 mtd returns -EUCLEAN from mtd_read(). If the maximum number of
146 bit errors that were corrected on any single region comprising
147 an ecc step (as reported by the driver) equals or exceeds this
148 value, -EUCLEAN is returned. Otherwise, absent an error, 0 is
149 returned. Higher layers (e.g., UBI) use this return code as an
150 indication that an erase block may be degrading and should be
151 scrutinized as a candidate for being marked as bad.
152
153 The initial value may be specified by the flash device driver.
154 If not, then the default value is ecc_strength.
155
156 The introduction of this feature brings a subtle change to the
157 meaning of the -EUCLEAN return code. Previously, it was
158 interpreted to mean simply "one or more bit errors were
159 corrected". Its new interpretation can be phrased as "a
160 dangerously high number of bit errors were corrected on one or
161 more regions comprising an ecc step". The precise definition of
162 "dangerously high" can be adjusted by the user with
163 bitflip_threshold. Users are discouraged from doing this,
164 however, unless they know what they are doing and have intimate
165 knowledge of the properties of their device. Broadly speaking,
166 bitflip_threshold should be low enough to detect genuine erase
167 block degradation, but high enough to avoid the consequences of
168 a persistent return value of -EUCLEAN on devices where sticky
169 bitflips occur. Note that if bitflip_threshold exceeds
170 ecc_strength, -EUCLEAN is never returned by mtd_read().
171 Conversely, if bitflip_threshold is zero, -EUCLEAN is always
172 returned, absent a hard error.
173
174 This is generally applicable only to NAND flash devices with ECC
175 capability. It is ignored on devices lacking ECC capability;
176 i.e., devices for which ecc_strength is zero.
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index c58b236bbe04..cb9258b8fd35 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -671,8 +671,9 @@ ones already enabled by DEBUG.
671 Chapter 14: Allocating memory 671 Chapter 14: Allocating memory
672 672
673The kernel provides the following general purpose memory allocators: 673The kernel provides the following general purpose memory allocators:
674kmalloc(), kzalloc(), kcalloc(), vmalloc(), and vzalloc(). Please refer to 674kmalloc(), kzalloc(), kmalloc_array(), kcalloc(), vmalloc(), and
675the API documentation for further information about them. 675vzalloc(). Please refer to the API documentation for further information
676about them.
676 677
677The preferred form for passing a size of a struct is the following: 678The preferred form for passing a size of a struct is the following:
678 679
@@ -686,6 +687,17 @@ Casting the return value which is a void pointer is redundant. The conversion
686from void pointer to any other pointer type is guaranteed by the C programming 687from void pointer to any other pointer type is guaranteed by the C programming
687language. 688language.
688 689
690The preferred form for allocating an array is the following:
691
692 p = kmalloc_array(n, sizeof(...), ...);
693
694The preferred form for allocating a zeroed array is the following:
695
696 p = kcalloc(n, sizeof(...), ...);
697
698Both forms check for overflow on the allocation size n * sizeof(...),
699and return NULL if that occurred.
700
689 701
690 Chapter 15: The inline disease 702 Chapter 15: The inline disease
691 703
diff --git a/Documentation/DocBook/mtdnand.tmpl b/Documentation/DocBook/mtdnand.tmpl
index 0c674be0d3c6..e0aedb7a7827 100644
--- a/Documentation/DocBook/mtdnand.tmpl
+++ b/Documentation/DocBook/mtdnand.tmpl
@@ -1119,8 +1119,6 @@ in this page</entry>
1119 These constants are defined in nand.h. They are ored together to describe 1119 These constants are defined in nand.h. They are ored together to describe
1120 the chip functionality. 1120 the chip functionality.
1121 <programlisting> 1121 <programlisting>
1122/* Chip can not auto increment pages */
1123#define NAND_NO_AUTOINCR 0x00000001
1124/* Buswitdh is 16 bit */ 1122/* Buswitdh is 16 bit */
1125#define NAND_BUSWIDTH_16 0x00000002 1123#define NAND_BUSWIDTH_16 0x00000002
1126/* Device supports partial programming without padding */ 1124/* Device supports partial programming without padding */
diff --git a/Documentation/arm/OMAP/DSS b/Documentation/arm/OMAP/DSS
index 888ae7b83ae4..a564ceea9e98 100644
--- a/Documentation/arm/OMAP/DSS
+++ b/Documentation/arm/OMAP/DSS
@@ -47,6 +47,51 @@ flexible way to enable non-common multi-display configuration. In addition to
47modelling the hardware overlays, omapdss supports virtual overlays and overlay 47modelling the hardware overlays, omapdss supports virtual overlays and overlay
48managers. These can be used when updating a display with CPU or system DMA. 48managers. These can be used when updating a display with CPU or system DMA.
49 49
50omapdss driver support for audio
51--------------------------------
52There exist several display technologies and standards that support audio as
53well. Hence, it is relevant to update the DSS device driver to provide an audio
54interface that may be used by an audio driver or any other driver interested in
55the functionality.
56
57The audio_enable function is intended to prepare the relevant
58IP for playback (e.g., enabling an audio FIFO, taking in/out of reset
59some IP, enabling companion chips, etc). It is intended to be called before
60audio_start. The audio_disable function performs the reverse operation and is
61intended to be called after audio_stop.
62
63While a given DSS device driver may support audio, it is possible that for
64certain configurations audio is not supported (e.g., an HDMI display using a
65VESA video timing). The audio_supported function is intended to query whether
66the current configuration of the display supports audio.
67
68The audio_config function is intended to configure all the relevant audio
69parameters of the display. In order to make the function independent of any
70specific DSS device driver, a struct omap_dss_audio is defined. Its purpose
71is to contain all the required parameters for audio configuration. At the
72moment, such structure contains pointers to IEC-60958 channel status word
73and CEA-861 audio infoframe structures. This should be enough to support
74HDMI and DisplayPort, as both are based on CEA-861 and IEC-60958.
75
76The audio_enable/disable, audio_config and audio_supported functions could be
77implemented as functions that may sleep. Hence, they should not be called
78while holding a spinlock or a readlock.
79
80The audio_start/audio_stop function is intended to effectively start/stop audio
81playback after the configuration has taken place. These functions are designed
82to be used in an atomic context. Hence, audio_start should return quickly and be
83called only after all the needed resources for audio playback (audio FIFOs,
84DMA channels, companion chips, etc) have been enabled to begin data transfers.
85audio_stop is designed to only stop the audio transfers. The resources used
86for playback are released using audio_disable.
87
88The enum omap_dss_audio_state may be used to help the implementations of
89the interface to keep track of the audio state. The initial state is _DISABLED;
90then, the state transitions to _CONFIGURED, and then, when it is ready to
91play audio, to _ENABLED. The state _PLAYING is used when the audio is being
92rendered.
93
94
50Panel and controller drivers 95Panel and controller drivers
51---------------------------- 96----------------------------
52 97
@@ -156,6 +201,7 @@ timings Display timings (pixclock,xres/hfp/hbp/hsw,yres/vfp/vbp/vsw)
156 "pal" and "ntsc" 201 "pal" and "ntsc"
157panel_name 202panel_name
158tear_elim Tearing elimination 0=off, 1=on 203tear_elim Tearing elimination 0=off, 1=on
204output_type Output type (video encoder only): "composite" or "svideo"
159 205
160There are also some debugfs files at <debugfs>/omapdss/ which show information 206There are also some debugfs files at <debugfs>/omapdss/ which show information
161about clocks and registers. 207about clocks and registers.
diff --git a/Documentation/devicetree/bindings/mtd/gpmi-nand.txt b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt
new file mode 100644
index 000000000000..1a5bbd346d22
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/gpmi-nand.txt
@@ -0,0 +1,33 @@
1* Freescale General-Purpose Media Interface (GPMI)
2
3The GPMI nand controller provides an interface to control the
4NAND flash chips. We support only one NAND chip now.
5
6Required properties:
7 - compatible : should be "fsl,<chip>-gpmi-nand"
8 - reg : should contain registers location and length for gpmi and bch.
9 - reg-names: Should contain the reg names "gpmi-nand" and "bch"
10 - interrupts : The first is the DMA interrupt number for GPMI.
11 The second is the BCH interrupt number.
12 - interrupt-names : The interrupt names "gpmi-dma", "bch";
13 - fsl,gpmi-dma-channel : Should contain the dma channel it uses.
14
15The device tree may optionally contain sub-nodes describing partitions of the
16address space. See partition.txt for more detail.
17
18Examples:
19
20gpmi-nand@8000c000 {
21 compatible = "fsl,imx28-gpmi-nand";
22 #address-cells = <1>;
23 #size-cells = <1>;
24 reg = <0x8000c000 2000>, <0x8000a000 2000>;
25 reg-names = "gpmi-nand", "bch";
26 interrupts = <88>, <41>;
27 interrupt-names = "gpmi-dma", "bch";
28 fsl,gpmi-dma-channel = <4>;
29
30 partition@0 {
31 ...
32 };
33};
diff --git a/Documentation/devicetree/bindings/mtd/mxc-nand.txt b/Documentation/devicetree/bindings/mtd/mxc-nand.txt
new file mode 100644
index 000000000000..b5833d11c7be
--- /dev/null
+++ b/Documentation/devicetree/bindings/mtd/mxc-nand.txt
@@ -0,0 +1,19 @@
1* Freescale's mxc_nand
2
3Required properties:
4- compatible: "fsl,imxXX-nand"
5- reg: address range of the nfc block
6- interrupts: irq to be used
7- nand-bus-width: see nand.txt
8- nand-ecc-mode: see nand.txt
9- nand-on-flash-bbt: see nand.txt
10
11Example:
12
13 nand@d8000000 {
14 compatible = "fsl,imx27-nand";
15 reg = <0xd8000000 0x1000>;
16 interrupts = <29>;
17 nand-bus-width = <8>;
18 nand-ecc-mode = "hw";
19 };
diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking
index d449e632e6a0..8e2da1e06e3b 100644
--- a/Documentation/filesystems/Locking
+++ b/Documentation/filesystems/Locking
@@ -61,6 +61,7 @@ ata *);
61 ssize_t (*listxattr) (struct dentry *, char *, size_t); 61 ssize_t (*listxattr) (struct dentry *, char *, size_t);
62 int (*removexattr) (struct dentry *, const char *); 62 int (*removexattr) (struct dentry *, const char *);
63 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, u64 len); 63 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, u64 len);
64 void (*update_time)(struct inode *, struct timespec *, int);
64 65
65locking rules: 66locking rules:
66 all may block 67 all may block
@@ -87,6 +88,8 @@ getxattr: no
87listxattr: no 88listxattr: no
88removexattr: yes 89removexattr: yes
89fiemap: no 90fiemap: no
91update_time: no
92
90 Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_mutex on 93 Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_mutex on
91victim. 94victim.
92 cross-directory ->rename() has (per-superblock) ->s_vfs_rename_sem. 95 cross-directory ->rename() has (per-superblock) ->s_vfs_rename_sem.
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
index 912af6ce5626..fb0a6aeb936c 100644
--- a/Documentation/filesystems/proc.txt
+++ b/Documentation/filesystems/proc.txt
@@ -40,6 +40,7 @@ Table of Contents
40 3.4 /proc/<pid>/coredump_filter - Core dump filtering settings 40 3.4 /proc/<pid>/coredump_filter - Core dump filtering settings
41 3.5 /proc/<pid>/mountinfo - Information about mounts 41 3.5 /proc/<pid>/mountinfo - Information about mounts
42 3.6 /proc/<pid>/comm & /proc/<pid>/task/<tid>/comm 42 3.6 /proc/<pid>/comm & /proc/<pid>/task/<tid>/comm
43 3.7 /proc/<pid>/task/<tid>/children - Information about task children
43 44
44 4 Configuring procfs 45 4 Configuring procfs
45 4.1 Mount options 46 4.1 Mount options
@@ -310,6 +311,11 @@ Table 1-4: Contents of the stat files (as of 2.6.30-rc7)
310 start_data address above which program data+bss is placed 311 start_data address above which program data+bss is placed
311 end_data address below which program data+bss is placed 312 end_data address below which program data+bss is placed
312 start_brk address above which program heap can be expanded with brk() 313 start_brk address above which program heap can be expanded with brk()
314 arg_start address above which program command line is placed
315 arg_end address below which program command line is placed
316 env_start address above which program environment is placed
317 env_end address below which program environment is placed
318 exit_code the thread's exit_code in the form reported by the waitpid system call
313.............................................................................. 319..............................................................................
314 320
315The /proc/PID/maps file containing the currently mapped memory regions and 321The /proc/PID/maps file containing the currently mapped memory regions and
@@ -1578,6 +1584,23 @@ then the kernel's TASK_COMM_LEN (currently 16 chars) will result in a truncated
1578comm value. 1584comm value.
1579 1585
1580 1586
15873.7 /proc/<pid>/task/<tid>/children - Information about task children
1588-------------------------------------------------------------------------
1589This file provides a fast way to retrieve first level children pids
1590of a task pointed by <pid>/<tid> pair. The format is a space separated
1591stream of pids.
1592
1593Note the "first level" here -- if a child has own children they will
1594not be listed here, one needs to read /proc/<children-pid>/task/<tid>/children
1595to obtain the descendants.
1596
1597Since this interface is intended to be fast and cheap it doesn't
1598guarantee to provide precise results and some children might be
1599skipped, especially if they've exited right after we printed their
1600pids, so one need to either stop or freeze processes being inspected
1601if precise results are needed.
1602
1603
1581------------------------------------------------------------------------------ 1604------------------------------------------------------------------------------
1582Configuring procfs 1605Configuring procfs
1583------------------------------------------------------------------------------ 1606------------------------------------------------------------------------------
diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt
index ef19f91a0f12..efd23f481704 100644
--- a/Documentation/filesystems/vfs.txt
+++ b/Documentation/filesystems/vfs.txt
@@ -363,6 +363,7 @@ struct inode_operations {
363 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t); 363 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
364 ssize_t (*listxattr) (struct dentry *, char *, size_t); 364 ssize_t (*listxattr) (struct dentry *, char *, size_t);
365 int (*removexattr) (struct dentry *, const char *); 365 int (*removexattr) (struct dentry *, const char *);
366 void (*update_time)(struct inode *, struct timespec *, int);
366}; 367};
367 368
368Again, all methods are called without any locks being held, unless 369Again, all methods are called without any locks being held, unless
@@ -471,6 +472,9 @@ otherwise noted.
471 removexattr: called by the VFS to remove an extended attribute from 472 removexattr: called by the VFS to remove an extended attribute from
472 a file. This method is called by removexattr(2) system call. 473 a file. This method is called by removexattr(2) system call.
473 474
475 update_time: called by the VFS to update a specific time or the i_version of
476 an inode. If this is not defined the VFS will update the inode itself
477 and call mark_inode_dirty_sync.
474 478
475The Address Space Object 479The Address Space Object
476======================== 480========================
diff --git a/Documentation/sysctl/fs.txt b/Documentation/sysctl/fs.txt
index 88fd7f5c8dcd..13d6166d7a27 100644
--- a/Documentation/sysctl/fs.txt
+++ b/Documentation/sysctl/fs.txt
@@ -225,6 +225,13 @@ a queue must be less or equal then msg_max.
225maximum message size value (it is every message queue's attribute set during 225maximum message size value (it is every message queue's attribute set during
226its creation). 226its creation).
227 227
228/proc/sys/fs/mqueue/msg_default is a read/write file for setting/getting the
229default number of messages in a queue value if attr parameter of mq_open(2) is
230NULL. If it exceed msg_max, the default value is initialized msg_max.
231
232/proc/sys/fs/mqueue/msgsize_default is a read/write file for setting/getting
233the default message size value if attr parameter of mq_open(2) is NULL. If it
234exceed msgsize_max, the default value is initialized msgsize_max.
228 235
2294. /proc/sys/fs/epoll - Configuration options for the epoll interface 2364. /proc/sys/fs/epoll - Configuration options for the epoll interface
230-------------------------------------------------------- 237--------------------------------------------------------
diff --git a/Documentation/vm/pagemap.txt b/Documentation/vm/pagemap.txt
index 4600cbe3d6be..7587493c67f1 100644
--- a/Documentation/vm/pagemap.txt
+++ b/Documentation/vm/pagemap.txt
@@ -16,7 +16,7 @@ There are three components to pagemap:
16 * Bits 0-4 swap type if swapped 16 * Bits 0-4 swap type if swapped
17 * Bits 5-54 swap offset if swapped 17 * Bits 5-54 swap offset if swapped
18 * Bits 55-60 page shift (page size = 1<<page shift) 18 * Bits 55-60 page shift (page size = 1<<page shift)
19 * Bit 61 reserved for future use 19 * Bit 61 page is file-page or shared-anon
20 * Bit 62 page swapped 20 * Bit 62 page swapped
21 * Bit 63 page present 21 * Bit 63 page present
22 22
diff --git a/Documentation/vm/slub.txt b/Documentation/vm/slub.txt
index 6752870c4970..b0c6d1bbb434 100644
--- a/Documentation/vm/slub.txt
+++ b/Documentation/vm/slub.txt
@@ -17,7 +17,7 @@ data and perform operation on the slabs. By default slabinfo only lists
17slabs that have data in them. See "slabinfo -h" for more options when 17slabs that have data in them. See "slabinfo -h" for more options when
18running the command. slabinfo can be compiled with 18running the command. slabinfo can be compiled with
19 19
20gcc -o slabinfo tools/slub/slabinfo.c 20gcc -o slabinfo tools/vm/slabinfo.c
21 21
22Some of the modes of operation of slabinfo require that slub debugging 22Some of the modes of operation of slabinfo require that slub debugging
23be enabled on the command line. F.e. no tracking information will be 23be enabled on the command line. F.e. no tracking information will be
diff --git a/Documentation/x86/efi-stub.txt b/Documentation/x86/efi-stub.txt
new file mode 100644
index 000000000000..44e6bb6ead10
--- /dev/null
+++ b/Documentation/x86/efi-stub.txt
@@ -0,0 +1,65 @@
1 The EFI Boot Stub
2 ---------------------------
3
4On the x86 platform, a bzImage can masquerade as a PE/COFF image,
5thereby convincing EFI firmware loaders to load it as an EFI
6executable. The code that modifies the bzImage header, along with the
7EFI-specific entry point that the firmware loader jumps to are
8collectively known as the "EFI boot stub", and live in
9arch/x86/boot/header.S and arch/x86/boot/compressed/eboot.c,
10respectively.
11
12By using the EFI boot stub it's possible to boot a Linux kernel
13without the use of a conventional EFI boot loader, such as grub or
14elilo. Since the EFI boot stub performs the jobs of a boot loader, in
15a certain sense it *IS* the boot loader.
16
17The EFI boot stub is enabled with the CONFIG_EFI_STUB kernel option.
18
19
20**** How to install bzImage.efi
21
22The bzImage located in arch/x86/boot/bzImage must be copied to the EFI
23System Partiion (ESP) and renamed with the extension ".efi". Without
24the extension the EFI firmware loader will refuse to execute it. It's
25not possible to execute bzImage.efi from the usual Linux file systems
26because EFI firmware doesn't have support for them.
27
28
29**** Passing kernel parameters from the EFI shell
30
31Arguments to the kernel can be passed after bzImage.efi, e.g.
32
33 fs0:> bzImage.efi console=ttyS0 root=/dev/sda4
34
35
36**** The "initrd=" option
37
38Like most boot loaders, the EFI stub allows the user to specify
39multiple initrd files using the "initrd=" option. This is the only EFI
40stub-specific command line parameter, everything else is passed to the
41kernel when it boots.
42
43The path to the initrd file must be an absolute path from the
44beginning of the ESP, relative path names do not work. Also, the path
45is an EFI-style path and directory elements must be separated with
46backslashes (\). For example, given the following directory layout,
47
48fs0:>
49 Kernels\
50 bzImage.efi
51 initrd-large.img
52
53 Ramdisks\
54 initrd-small.img
55 initrd-medium.img
56
57to boot with the initrd-large.img file if the current working
58directory is fs0:\Kernels, the following command must be used,
59
60 fs0:\Kernels> bzImage.efi initrd=\Kernels\initrd-large.img
61
62Notice how bzImage.efi can be specified with a relative path. That's
63because the image we're executing is interpreted by the EFI shell,
64which understands relative paths, whereas the rest of the command line
65is passed to bzImage.efi.
diff --git a/arch/alpha/include/asm/posix_types.h b/arch/alpha/include/asm/posix_types.h
index 24779fc95994..5a8a48320efe 100644
--- a/arch/alpha/include/asm/posix_types.h
+++ b/arch/alpha/include/asm/posix_types.h
@@ -10,9 +10,6 @@
10typedef unsigned int __kernel_ino_t; 10typedef unsigned int __kernel_ino_t;
11#define __kernel_ino_t __kernel_ino_t 11#define __kernel_ino_t __kernel_ino_t
12 12
13typedef unsigned int __kernel_nlink_t;
14#define __kernel_nlink_t __kernel_nlink_t
15
16typedef unsigned long __kernel_sigset_t; /* at least 32 bits */ 13typedef unsigned long __kernel_sigset_t; /* at least 32 bits */
17 14
18#include <asm-generic/posix_types.h> 15#include <asm-generic/posix_types.h>
diff --git a/arch/alpha/kernel/signal.c b/arch/alpha/kernel/signal.c
index 10ab2d74ecbb..a8c97d42ec8e 100644
--- a/arch/alpha/kernel/signal.c
+++ b/arch/alpha/kernel/signal.c
@@ -226,7 +226,6 @@ do_sigreturn(struct sigcontext __user *sc, struct pt_regs *regs,
226 if (__get_user(set.sig[0], &sc->sc_mask)) 226 if (__get_user(set.sig[0], &sc->sc_mask))
227 goto give_sigsegv; 227 goto give_sigsegv;
228 228
229 sigdelsetmask(&set, ~_BLOCKABLE);
230 set_current_blocked(&set); 229 set_current_blocked(&set);
231 230
232 if (restore_sigcontext(sc, regs, sw)) 231 if (restore_sigcontext(sc, regs, sw))
@@ -261,7 +260,6 @@ do_rt_sigreturn(struct rt_sigframe __user *frame, struct pt_regs *regs,
261 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 260 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
262 goto give_sigsegv; 261 goto give_sigsegv;
263 262
264 sigdelsetmask(&set, ~_BLOCKABLE);
265 set_current_blocked(&set); 263 set_current_blocked(&set);
266 264
267 if (restore_sigcontext(&frame->uc.uc_mcontext, regs, sw)) 265 if (restore_sigcontext(&frame->uc.uc_mcontext, regs, sw))
@@ -468,12 +466,9 @@ static inline void
468handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info, 466handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
469 struct pt_regs * regs, struct switch_stack *sw) 467 struct pt_regs * regs, struct switch_stack *sw)
470{ 468{
471 sigset_t *oldset = &current->blocked; 469 sigset_t *oldset = sigmask_to_save();
472 int ret; 470 int ret;
473 471
474 if (test_thread_flag(TIF_RESTORE_SIGMASK))
475 oldset = &current->saved_sigmask;
476
477 if (ka->sa.sa_flags & SA_SIGINFO) 472 if (ka->sa.sa_flags & SA_SIGINFO)
478 ret = setup_rt_frame(sig, ka, info, oldset, regs, sw); 473 ret = setup_rt_frame(sig, ka, info, oldset, regs, sw);
479 else 474 else
@@ -483,12 +478,7 @@ handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
483 force_sigsegv(sig, current); 478 force_sigsegv(sig, current);
484 return; 479 return;
485 } 480 }
486 block_sigmask(ka, sig); 481 signal_delivered(sig, info, ka, regs, 0);
487 /* A signal was successfully delivered, and the
488 saved sigmask was stored on the signal frame,
489 and will be restored by sigreturn. So we can
490 simply clear the restore sigmask flag. */
491 clear_thread_flag(TIF_RESTORE_SIGMASK);
492} 482}
493 483
494static inline void 484static inline void
@@ -572,9 +562,7 @@ do_signal(struct pt_regs * regs, struct switch_stack * sw,
572 } 562 }
573 563
574 /* If there's no signal to deliver, we just restore the saved mask. */ 564 /* If there's no signal to deliver, we just restore the saved mask. */
575 if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK)) 565 restore_saved_sigmask();
576 set_current_blocked(&current->saved_sigmask);
577
578 if (single_stepping) 566 if (single_stepping)
579 ptrace_set_bpt(current); /* re-set breakpoint */ 567 ptrace_set_bpt(current); /* re-set breakpoint */
580} 568}
@@ -590,7 +578,5 @@ do_notify_resume(struct pt_regs *regs, struct switch_stack *sw,
590 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 578 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
591 clear_thread_flag(TIF_NOTIFY_RESUME); 579 clear_thread_flag(TIF_NOTIFY_RESUME);
592 tracehook_notify_resume(regs); 580 tracehook_notify_resume(regs);
593 if (current->replacement_session_keyring)
594 key_replace_session_keyring();
595 } 581 }
596} 582}
diff --git a/arch/arm/boot/dts/db8500.dtsi b/arch/arm/boot/dts/db8500.dtsi
index 881bc3987844..4ad5160018cb 100644
--- a/arch/arm/boot/dts/db8500.dtsi
+++ b/arch/arm/boot/dts/db8500.dtsi
@@ -58,6 +58,8 @@
58 "st,nomadik-gpio"; 58 "st,nomadik-gpio";
59 reg = <0x8012e000 0x80>; 59 reg = <0x8012e000 0x80>;
60 interrupts = <0 119 0x4>; 60 interrupts = <0 119 0x4>;
61 interrupt-controller;
62 #interrupt-cells = <2>;
61 supports-sleepmode; 63 supports-sleepmode;
62 gpio-controller; 64 gpio-controller;
63 #gpio-cells = <2>; 65 #gpio-cells = <2>;
@@ -69,6 +71,8 @@
69 "st,nomadik-gpio"; 71 "st,nomadik-gpio";
70 reg = <0x8012e080 0x80>; 72 reg = <0x8012e080 0x80>;
71 interrupts = <0 120 0x4>; 73 interrupts = <0 120 0x4>;
74 interrupt-controller;
75 #interrupt-cells = <2>;
72 supports-sleepmode; 76 supports-sleepmode;
73 gpio-controller; 77 gpio-controller;
74 #gpio-cells = <2>; 78 #gpio-cells = <2>;
@@ -80,6 +84,8 @@
80 "st,nomadik-gpio"; 84 "st,nomadik-gpio";
81 reg = <0x8000e000 0x80>; 85 reg = <0x8000e000 0x80>;
82 interrupts = <0 121 0x4>; 86 interrupts = <0 121 0x4>;
87 interrupt-controller;
88 #interrupt-cells = <2>;
83 supports-sleepmode; 89 supports-sleepmode;
84 gpio-controller; 90 gpio-controller;
85 #gpio-cells = <2>; 91 #gpio-cells = <2>;
@@ -91,6 +97,8 @@
91 "st,nomadik-gpio"; 97 "st,nomadik-gpio";
92 reg = <0x8000e080 0x80>; 98 reg = <0x8000e080 0x80>;
93 interrupts = <0 122 0x4>; 99 interrupts = <0 122 0x4>;
100 interrupt-controller;
101 #interrupt-cells = <2>;
94 supports-sleepmode; 102 supports-sleepmode;
95 gpio-controller; 103 gpio-controller;
96 #gpio-cells = <2>; 104 #gpio-cells = <2>;
@@ -102,6 +110,8 @@
102 "st,nomadik-gpio"; 110 "st,nomadik-gpio";
103 reg = <0x8000e100 0x80>; 111 reg = <0x8000e100 0x80>;
104 interrupts = <0 123 0x4>; 112 interrupts = <0 123 0x4>;
113 interrupt-controller;
114 #interrupt-cells = <2>;
105 supports-sleepmode; 115 supports-sleepmode;
106 gpio-controller; 116 gpio-controller;
107 #gpio-cells = <2>; 117 #gpio-cells = <2>;
@@ -113,6 +123,8 @@
113 "st,nomadik-gpio"; 123 "st,nomadik-gpio";
114 reg = <0x8000e180 0x80>; 124 reg = <0x8000e180 0x80>;
115 interrupts = <0 124 0x4>; 125 interrupts = <0 124 0x4>;
126 interrupt-controller;
127 #interrupt-cells = <2>;
116 supports-sleepmode; 128 supports-sleepmode;
117 gpio-controller; 129 gpio-controller;
118 #gpio-cells = <2>; 130 #gpio-cells = <2>;
@@ -124,6 +136,8 @@
124 "st,nomadik-gpio"; 136 "st,nomadik-gpio";
125 reg = <0x8011e000 0x80>; 137 reg = <0x8011e000 0x80>;
126 interrupts = <0 125 0x4>; 138 interrupts = <0 125 0x4>;
139 interrupt-controller;
140 #interrupt-cells = <2>;
127 supports-sleepmode; 141 supports-sleepmode;
128 gpio-controller; 142 gpio-controller;
129 #gpio-cells = <2>; 143 #gpio-cells = <2>;
@@ -135,6 +149,8 @@
135 "st,nomadik-gpio"; 149 "st,nomadik-gpio";
136 reg = <0x8011e080 0x80>; 150 reg = <0x8011e080 0x80>;
137 interrupts = <0 126 0x4>; 151 interrupts = <0 126 0x4>;
152 interrupt-controller;
153 #interrupt-cells = <2>;
138 supports-sleepmode; 154 supports-sleepmode;
139 gpio-controller; 155 gpio-controller;
140 #gpio-cells = <2>; 156 #gpio-cells = <2>;
@@ -146,12 +162,18 @@
146 "st,nomadik-gpio"; 162 "st,nomadik-gpio";
147 reg = <0xa03fe000 0x80>; 163 reg = <0xa03fe000 0x80>;
148 interrupts = <0 127 0x4>; 164 interrupts = <0 127 0x4>;
165 interrupt-controller;
166 #interrupt-cells = <2>;
149 supports-sleepmode; 167 supports-sleepmode;
150 gpio-controller; 168 gpio-controller;
151 #gpio-cells = <2>; 169 #gpio-cells = <2>;
152 gpio-bank = <8>; 170 gpio-bank = <8>;
153 }; 171 };
154 172
173 pinctrl {
174 compatible = "stericsson,nmk_pinctrl";
175 };
176
155 usb@a03e0000 { 177 usb@a03e0000 {
156 compatible = "stericsson,db8500-musb", 178 compatible = "stericsson,db8500-musb",
157 "mentor,musb"; 179 "mentor,musb";
@@ -169,20 +191,195 @@
169 prcmu@80157000 { 191 prcmu@80157000 {
170 compatible = "stericsson,db8500-prcmu"; 192 compatible = "stericsson,db8500-prcmu";
171 reg = <0x80157000 0x1000>; 193 reg = <0x80157000 0x1000>;
172 interrupts = <46 47>; 194 interrupts = <0 47 0x4>;
173 #address-cells = <1>; 195 #address-cells = <1>;
174 #size-cells = <1>; 196 #size-cells = <1>;
175 ranges; 197 ranges;
176 198
177 prcmu-timer-4@80157450 { 199 prcmu-timer-4@80157450 {
178 compatible = "stericsson,db8500-prcmu-timer-4"; 200 compatible = "stericsson,db8500-prcmu-timer-4";
179 reg = <0x80157450 0xC>; 201 reg = <0x80157450 0xC>;
180 }; 202 };
181 203
204 db8500-prcmu-regulators {
205 compatible = "stericsson,db8500-prcmu-regulator";
206
207 // DB8500_REGULATOR_VAPE
208 db8500_vape_reg: db8500_vape {
209 regulator-name = "db8500-vape";
210 regulator-always-on;
211 };
212
213 // DB8500_REGULATOR_VARM
214 db8500_varm_reg: db8500_varm {
215 regulator-name = "db8500-varm";
216 };
217
218 // DB8500_REGULATOR_VMODEM
219 db8500_vmodem_reg: db8500_vmodem {
220 regulator-name = "db8500-vmodem";
221 };
222
223 // DB8500_REGULATOR_VPLL
224 db8500_vpll_reg: db8500_vpll {
225 regulator-name = "db8500-vpll";
226 };
227
228 // DB8500_REGULATOR_VSMPS1
229 db8500_vsmps1_reg: db8500_vsmps1 {
230 regulator-name = "db8500-vsmps1";
231 };
232
233 // DB8500_REGULATOR_VSMPS2
234 db8500_vsmps2_reg: db8500_vsmps2 {
235 regulator-name = "db8500-vsmps2";
236 };
237
238 // DB8500_REGULATOR_VSMPS3
239 db8500_vsmps3_reg: db8500_vsmps3 {
240 regulator-name = "db8500-vsmps3";
241 };
242
243 // DB8500_REGULATOR_VRF1
244 db8500_vrf1_reg: db8500_vrf1 {
245 regulator-name = "db8500-vrf1";
246 };
247
248 // DB8500_REGULATOR_SWITCH_SVAMMDSP
249 db8500_sva_mmdsp_reg: db8500_sva_mmdsp {
250 regulator-name = "db8500-sva-mmdsp";
251 };
252
253 // DB8500_REGULATOR_SWITCH_SVAMMDSPRET
254 db8500_sva_mmdsp_ret_reg: db8500_sva_mmdsp_ret {
255 regulator-name = "db8500-sva-mmdsp-ret";
256 };
257
258 // DB8500_REGULATOR_SWITCH_SVAPIPE
259 db8500_sva_pipe_reg: db8500_sva_pipe {
260 regulator-name = "db8500_sva_pipe";
261 };
262
263 // DB8500_REGULATOR_SWITCH_SIAMMDSP
264 db8500_sia_mmdsp_reg: db8500_sia_mmdsp {
265 regulator-name = "db8500_sia_mmdsp";
266 };
267
268 // DB8500_REGULATOR_SWITCH_SIAMMDSPRET
269 db8500_sia_mmdsp_ret_reg: db8500_sia_mmdsp_ret {
270 regulator-name = "db8500-sia-mmdsp-ret";
271 };
272
273 // DB8500_REGULATOR_SWITCH_SIAPIPE
274 db8500_sia_pipe_reg: db8500_sia_pipe {
275 regulator-name = "db8500-sia-pipe";
276 };
277
278 // DB8500_REGULATOR_SWITCH_SGA
279 db8500_sga_reg: db8500_sga {
280 regulator-name = "db8500-sga";
281 vin-supply = <&db8500_vape_reg>;
282 };
283
284 // DB8500_REGULATOR_SWITCH_B2R2_MCDE
285 db8500_b2r2_mcde_reg: db8500_b2r2_mcde {
286 regulator-name = "db8500-b2r2-mcde";
287 vin-supply = <&db8500_vape_reg>;
288 };
289
290 // DB8500_REGULATOR_SWITCH_ESRAM12
291 db8500_esram12_reg: db8500_esram12 {
292 regulator-name = "db8500-esram12";
293 };
294
295 // DB8500_REGULATOR_SWITCH_ESRAM12RET
296 db8500_esram12_ret_reg: db8500_esram12_ret {
297 regulator-name = "db8500-esram12-ret";
298 };
299
300 // DB8500_REGULATOR_SWITCH_ESRAM34
301 db8500_esram34_reg: db8500_esram34 {
302 regulator-name = "db8500-esram34";
303 };
304
305 // DB8500_REGULATOR_SWITCH_ESRAM34RET
306 db8500_esram34_ret_reg: db8500_esram34_ret {
307 regulator-name = "db8500-esram34-ret";
308 };
309 };
310
182 ab8500@5 { 311 ab8500@5 {
183 compatible = "stericsson,ab8500"; 312 compatible = "stericsson,ab8500";
184 reg = <5>; /* mailbox 5 is i2c */ 313 reg = <5>; /* mailbox 5 is i2c */
185 interrupts = <0 40 0x4>; 314 interrupts = <0 40 0x4>;
315
316 ab8500-regulators {
317 compatible = "stericsson,ab8500-regulator";
318
319 // supplies to the display/camera
320 ab8500_ldo_aux1_reg: ab8500_ldo_aux1 {
321 regulator-name = "V-DISPLAY";
322 regulator-min-microvolt = <2500000>;
323 regulator-max-microvolt = <2900000>;
324 regulator-boot-on;
325 /* BUG: If turned off MMC will be affected. */
326 regulator-always-on;
327 };
328
329 // supplies to the on-board eMMC
330 ab8500_ldo_aux2_reg: ab8500_ldo_aux2 {
331 regulator-name = "V-eMMC1";
332 regulator-min-microvolt = <1100000>;
333 regulator-max-microvolt = <3300000>;
334 };
335
336 // supply for VAUX3; SDcard slots
337 ab8500_ldo_aux3_reg: ab8500_ldo_aux3 {
338 regulator-name = "V-MMC-SD";
339 regulator-min-microvolt = <1100000>;
340 regulator-max-microvolt = <3300000>;
341 };
342
343 // supply for v-intcore12; VINTCORE12 LDO
344 ab8500_ldo_initcore_reg: ab8500_ldo_initcore {
345 regulator-name = "V-INTCORE";
346 };
347
348 // supply for tvout; gpadc; TVOUT LDO
349 ab8500_ldo_tvout_reg: ab8500_ldo_tvout {
350 regulator-name = "V-TVOUT";
351 };
352
353 // supply for ab8500-usb; USB LDO
354 ab8500_ldo_usb_reg: ab8500_ldo_usb {
355 regulator-name = "dummy";
356 };
357
358 // supply for ab8500-vaudio; VAUDIO LDO
359 ab8500_ldo_audio_reg: ab8500_ldo_audio {
360 regulator-name = "V-AUD";
361 };
362
363 // supply for v-anamic1 VAMic1-LDO
364 ab8500_ldo_anamic1_reg: ab8500_ldo_anamic1 {
365 regulator-name = "V-AMIC1";
366 };
367
368 // supply for v-amic2; VAMIC2 LDO; reuse constants for AMIC1
369 ab8500_ldo_amamic2_reg: ab8500_ldo_amamic2 {
370 regulator-name = "V-AMIC2";
371 };
372
373 // supply for v-dmic; VDMIC LDO
374 ab8500_ldo_dmic_reg: ab8500_ldo_dmic {
375 regulator-name = "V-DMIC";
376 };
377
378 // supply for U8500 CSI/DSI; VANA LDO
379 ab8500_ldo_ana_reg: ab8500_ldo_ana {
380 regulator-name = "V-CSI/DSI";
381 };
382 };
186 }; 383 };
187 }; 384 };
188 385
@@ -235,7 +432,8 @@
235 status = "disabled"; 432 status = "disabled";
236 433
237 // Add one of these for each child device 434 // Add one of these for each child device
238 cs-gpios = <&gpio0 31 &gpio4 14 &gpio4 16 &gpio6 22 &gpio7 0>; 435 cs-gpios = <&gpio0 31 0x4 &gpio4 14 0x4 &gpio4 16 0x4
436 &gpio6 22 0x4 &gpio7 0 0x4>;
239 437
240 }; 438 };
241 439
diff --git a/arch/arm/boot/dts/imx27.dtsi b/arch/arm/boot/dts/imx27.dtsi
index 2b1a166d41f9..386c769c38d1 100644
--- a/arch/arm/boot/dts/imx27.dtsi
+++ b/arch/arm/boot/dts/imx27.dtsi
@@ -213,5 +213,14 @@
213 status = "disabled"; 213 status = "disabled";
214 }; 214 };
215 }; 215 };
216 nand@d8000000 {
217 #address-cells = <1>;
218 #size-cells = <1>;
219
220 compatible = "fsl,imx27-nand";
221 reg = <0xd8000000 0x1000>;
222 interrupts = <29>;
223 status = "disabled";
224 };
216 }; 225 };
217}; 226};
diff --git a/arch/arm/boot/dts/snowball.dts b/arch/arm/boot/dts/snowball.dts
index d99dc04f0d91..ec3c33975110 100644
--- a/arch/arm/boot/dts/snowball.dts
+++ b/arch/arm/boot/dts/snowball.dts
@@ -20,6 +20,16 @@
20 reg = <0x00000000 0x20000000>; 20 reg = <0x00000000 0x20000000>;
21 }; 21 };
22 22
23 en_3v3_reg: en_3v3 {
24 compatible = "regulator-fixed";
25 regulator-name = "en-3v3-fixed-supply";
26 regulator-min-microvolt = <3300000>;
27 regulator-max-microvolt = <3300000>;
28 gpios = <&gpio0 26 0x4>; // 26
29 startup-delay-us = <5000>;
30 enable-active-high;
31 };
32
23 gpio_keys { 33 gpio_keys {
24 compatible = "gpio-keys"; 34 compatible = "gpio-keys";
25 #address-cells = <1>; 35 #address-cells = <1>;
@@ -30,35 +40,35 @@
30 wakeup = <1>; 40 wakeup = <1>;
31 linux,code = <2>; 41 linux,code = <2>;
32 label = "userpb"; 42 label = "userpb";
33 gpios = <&gpio1 0 0>; 43 gpios = <&gpio1 0 0x4>;
34 }; 44 };
35 button@2 { 45 button@2 {
36 debounce_interval = <50>; 46 debounce_interval = <50>;
37 wakeup = <1>; 47 wakeup = <1>;
38 linux,code = <3>; 48 linux,code = <3>;
39 label = "extkb1"; 49 label = "extkb1";
40 gpios = <&gpio4 23 0>; 50 gpios = <&gpio4 23 0x4>;
41 }; 51 };
42 button@3 { 52 button@3 {
43 debounce_interval = <50>; 53 debounce_interval = <50>;
44 wakeup = <1>; 54 wakeup = <1>;
45 linux,code = <4>; 55 linux,code = <4>;
46 label = "extkb2"; 56 label = "extkb2";
47 gpios = <&gpio4 24 0>; 57 gpios = <&gpio4 24 0x4>;
48 }; 58 };
49 button@4 { 59 button@4 {
50 debounce_interval = <50>; 60 debounce_interval = <50>;
51 wakeup = <1>; 61 wakeup = <1>;
52 linux,code = <5>; 62 linux,code = <5>;
53 label = "extkb3"; 63 label = "extkb3";
54 gpios = <&gpio5 1 0>; 64 gpios = <&gpio5 1 0x4>;
55 }; 65 };
56 button@5 { 66 button@5 {
57 debounce_interval = <50>; 67 debounce_interval = <50>;
58 wakeup = <1>; 68 wakeup = <1>;
59 linux,code = <6>; 69 linux,code = <6>;
60 label = "extkb4"; 70 label = "extkb4";
61 gpios = <&gpio5 2 0>; 71 gpios = <&gpio5 2 0x4>;
62 }; 72 };
63 }; 73 };
64 74
@@ -66,12 +76,11 @@
66 compatible = "gpio-leds"; 76 compatible = "gpio-leds";
67 used-led { 77 used-led {
68 label = "user_led"; 78 label = "user_led";
69 gpios = <&gpio4 14>; 79 gpios = <&gpio4 14 0x4>;
70 }; 80 };
71 }; 81 };
72 82
73 soc-u9500 { 83 soc-u9500 {
74
75 external-bus@50000000 { 84 external-bus@50000000 {
76 status = "okay"; 85 status = "okay";
77 86
@@ -80,6 +89,9 @@
80 reg = <0 0x10000>; 89 reg = <0 0x10000>;
81 interrupts = <12 0x1>; 90 interrupts = <12 0x1>;
82 interrupt-parent = <&gpio4>; 91 interrupt-parent = <&gpio4>;
92 vdd33a-supply = <&en_3v3_reg>;
93 vddvario-supply = <&db8500_vape_reg>;
94
83 95
84 reg-shift = <1>; 96 reg-shift = <1>;
85 reg-io-width = <2>; 97 reg-io-width = <2>;
@@ -91,11 +103,13 @@
91 103
92 sdi@80126000 { 104 sdi@80126000 {
93 status = "enabled"; 105 status = "enabled";
94 cd-gpios = <&gpio6 26>; 106 vmmc-supply = <&ab8500_ldo_aux3_reg>;
107 cd-gpios = <&gpio6 26 0x4>; // 218
95 }; 108 };
96 109
97 sdi@80114000 { 110 sdi@80114000 {
98 status = "enabled"; 111 status = "enabled";
112 vmmc-supply = <&ab8500_ldo_aux2_reg>;
99 }; 113 };
100 114
101 uart@80120000 { 115 uart@80120000 {
@@ -114,7 +128,7 @@
114 tc3589x@42 { 128 tc3589x@42 {
115 //compatible = "tc3589x"; 129 //compatible = "tc3589x";
116 reg = <0x42>; 130 reg = <0x42>;
117 interrupts = <25>; 131 gpios = <&gpio6 25 0x4>;
118 interrupt-parent = <&gpio6>; 132 interrupt-parent = <&gpio6>;
119 }; 133 };
120 tps61052@33 { 134 tps61052@33 {
diff --git a/arch/arm/configs/u8500_defconfig b/arch/arm/configs/u8500_defconfig
index 7e84f453e8a6..2d4f661d1cf6 100644
--- a/arch/arm/configs/u8500_defconfig
+++ b/arch/arm/configs/u8500_defconfig
@@ -75,6 +75,7 @@ CONFIG_AB5500_CORE=y
75CONFIG_AB8500_CORE=y 75CONFIG_AB8500_CORE=y
76CONFIG_REGULATOR=y 76CONFIG_REGULATOR=y
77CONFIG_REGULATOR_AB8500=y 77CONFIG_REGULATOR_AB8500=y
78CONFIG_REGULATOR_FIXED_VOLTAGE=y
78# CONFIG_HID_SUPPORT is not set 79# CONFIG_HID_SUPPORT is not set
79CONFIG_USB_GADGET=y 80CONFIG_USB_GADGET=y
80CONFIG_AB8500_USB=y 81CONFIG_AB8500_USB=y
diff --git a/arch/arm/include/asm/posix_types.h b/arch/arm/include/asm/posix_types.h
index efdf99045d87..d2de9cbbcd9b 100644
--- a/arch/arm/include/asm/posix_types.h
+++ b/arch/arm/include/asm/posix_types.h
@@ -22,9 +22,6 @@
22typedef unsigned short __kernel_mode_t; 22typedef unsigned short __kernel_mode_t;
23#define __kernel_mode_t __kernel_mode_t 23#define __kernel_mode_t __kernel_mode_t
24 24
25typedef unsigned short __kernel_nlink_t;
26#define __kernel_nlink_t __kernel_nlink_t
27
28typedef unsigned short __kernel_ipc_pid_t; 25typedef unsigned short __kernel_ipc_pid_t;
29#define __kernel_ipc_pid_t __kernel_ipc_pid_t 26#define __kernel_ipc_pid_t __kernel_ipc_pid_t
30 27
diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
index 17fc36c41cff..fd2392a17ac1 100644
--- a/arch/arm/kernel/signal.c
+++ b/arch/arm/kernel/signal.c
@@ -22,8 +22,6 @@
22 22
23#include "signal.h" 23#include "signal.h"
24 24
25#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
26
27/* 25/*
28 * For ARM syscalls, we encode the syscall number into the instruction. 26 * For ARM syscalls, we encode the syscall number into the instruction.
29 */ 27 */
@@ -210,10 +208,8 @@ static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
210 int err; 208 int err;
211 209
212 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set)); 210 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
213 if (err == 0) { 211 if (err == 0)
214 sigdelsetmask(&set, ~_BLOCKABLE);
215 set_current_blocked(&set); 212 set_current_blocked(&set);
216 }
217 213
218 __get_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err); 214 __get_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
219 __get_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err); 215 __get_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
@@ -528,13 +524,13 @@ setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
528/* 524/*
529 * OK, we're invoking a handler 525 * OK, we're invoking a handler
530 */ 526 */
531static int 527static void
532handle_signal(unsigned long sig, struct k_sigaction *ka, 528handle_signal(unsigned long sig, struct k_sigaction *ka,
533 siginfo_t *info, sigset_t *oldset, 529 siginfo_t *info, struct pt_regs *regs)
534 struct pt_regs * regs)
535{ 530{
536 struct thread_info *thread = current_thread_info(); 531 struct thread_info *thread = current_thread_info();
537 struct task_struct *tsk = current; 532 struct task_struct *tsk = current;
533 sigset_t *oldset = sigmask_to_save();
538 int usig = sig; 534 int usig = sig;
539 int ret; 535 int ret;
540 536
@@ -559,17 +555,9 @@ handle_signal(unsigned long sig, struct k_sigaction *ka,
559 555
560 if (ret != 0) { 556 if (ret != 0) {
561 force_sigsegv(sig, tsk); 557 force_sigsegv(sig, tsk);
562 return ret; 558 return;
563 } 559 }
564 560 signal_delivered(sig, info, ka, regs, 0);
565 /*
566 * Block the signal if we were successful.
567 */
568 block_sigmask(ka, sig);
569
570 tracehook_signal_handler(sig, info, ka, regs, 0);
571
572 return 0;
573} 561}
574 562
575/* 563/*
@@ -617,8 +605,6 @@ static void do_signal(struct pt_regs *regs, int syscall)
617 */ 605 */
618 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 606 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
619 if (signr > 0) { 607 if (signr > 0) {
620 sigset_t *oldset;
621
622 /* 608 /*
623 * Depending on the signal settings we may need to revert the 609 * Depending on the signal settings we may need to revert the
624 * decision to restart the system call. But skip this if a 610 * decision to restart the system call. But skip this if a
@@ -635,20 +621,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
635 clear_thread_flag(TIF_SYSCALL_RESTARTSYS); 621 clear_thread_flag(TIF_SYSCALL_RESTARTSYS);
636 } 622 }
637 623
638 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 624 handle_signal(signr, &ka, &info, regs);
639 oldset = &current->saved_sigmask;
640 else
641 oldset = &current->blocked;
642 if (handle_signal(signr, &ka, &info, oldset, regs) == 0) {
643 /*
644 * A signal was successfully delivered; the saved
645 * sigmask will have been stored in the signal frame,
646 * and will be restored by sigreturn, so we can simply
647 * clear the TIF_RESTORE_SIGMASK flag.
648 */
649 if (test_thread_flag(TIF_RESTORE_SIGMASK))
650 clear_thread_flag(TIF_RESTORE_SIGMASK);
651 }
652 return; 625 return;
653 } 626 }
654 627
@@ -663,11 +636,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
663 set_thread_flag(TIF_SYSCALL_RESTARTSYS); 636 set_thread_flag(TIF_SYSCALL_RESTARTSYS);
664 } 637 }
665 638
666 /* If there's no signal to deliver, we just put the saved sigmask 639 restore_saved_sigmask();
667 * back.
668 */
669 if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK))
670 set_current_blocked(&current->saved_sigmask);
671} 640}
672 641
673asmlinkage void 642asmlinkage void
@@ -679,7 +648,5 @@ do_notify_resume(struct pt_regs *regs, unsigned int thread_flags, int syscall)
679 if (thread_flags & _TIF_NOTIFY_RESUME) { 648 if (thread_flags & _TIF_NOTIFY_RESUME) {
680 clear_thread_flag(TIF_NOTIFY_RESUME); 649 clear_thread_flag(TIF_NOTIFY_RESUME);
681 tracehook_notify_resume(regs); 650 tracehook_notify_resume(regs);
682 if (current->replacement_session_keyring)
683 key_replace_session_keyring();
684 } 651 }
685} 652}
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index b735521a4a54..2c7217d971db 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -109,7 +109,6 @@ static void percpu_timer_stop(void);
109int __cpu_disable(void) 109int __cpu_disable(void)
110{ 110{
111 unsigned int cpu = smp_processor_id(); 111 unsigned int cpu = smp_processor_id();
112 struct task_struct *p;
113 int ret; 112 int ret;
114 113
115 ret = platform_cpu_disable(cpu); 114 ret = platform_cpu_disable(cpu);
@@ -139,12 +138,7 @@ int __cpu_disable(void)
139 flush_cache_all(); 138 flush_cache_all();
140 local_flush_tlb_all(); 139 local_flush_tlb_all();
141 140
142 read_lock(&tasklist_lock); 141 clear_tasks_mm_cpumask(cpu);
143 for_each_process(p) {
144 if (p->mm)
145 cpumask_clear_cpu(cpu, mm_cpumask(p->mm));
146 }
147 read_unlock(&tasklist_lock);
148 142
149 return 0; 143 return 0;
150} 144}
diff --git a/arch/arm/mach-ep93xx/snappercl15.c b/arch/arm/mach-ep93xx/snappercl15.c
index eb282378fa78..01abd3516a77 100644
--- a/arch/arm/mach-ep93xx/snappercl15.c
+++ b/arch/arm/mach-ep93xx/snappercl15.c
@@ -82,8 +82,6 @@ static int snappercl15_nand_dev_ready(struct mtd_info *mtd)
82 return !!(__raw_readw(NAND_CTRL_ADDR(chip)) & SNAPPERCL15_NAND_RDY); 82 return !!(__raw_readw(NAND_CTRL_ADDR(chip)) & SNAPPERCL15_NAND_RDY);
83} 83}
84 84
85static const char *snappercl15_nand_part_probes[] = {"cmdlinepart", NULL};
86
87static struct mtd_partition snappercl15_nand_parts[] = { 85static struct mtd_partition snappercl15_nand_parts[] = {
88 { 86 {
89 .name = "Kernel", 87 .name = "Kernel",
@@ -100,10 +98,8 @@ static struct mtd_partition snappercl15_nand_parts[] = {
100static struct platform_nand_data snappercl15_nand_data = { 98static struct platform_nand_data snappercl15_nand_data = {
101 .chip = { 99 .chip = {
102 .nr_chips = 1, 100 .nr_chips = 1,
103 .part_probe_types = snappercl15_nand_part_probes,
104 .partitions = snappercl15_nand_parts, 101 .partitions = snappercl15_nand_parts,
105 .nr_partitions = ARRAY_SIZE(snappercl15_nand_parts), 102 .nr_partitions = ARRAY_SIZE(snappercl15_nand_parts),
106 .options = NAND_NO_AUTOINCR,
107 .chip_delay = 25, 103 .chip_delay = 25,
108 }, 104 },
109 .ctrl = { 105 .ctrl = {
diff --git a/arch/arm/mach-ep93xx/ts72xx.c b/arch/arm/mach-ep93xx/ts72xx.c
index d4ef339d961e..75cab2d7ec73 100644
--- a/arch/arm/mach-ep93xx/ts72xx.c
+++ b/arch/arm/mach-ep93xx/ts72xx.c
@@ -105,8 +105,6 @@ static int ts72xx_nand_device_ready(struct mtd_info *mtd)
105 return !!(__raw_readb(addr) & 0x20); 105 return !!(__raw_readb(addr) & 0x20);
106} 106}
107 107
108static const char *ts72xx_nand_part_probes[] = { "cmdlinepart", NULL };
109
110#define TS72XX_BOOTROM_PART_SIZE (SZ_16K) 108#define TS72XX_BOOTROM_PART_SIZE (SZ_16K)
111#define TS72XX_REDBOOT_PART_SIZE (SZ_2M + SZ_1M) 109#define TS72XX_REDBOOT_PART_SIZE (SZ_2M + SZ_1M)
112 110
@@ -134,7 +132,6 @@ static struct platform_nand_data ts72xx_nand_data = {
134 .nr_chips = 1, 132 .nr_chips = 1,
135 .chip_offset = 0, 133 .chip_offset = 0,
136 .chip_delay = 15, 134 .chip_delay = 15,
137 .part_probe_types = ts72xx_nand_part_probes,
138 .partitions = ts72xx_nand_parts, 135 .partitions = ts72xx_nand_parts,
139 .nr_partitions = ARRAY_SIZE(ts72xx_nand_parts), 136 .nr_partitions = ARRAY_SIZE(ts72xx_nand_parts),
140 }, 137 },
diff --git a/arch/arm/mach-exynos/mach-nuri.c b/arch/arm/mach-exynos/mach-nuri.c
index 972983e392bc..656f8fc9addd 100644
--- a/arch/arm/mach-exynos/mach-nuri.c
+++ b/arch/arm/mach-exynos/mach-nuri.c
@@ -237,25 +237,29 @@ static struct exynos_drm_fimd_pdata drm_fimd_pdata = {
237#else 237#else
238/* Frame Buffer */ 238/* Frame Buffer */
239static struct s3c_fb_pd_win nuri_fb_win0 = { 239static struct s3c_fb_pd_win nuri_fb_win0 = {
240 .win_mode = {
241 .left_margin = 64,
242 .right_margin = 16,
243 .upper_margin = 64,
244 .lower_margin = 1,
245 .hsync_len = 48,
246 .vsync_len = 3,
247 .xres = 1024,
248 .yres = 600,
249 .refresh = 60,
250 },
251 .max_bpp = 24, 240 .max_bpp = 24,
252 .default_bpp = 16, 241 .default_bpp = 16,
242 .xres = 1024,
243 .yres = 600,
253 .virtual_x = 1024, 244 .virtual_x = 1024,
254 .virtual_y = 2 * 600, 245 .virtual_y = 2 * 600,
255}; 246};
256 247
248static struct fb_videomode nuri_lcd_timing = {
249 .left_margin = 64,
250 .right_margin = 16,
251 .upper_margin = 64,
252 .lower_margin = 1,
253 .hsync_len = 48,
254 .vsync_len = 3,
255 .xres = 1024,
256 .yres = 600,
257 .refresh = 60,
258};
259
257static struct s3c_fb_platdata nuri_fb_pdata __initdata = { 260static struct s3c_fb_platdata nuri_fb_pdata __initdata = {
258 .win[0] = &nuri_fb_win0, 261 .win[0] = &nuri_fb_win0,
262 .vtiming = &nuri_lcd_timing,
259 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB | 263 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB |
260 VIDCON0_CLKSEL_LCD, 264 VIDCON0_CLKSEL_LCD,
261 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, 265 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
diff --git a/arch/arm/mach-exynos/mach-origen.c b/arch/arm/mach-exynos/mach-origen.c
index a7f7fd567dde..f5572be9d7bf 100644
--- a/arch/arm/mach-exynos/mach-origen.c
+++ b/arch/arm/mach-exynos/mach-origen.c
@@ -604,24 +604,28 @@ static struct exynos_drm_fimd_pdata drm_fimd_pdata = {
604}; 604};
605#else 605#else
606static struct s3c_fb_pd_win origen_fb_win0 = { 606static struct s3c_fb_pd_win origen_fb_win0 = {
607 .win_mode = { 607 .xres = 1024,
608 .left_margin = 64, 608 .yres = 600,
609 .right_margin = 16,
610 .upper_margin = 64,
611 .lower_margin = 16,
612 .hsync_len = 48,
613 .vsync_len = 3,
614 .xres = 1024,
615 .yres = 600,
616 },
617 .max_bpp = 32, 609 .max_bpp = 32,
618 .default_bpp = 24, 610 .default_bpp = 24,
619 .virtual_x = 1024, 611 .virtual_x = 1024,
620 .virtual_y = 2 * 600, 612 .virtual_y = 2 * 600,
621}; 613};
622 614
615static struct fb_videomode origen_lcd_timing = {
616 .left_margin = 64,
617 .right_margin = 16,
618 .upper_margin = 64,
619 .lower_margin = 16,
620 .hsync_len = 48,
621 .vsync_len = 3,
622 .xres = 1024,
623 .yres = 600,
624};
625
623static struct s3c_fb_platdata origen_lcd_pdata __initdata = { 626static struct s3c_fb_platdata origen_lcd_pdata __initdata = {
624 .win[0] = &origen_fb_win0, 627 .win[0] = &origen_fb_win0,
628 .vtiming = &origen_lcd_timing,
625 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 629 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
626 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC | 630 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC |
627 VIDCON1_INV_VCLK, 631 VIDCON1_INV_VCLK,
diff --git a/arch/arm/mach-exynos/mach-smdkv310.c b/arch/arm/mach-exynos/mach-smdkv310.c
index 70df1a0c2118..262e9e446a96 100644
--- a/arch/arm/mach-exynos/mach-smdkv310.c
+++ b/arch/arm/mach-exynos/mach-smdkv310.c
@@ -178,22 +178,26 @@ static struct exynos_drm_fimd_pdata drm_fimd_pdata = {
178}; 178};
179#else 179#else
180static struct s3c_fb_pd_win smdkv310_fb_win0 = { 180static struct s3c_fb_pd_win smdkv310_fb_win0 = {
181 .win_mode = { 181 .max_bpp = 32,
182 .left_margin = 13, 182 .default_bpp = 24,
183 .right_margin = 8, 183 .xres = 800,
184 .upper_margin = 7, 184 .yres = 480,
185 .lower_margin = 5, 185};
186 .hsync_len = 3, 186
187 .vsync_len = 1, 187static struct fb_videomode smdkv310_lcd_timing = {
188 .xres = 800, 188 .left_margin = 13,
189 .yres = 480, 189 .right_margin = 8,
190 }, 190 .upper_margin = 7,
191 .max_bpp = 32, 191 .lower_margin = 5,
192 .default_bpp = 24, 192 .hsync_len = 3,
193 .vsync_len = 1,
194 .xres = 800,
195 .yres = 480,
193}; 196};
194 197
195static struct s3c_fb_platdata smdkv310_lcd0_pdata __initdata = { 198static struct s3c_fb_platdata smdkv310_lcd0_pdata __initdata = {
196 .win[0] = &smdkv310_fb_win0, 199 .win[0] = &smdkv310_fb_win0,
200 .vtiming = &smdkv310_lcd_timing,
197 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 201 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
198 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, 202 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
199 .setup_gpio = exynos4_fimd0_gpio_setup_24bpp, 203 .setup_gpio = exynos4_fimd0_gpio_setup_24bpp,
diff --git a/arch/arm/mach-exynos/mach-universal_c210.c b/arch/arm/mach-exynos/mach-universal_c210.c
index 083b44de9c10..cd92fa86ba41 100644
--- a/arch/arm/mach-exynos/mach-universal_c210.c
+++ b/arch/arm/mach-exynos/mach-universal_c210.c
@@ -843,25 +843,29 @@ static struct exynos_drm_fimd_pdata drm_fimd_pdata = {
843#else 843#else
844/* Frame Buffer */ 844/* Frame Buffer */
845static struct s3c_fb_pd_win universal_fb_win0 = { 845static struct s3c_fb_pd_win universal_fb_win0 = {
846 .win_mode = {
847 .left_margin = 16,
848 .right_margin = 16,
849 .upper_margin = 2,
850 .lower_margin = 28,
851 .hsync_len = 2,
852 .vsync_len = 1,
853 .xres = 480,
854 .yres = 800,
855 .refresh = 55,
856 },
857 .max_bpp = 32, 846 .max_bpp = 32,
858 .default_bpp = 16, 847 .default_bpp = 16,
848 .xres = 480,
849 .yres = 800,
859 .virtual_x = 480, 850 .virtual_x = 480,
860 .virtual_y = 2 * 800, 851 .virtual_y = 2 * 800,
861}; 852};
862 853
854static struct fb_videomode universal_lcd_timing = {
855 .left_margin = 16,
856 .right_margin = 16,
857 .upper_margin = 2,
858 .lower_margin = 28,
859 .hsync_len = 2,
860 .vsync_len = 1,
861 .xres = 480,
862 .yres = 800,
863 .refresh = 55,
864};
865
863static struct s3c_fb_platdata universal_lcd_pdata __initdata = { 866static struct s3c_fb_platdata universal_lcd_pdata __initdata = {
864 .win[0] = &universal_fb_win0, 867 .win[0] = &universal_fb_win0,
868 .vtiming = &universal_lcd_timing,
865 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB | 869 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB |
866 VIDCON0_CLKSEL_LCD, 870 VIDCON0_CLKSEL_LCD,
867 .vidcon1 = VIDCON1_INV_VCLK | VIDCON1_INV_VDEN 871 .vidcon1 = VIDCON1_INV_VCLK | VIDCON1_INV_VDEN
diff --git a/arch/arm/mach-imx/imx27-dt.c b/arch/arm/mach-imx/imx27-dt.c
index ed38d03c61f2..eee0cc8d92a4 100644
--- a/arch/arm/mach-imx/imx27-dt.c
+++ b/arch/arm/mach-imx/imx27-dt.c
@@ -29,6 +29,7 @@ static const struct of_dev_auxdata imx27_auxdata_lookup[] __initconst = {
29 OF_DEV_AUXDATA("fsl,imx27-cspi", MX27_CSPI2_BASE_ADDR, "imx27-cspi.1", NULL), 29 OF_DEV_AUXDATA("fsl,imx27-cspi", MX27_CSPI2_BASE_ADDR, "imx27-cspi.1", NULL),
30 OF_DEV_AUXDATA("fsl,imx27-cspi", MX27_CSPI3_BASE_ADDR, "imx27-cspi.2", NULL), 30 OF_DEV_AUXDATA("fsl,imx27-cspi", MX27_CSPI3_BASE_ADDR, "imx27-cspi.2", NULL),
31 OF_DEV_AUXDATA("fsl,imx27-wdt", MX27_WDOG_BASE_ADDR, "imx2-wdt.0", NULL), 31 OF_DEV_AUXDATA("fsl,imx27-wdt", MX27_WDOG_BASE_ADDR, "imx2-wdt.0", NULL),
32 OF_DEV_AUXDATA("fsl,imx27-nand", MX27_NFC_BASE_ADDR, "mxc_nand.0", NULL),
32 { /* sentinel */ } 33 { /* sentinel */ }
33}; 34};
34 35
diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index 3d742aee1773..108a9d3f382d 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -60,8 +60,6 @@ static struct platform_device ixdp425_flash = {
60#if defined(CONFIG_MTD_NAND_PLATFORM) || \ 60#if defined(CONFIG_MTD_NAND_PLATFORM) || \
61 defined(CONFIG_MTD_NAND_PLATFORM_MODULE) 61 defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
62 62
63const char *part_probes[] = { "cmdlinepart", NULL };
64
65static struct mtd_partition ixdp425_partitions[] = { 63static struct mtd_partition ixdp425_partitions[] = {
66 { 64 {
67 .name = "ixp400 NAND FS 0", 65 .name = "ixp400 NAND FS 0",
@@ -100,8 +98,6 @@ static struct platform_nand_data ixdp425_flash_nand_data = {
100 .chip = { 98 .chip = {
101 .nr_chips = 1, 99 .nr_chips = 1,
102 .chip_delay = 30, 100 .chip_delay = 30,
103 .options = NAND_NO_AUTOINCR,
104 .part_probe_types = part_probes,
105 .partitions = ixdp425_partitions, 101 .partitions = ixdp425_partitions,
106 .nr_partitions = ARRAY_SIZE(ixdp425_partitions), 102 .nr_partitions = ARRAY_SIZE(ixdp425_partitions),
107 }, 103 },
diff --git a/arch/arm/mach-nomadik/board-nhk8815.c b/arch/arm/mach-nomadik/board-nhk8815.c
index 58cacafcf662..2e8d3e176bc7 100644
--- a/arch/arm/mach-nomadik/board-nhk8815.c
+++ b/arch/arm/mach-nomadik/board-nhk8815.c
@@ -111,7 +111,7 @@ static struct nomadik_nand_platform_data nhk8815_nand_data = {
111 .parts = nhk8815_partitions, 111 .parts = nhk8815_partitions,
112 .nparts = ARRAY_SIZE(nhk8815_partitions), 112 .nparts = ARRAY_SIZE(nhk8815_partitions),
113 .options = NAND_COPYBACK | NAND_CACHEPRG | NAND_NO_PADDING \ 113 .options = NAND_COPYBACK | NAND_CACHEPRG | NAND_NO_PADDING \
114 | NAND_NO_READRDY | NAND_NO_AUTOINCR, 114 | NAND_NO_READRDY,
115 .init = nhk8815_nand_init, 115 .init = nhk8815_nand_init,
116}; 116};
117 117
diff --git a/arch/arm/mach-omap1/board-fsample.c b/arch/arm/mach-omap1/board-fsample.c
index c7364fdbda05..6872f3fd400f 100644
--- a/arch/arm/mach-omap1/board-fsample.c
+++ b/arch/arm/mach-omap1/board-fsample.c
@@ -192,14 +192,11 @@ static int nand_dev_ready(struct mtd_info *mtd)
192 return gpio_get_value(FSAMPLE_NAND_RB_GPIO_PIN); 192 return gpio_get_value(FSAMPLE_NAND_RB_GPIO_PIN);
193} 193}
194 194
195static const char *part_probes[] = { "cmdlinepart", NULL };
196
197static struct platform_nand_data nand_data = { 195static struct platform_nand_data nand_data = {
198 .chip = { 196 .chip = {
199 .nr_chips = 1, 197 .nr_chips = 1,
200 .chip_offset = 0, 198 .chip_offset = 0,
201 .options = NAND_SAMSUNG_LP_OPTIONS, 199 .options = NAND_SAMSUNG_LP_OPTIONS,
202 .part_probe_types = part_probes,
203 }, 200 },
204 .ctrl = { 201 .ctrl = {
205 .cmd_ctrl = omap1_nand_cmd_ctl, 202 .cmd_ctrl = omap1_nand_cmd_ctl,
diff --git a/arch/arm/mach-omap1/board-h2.c b/arch/arm/mach-omap1/board-h2.c
index 7e503686f7af..a28e989a63f4 100644
--- a/arch/arm/mach-omap1/board-h2.c
+++ b/arch/arm/mach-omap1/board-h2.c
@@ -186,8 +186,6 @@ static int h2_nand_dev_ready(struct mtd_info *mtd)
186 return gpio_get_value(H2_NAND_RB_GPIO_PIN); 186 return gpio_get_value(H2_NAND_RB_GPIO_PIN);
187} 187}
188 188
189static const char *h2_part_probes[] = { "cmdlinepart", NULL };
190
191static struct platform_nand_data h2_nand_platdata = { 189static struct platform_nand_data h2_nand_platdata = {
192 .chip = { 190 .chip = {
193 .nr_chips = 1, 191 .nr_chips = 1,
@@ -195,7 +193,6 @@ static struct platform_nand_data h2_nand_platdata = {
195 .nr_partitions = ARRAY_SIZE(h2_nand_partitions), 193 .nr_partitions = ARRAY_SIZE(h2_nand_partitions),
196 .partitions = h2_nand_partitions, 194 .partitions = h2_nand_partitions,
197 .options = NAND_SAMSUNG_LP_OPTIONS, 195 .options = NAND_SAMSUNG_LP_OPTIONS,
198 .part_probe_types = h2_part_probes,
199 }, 196 },
200 .ctrl = { 197 .ctrl = {
201 .cmd_ctrl = omap1_nand_cmd_ctl, 198 .cmd_ctrl = omap1_nand_cmd_ctl,
diff --git a/arch/arm/mach-omap1/board-h3.c b/arch/arm/mach-omap1/board-h3.c
index 9fb03f189d93..108a8640fc6f 100644
--- a/arch/arm/mach-omap1/board-h3.c
+++ b/arch/arm/mach-omap1/board-h3.c
@@ -188,8 +188,6 @@ static int nand_dev_ready(struct mtd_info *mtd)
188 return gpio_get_value(H3_NAND_RB_GPIO_PIN); 188 return gpio_get_value(H3_NAND_RB_GPIO_PIN);
189} 189}
190 190
191static const char *part_probes[] = { "cmdlinepart", NULL };
192
193static struct platform_nand_data nand_platdata = { 191static struct platform_nand_data nand_platdata = {
194 .chip = { 192 .chip = {
195 .nr_chips = 1, 193 .nr_chips = 1,
@@ -197,7 +195,6 @@ static struct platform_nand_data nand_platdata = {
197 .nr_partitions = ARRAY_SIZE(nand_partitions), 195 .nr_partitions = ARRAY_SIZE(nand_partitions),
198 .partitions = nand_partitions, 196 .partitions = nand_partitions,
199 .options = NAND_SAMSUNG_LP_OPTIONS, 197 .options = NAND_SAMSUNG_LP_OPTIONS,
200 .part_probe_types = part_probes,
201 }, 198 },
202 .ctrl = { 199 .ctrl = {
203 .cmd_ctrl = omap1_nand_cmd_ctl, 200 .cmd_ctrl = omap1_nand_cmd_ctl,
diff --git a/arch/arm/mach-omap1/board-perseus2.c b/arch/arm/mach-omap1/board-perseus2.c
index f2cb24387c22..703d55ecffe2 100644
--- a/arch/arm/mach-omap1/board-perseus2.c
+++ b/arch/arm/mach-omap1/board-perseus2.c
@@ -150,14 +150,11 @@ static int nand_dev_ready(struct mtd_info *mtd)
150 return gpio_get_value(P2_NAND_RB_GPIO_PIN); 150 return gpio_get_value(P2_NAND_RB_GPIO_PIN);
151} 151}
152 152
153static const char *part_probes[] = { "cmdlinepart", NULL };
154
155static struct platform_nand_data nand_data = { 153static struct platform_nand_data nand_data = {
156 .chip = { 154 .chip = {
157 .nr_chips = 1, 155 .nr_chips = 1,
158 .chip_offset = 0, 156 .chip_offset = 0,
159 .options = NAND_SAMSUNG_LP_OPTIONS, 157 .options = NAND_SAMSUNG_LP_OPTIONS,
160 .part_probe_types = part_probes,
161 }, 158 },
162 .ctrl = { 159 .ctrl = {
163 .cmd_ctrl = omap1_nand_cmd_ctl, 160 .cmd_ctrl = omap1_nand_cmd_ctl,
diff --git a/arch/arm/mach-omap2/display.c b/arch/arm/mach-omap2/display.c
index db5a88a36c63..54d49ddb9b81 100644
--- a/arch/arm/mach-omap2/display.c
+++ b/arch/arm/mach-omap2/display.c
@@ -180,16 +180,133 @@ static void omap_dsi_disable_pads(int dsi_id, unsigned lane_mask)
180 omap4_dsi_mux_pads(dsi_id, 0); 180 omap4_dsi_mux_pads(dsi_id, 0);
181} 181}
182 182
183static int omap_dss_set_min_bus_tput(struct device *dev, unsigned long tput)
184{
185 return omap_pm_set_min_bus_tput(dev, OCP_INITIATOR_AGENT, tput);
186}
187
188static struct platform_device *create_dss_pdev(const char *pdev_name,
189 int pdev_id, const char *oh_name, void *pdata, int pdata_len,
190 struct platform_device *parent)
191{
192 struct platform_device *pdev;
193 struct omap_device *od;
194 struct omap_hwmod *ohs[1];
195 struct omap_hwmod *oh;
196 int r;
197
198 oh = omap_hwmod_lookup(oh_name);
199 if (!oh) {
200 pr_err("Could not look up %s\n", oh_name);
201 r = -ENODEV;
202 goto err;
203 }
204
205 pdev = platform_device_alloc(pdev_name, pdev_id);
206 if (!pdev) {
207 pr_err("Could not create pdev for %s\n", pdev_name);
208 r = -ENOMEM;
209 goto err;
210 }
211
212 if (parent != NULL)
213 pdev->dev.parent = &parent->dev;
214
215 if (pdev->id != -1)
216 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
217 else
218 dev_set_name(&pdev->dev, "%s", pdev->name);
219
220 ohs[0] = oh;
221 od = omap_device_alloc(pdev, ohs, 1, NULL, 0);
222 if (!od) {
223 pr_err("Could not alloc omap_device for %s\n", pdev_name);
224 r = -ENOMEM;
225 goto err;
226 }
227
228 r = platform_device_add_data(pdev, pdata, pdata_len);
229 if (r) {
230 pr_err("Could not set pdata for %s\n", pdev_name);
231 goto err;
232 }
233
234 r = omap_device_register(pdev);
235 if (r) {
236 pr_err("Could not register omap_device for %s\n", pdev_name);
237 goto err;
238 }
239
240 return pdev;
241
242err:
243 return ERR_PTR(r);
244}
245
246static struct platform_device *create_simple_dss_pdev(const char *pdev_name,
247 int pdev_id, void *pdata, int pdata_len,
248 struct platform_device *parent)
249{
250 struct platform_device *pdev;
251 int r;
252
253 pdev = platform_device_alloc(pdev_name, pdev_id);
254 if (!pdev) {
255 pr_err("Could not create pdev for %s\n", pdev_name);
256 r = -ENOMEM;
257 goto err;
258 }
259
260 if (parent != NULL)
261 pdev->dev.parent = &parent->dev;
262
263 if (pdev->id != -1)
264 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
265 else
266 dev_set_name(&pdev->dev, "%s", pdev->name);
267
268 r = platform_device_add_data(pdev, pdata, pdata_len);
269 if (r) {
270 pr_err("Could not set pdata for %s\n", pdev_name);
271 goto err;
272 }
273
274 r = omap_device_register(pdev);
275 if (r) {
276 pr_err("Could not register omap_device for %s\n", pdev_name);
277 goto err;
278 }
279
280 return pdev;
281
282err:
283 return ERR_PTR(r);
284}
285
183int __init omap_display_init(struct omap_dss_board_info *board_data) 286int __init omap_display_init(struct omap_dss_board_info *board_data)
184{ 287{
185 int r = 0; 288 int r = 0;
186 struct omap_hwmod *oh;
187 struct platform_device *pdev; 289 struct platform_device *pdev;
188 int i, oh_count; 290 int i, oh_count;
189 struct omap_display_platform_data pdata;
190 const struct omap_dss_hwmod_data *curr_dss_hwmod; 291 const struct omap_dss_hwmod_data *curr_dss_hwmod;
292 struct platform_device *dss_pdev;
293
294 /* create omapdss device */
295
296 board_data->dsi_enable_pads = omap_dsi_enable_pads;
297 board_data->dsi_disable_pads = omap_dsi_disable_pads;
298 board_data->get_context_loss_count = omap_pm_get_dev_context_loss_count;
299 board_data->set_min_bus_tput = omap_dss_set_min_bus_tput;
300
301 omap_display_device.dev.platform_data = board_data;
302
303 r = platform_device_register(&omap_display_device);
304 if (r < 0) {
305 pr_err("Unable to register omapdss device\n");
306 return r;
307 }
191 308
192 memset(&pdata, 0, sizeof(pdata)); 309 /* create devices for dss hwmods */
193 310
194 if (cpu_is_omap24xx()) { 311 if (cpu_is_omap24xx()) {
195 curr_dss_hwmod = omap2_dss_hwmod_data; 312 curr_dss_hwmod = omap2_dss_hwmod_data;
@@ -202,39 +319,58 @@ int __init omap_display_init(struct omap_dss_board_info *board_data)
202 oh_count = ARRAY_SIZE(omap4_dss_hwmod_data); 319 oh_count = ARRAY_SIZE(omap4_dss_hwmod_data);
203 } 320 }
204 321
205 if (board_data->dsi_enable_pads == NULL) 322 /*
206 board_data->dsi_enable_pads = omap_dsi_enable_pads; 323 * First create the pdev for dss_core, which is used as a parent device
207 if (board_data->dsi_disable_pads == NULL) 324 * by the other dss pdevs. Note: dss_core has to be the first item in
208 board_data->dsi_disable_pads = omap_dsi_disable_pads; 325 * the hwmod list.
209 326 */
210 pdata.board_data = board_data; 327 dss_pdev = create_dss_pdev(curr_dss_hwmod[0].dev_name,
211 pdata.board_data->get_context_loss_count = 328 curr_dss_hwmod[0].id,
212 omap_pm_get_dev_context_loss_count; 329 curr_dss_hwmod[0].oh_name,
213 330 board_data, sizeof(*board_data),
214 for (i = 0; i < oh_count; i++) { 331 NULL);
215 oh = omap_hwmod_lookup(curr_dss_hwmod[i].oh_name); 332
216 if (!oh) { 333 if (IS_ERR(dss_pdev)) {
217 pr_err("Could not look up %s\n", 334 pr_err("Could not build omap_device for %s\n",
218 curr_dss_hwmod[i].oh_name); 335 curr_dss_hwmod[0].oh_name);
219 return -ENODEV; 336
337 return PTR_ERR(dss_pdev);
338 }
339
340 for (i = 1; i < oh_count; i++) {
341 pdev = create_dss_pdev(curr_dss_hwmod[i].dev_name,
342 curr_dss_hwmod[i].id,
343 curr_dss_hwmod[i].oh_name,
344 board_data, sizeof(*board_data),
345 dss_pdev);
346
347 if (IS_ERR(pdev)) {
348 pr_err("Could not build omap_device for %s\n",
349 curr_dss_hwmod[i].oh_name);
350
351 return PTR_ERR(pdev);
220 } 352 }
353 }
221 354
222 pdev = omap_device_build(curr_dss_hwmod[i].dev_name, 355 /* Create devices for DPI and SDI */
223 curr_dss_hwmod[i].id, oh, &pdata,
224 sizeof(struct omap_display_platform_data),
225 NULL, 0, 0);
226 356
227 if (WARN((IS_ERR(pdev)), "Could not build omap_device for %s\n", 357 pdev = create_simple_dss_pdev("omapdss_dpi", -1,
228 curr_dss_hwmod[i].oh_name)) 358 board_data, sizeof(*board_data), dss_pdev);
229 return -ENODEV; 359 if (IS_ERR(pdev)) {
360 pr_err("Could not build platform_device for omapdss_dpi\n");
361 return PTR_ERR(pdev);
230 } 362 }
231 omap_display_device.dev.platform_data = board_data;
232 363
233 r = platform_device_register(&omap_display_device); 364 if (cpu_is_omap34xx()) {
234 if (r < 0) 365 pdev = create_simple_dss_pdev("omapdss_sdi", -1,
235 printk(KERN_ERR "Unable to register OMAP-Display device\n"); 366 board_data, sizeof(*board_data), dss_pdev);
367 if (IS_ERR(pdev)) {
368 pr_err("Could not build platform_device for omapdss_sdi\n");
369 return PTR_ERR(pdev);
370 }
371 }
236 372
237 return r; 373 return 0;
238} 374}
239 375
240static void dispc_disable_outputs(void) 376static void dispc_disable_outputs(void)
diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
index 46b09dae770e..2286410671e7 100644
--- a/arch/arm/mach-omap2/gpmc.c
+++ b/arch/arm/mach-omap2/gpmc.c
@@ -49,6 +49,7 @@
49#define GPMC_ECC_CONTROL 0x1f8 49#define GPMC_ECC_CONTROL 0x1f8
50#define GPMC_ECC_SIZE_CONFIG 0x1fc 50#define GPMC_ECC_SIZE_CONFIG 0x1fc
51#define GPMC_ECC1_RESULT 0x200 51#define GPMC_ECC1_RESULT 0x200
52#define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */
52 53
53/* GPMC ECC control settings */ 54/* GPMC ECC control settings */
54#define GPMC_ECC_CTRL_ECCCLEAR 0x100 55#define GPMC_ECC_CTRL_ECCCLEAR 0x100
@@ -935,3 +936,186 @@ int gpmc_calculate_ecc(int cs, const u_char *dat, u_char *ecc_code)
935 return 0; 936 return 0;
936} 937}
937EXPORT_SYMBOL_GPL(gpmc_calculate_ecc); 938EXPORT_SYMBOL_GPL(gpmc_calculate_ecc);
939
940#ifdef CONFIG_ARCH_OMAP3
941
942/**
943 * gpmc_init_hwecc_bch - initialize hardware BCH ecc functionality
944 * @cs: chip select number
945 * @nsectors: how many 512-byte sectors to process
946 * @nerrors: how many errors to correct per sector (4 or 8)
947 *
948 * This function must be executed before any call to gpmc_enable_hwecc_bch.
949 */
950int gpmc_init_hwecc_bch(int cs, int nsectors, int nerrors)
951{
952 /* check if ecc module is in use */
953 if (gpmc_ecc_used != -EINVAL)
954 return -EINVAL;
955
956 /* support only OMAP3 class */
957 if (!cpu_is_omap34xx()) {
958 printk(KERN_ERR "BCH ecc is not supported on this CPU\n");
959 return -EINVAL;
960 }
961
962 /*
963 * For now, assume 4-bit mode is only supported on OMAP3630 ES1.x, x>=1.
964 * Other chips may be added if confirmed to work.
965 */
966 if ((nerrors == 4) &&
967 (!cpu_is_omap3630() || (GET_OMAP_REVISION() == 0))) {
968 printk(KERN_ERR "BCH 4-bit mode is not supported on this CPU\n");
969 return -EINVAL;
970 }
971
972 /* sanity check */
973 if (nsectors > 8) {
974 printk(KERN_ERR "BCH cannot process %d sectors (max is 8)\n",
975 nsectors);
976 return -EINVAL;
977 }
978
979 return 0;
980}
981EXPORT_SYMBOL_GPL(gpmc_init_hwecc_bch);
982
983/**
984 * gpmc_enable_hwecc_bch - enable hardware BCH ecc functionality
985 * @cs: chip select number
986 * @mode: read/write mode
987 * @dev_width: device bus width(1 for x16, 0 for x8)
988 * @nsectors: how many 512-byte sectors to process
989 * @nerrors: how many errors to correct per sector (4 or 8)
990 */
991int gpmc_enable_hwecc_bch(int cs, int mode, int dev_width, int nsectors,
992 int nerrors)
993{
994 unsigned int val;
995
996 /* check if ecc module is in use */
997 if (gpmc_ecc_used != -EINVAL)
998 return -EINVAL;
999
1000 gpmc_ecc_used = cs;
1001
1002 /* clear ecc and enable bits */
1003 gpmc_write_reg(GPMC_ECC_CONTROL, 0x1);
1004
1005 /*
1006 * When using BCH, sector size is hardcoded to 512 bytes.
1007 * Here we are using wrapping mode 6 both for reading and writing, with:
1008 * size0 = 0 (no additional protected byte in spare area)
1009 * size1 = 32 (skip 32 nibbles = 16 bytes per sector in spare area)
1010 */
1011 gpmc_write_reg(GPMC_ECC_SIZE_CONFIG, (32 << 22) | (0 << 12));
1012
1013 /* BCH configuration */
1014 val = ((1 << 16) | /* enable BCH */
1015 (((nerrors == 8) ? 1 : 0) << 12) | /* 8 or 4 bits */
1016 (0x06 << 8) | /* wrap mode = 6 */
1017 (dev_width << 7) | /* bus width */
1018 (((nsectors-1) & 0x7) << 4) | /* number of sectors */
1019 (cs << 1) | /* ECC CS */
1020 (0x1)); /* enable ECC */
1021
1022 gpmc_write_reg(GPMC_ECC_CONFIG, val);
1023 gpmc_write_reg(GPMC_ECC_CONTROL, 0x101);
1024 return 0;
1025}
1026EXPORT_SYMBOL_GPL(gpmc_enable_hwecc_bch);
1027
1028/**
1029 * gpmc_calculate_ecc_bch4 - Generate 7 ecc bytes per sector of 512 data bytes
1030 * @cs: chip select number
1031 * @dat: The pointer to data on which ecc is computed
1032 * @ecc: The ecc output buffer
1033 */
1034int gpmc_calculate_ecc_bch4(int cs, const u_char *dat, u_char *ecc)
1035{
1036 int i;
1037 unsigned long nsectors, reg, val1, val2;
1038
1039 if (gpmc_ecc_used != cs)
1040 return -EINVAL;
1041
1042 nsectors = ((gpmc_read_reg(GPMC_ECC_CONFIG) >> 4) & 0x7) + 1;
1043
1044 for (i = 0; i < nsectors; i++) {
1045
1046 reg = GPMC_ECC_BCH_RESULT_0 + 16*i;
1047
1048 /* Read hw-computed remainder */
1049 val1 = gpmc_read_reg(reg + 0);
1050 val2 = gpmc_read_reg(reg + 4);
1051
1052 /*
1053 * Add constant polynomial to remainder, in order to get an ecc
1054 * sequence of 0xFFs for a buffer filled with 0xFFs; and
1055 * left-justify the resulting polynomial.
1056 */
1057 *ecc++ = 0x28 ^ ((val2 >> 12) & 0xFF);
1058 *ecc++ = 0x13 ^ ((val2 >> 4) & 0xFF);
1059 *ecc++ = 0xcc ^ (((val2 & 0xF) << 4)|((val1 >> 28) & 0xF));
1060 *ecc++ = 0x39 ^ ((val1 >> 20) & 0xFF);
1061 *ecc++ = 0x96 ^ ((val1 >> 12) & 0xFF);
1062 *ecc++ = 0xac ^ ((val1 >> 4) & 0xFF);
1063 *ecc++ = 0x7f ^ ((val1 & 0xF) << 4);
1064 }
1065
1066 gpmc_ecc_used = -EINVAL;
1067 return 0;
1068}
1069EXPORT_SYMBOL_GPL(gpmc_calculate_ecc_bch4);
1070
1071/**
1072 * gpmc_calculate_ecc_bch8 - Generate 13 ecc bytes per block of 512 data bytes
1073 * @cs: chip select number
1074 * @dat: The pointer to data on which ecc is computed
1075 * @ecc: The ecc output buffer
1076 */
1077int gpmc_calculate_ecc_bch8(int cs, const u_char *dat, u_char *ecc)
1078{
1079 int i;
1080 unsigned long nsectors, reg, val1, val2, val3, val4;
1081
1082 if (gpmc_ecc_used != cs)
1083 return -EINVAL;
1084
1085 nsectors = ((gpmc_read_reg(GPMC_ECC_CONFIG) >> 4) & 0x7) + 1;
1086
1087 for (i = 0; i < nsectors; i++) {
1088
1089 reg = GPMC_ECC_BCH_RESULT_0 + 16*i;
1090
1091 /* Read hw-computed remainder */
1092 val1 = gpmc_read_reg(reg + 0);
1093 val2 = gpmc_read_reg(reg + 4);
1094 val3 = gpmc_read_reg(reg + 8);
1095 val4 = gpmc_read_reg(reg + 12);
1096
1097 /*
1098 * Add constant polynomial to remainder, in order to get an ecc
1099 * sequence of 0xFFs for a buffer filled with 0xFFs.
1100 */
1101 *ecc++ = 0xef ^ (val4 & 0xFF);
1102 *ecc++ = 0x51 ^ ((val3 >> 24) & 0xFF);
1103 *ecc++ = 0x2e ^ ((val3 >> 16) & 0xFF);
1104 *ecc++ = 0x09 ^ ((val3 >> 8) & 0xFF);
1105 *ecc++ = 0xed ^ (val3 & 0xFF);
1106 *ecc++ = 0x93 ^ ((val2 >> 24) & 0xFF);
1107 *ecc++ = 0x9a ^ ((val2 >> 16) & 0xFF);
1108 *ecc++ = 0xc2 ^ ((val2 >> 8) & 0xFF);
1109 *ecc++ = 0x97 ^ (val2 & 0xFF);
1110 *ecc++ = 0x79 ^ ((val1 >> 24) & 0xFF);
1111 *ecc++ = 0xe5 ^ ((val1 >> 16) & 0xFF);
1112 *ecc++ = 0x24 ^ ((val1 >> 8) & 0xFF);
1113 *ecc++ = 0xb5 ^ (val1 & 0xFF);
1114 }
1115
1116 gpmc_ecc_used = -EINVAL;
1117 return 0;
1118}
1119EXPORT_SYMBOL_GPL(gpmc_calculate_ecc_bch8);
1120
1121#endif /* CONFIG_ARCH_OMAP3 */
diff --git a/arch/arm/mach-orion5x/ts78xx-setup.c b/arch/arm/mach-orion5x/ts78xx-setup.c
index a74f3cf54cc5..b4203277f3cd 100644
--- a/arch/arm/mach-orion5x/ts78xx-setup.c
+++ b/arch/arm/mach-orion5x/ts78xx-setup.c
@@ -251,8 +251,6 @@ static void ts78xx_ts_nand_read_buf(struct mtd_info *mtd,
251 readsb(io_base, buf, len); 251 readsb(io_base, buf, len);
252} 252}
253 253
254const char *ts_nand_part_probes[] = { "cmdlinepart", NULL };
255
256static struct mtd_partition ts78xx_ts_nand_parts[] = { 254static struct mtd_partition ts78xx_ts_nand_parts[] = {
257 { 255 {
258 .name = "mbr", 256 .name = "mbr",
@@ -277,7 +275,6 @@ static struct mtd_partition ts78xx_ts_nand_parts[] = {
277static struct platform_nand_data ts78xx_ts_nand_data = { 275static struct platform_nand_data ts78xx_ts_nand_data = {
278 .chip = { 276 .chip = {
279 .nr_chips = 1, 277 .nr_chips = 1,
280 .part_probe_types = ts_nand_part_probes,
281 .partitions = ts78xx_ts_nand_parts, 278 .partitions = ts78xx_ts_nand_parts,
282 .nr_partitions = ARRAY_SIZE(ts78xx_ts_nand_parts), 279 .nr_partitions = ARRAY_SIZE(ts78xx_ts_nand_parts),
283 .chip_delay = 15, 280 .chip_delay = 15,
diff --git a/arch/arm/mach-pxa/balloon3.c b/arch/arm/mach-pxa/balloon3.c
index 56e8cebeb7d5..9244493dbcb7 100644
--- a/arch/arm/mach-pxa/balloon3.c
+++ b/arch/arm/mach-pxa/balloon3.c
@@ -679,8 +679,6 @@ static struct mtd_partition balloon3_partition_info[] = {
679 }, 679 },
680}; 680};
681 681
682static const char *balloon3_part_probes[] = { "cmdlinepart", NULL };
683
684struct platform_nand_data balloon3_nand_pdata = { 682struct platform_nand_data balloon3_nand_pdata = {
685 .chip = { 683 .chip = {
686 .nr_chips = 4, 684 .nr_chips = 4,
@@ -688,7 +686,6 @@ struct platform_nand_data balloon3_nand_pdata = {
688 .nr_partitions = ARRAY_SIZE(balloon3_partition_info), 686 .nr_partitions = ARRAY_SIZE(balloon3_partition_info),
689 .partitions = balloon3_partition_info, 687 .partitions = balloon3_partition_info,
690 .chip_delay = 50, 688 .chip_delay = 50,
691 .part_probe_types = balloon3_part_probes,
692 }, 689 },
693 .ctrl = { 690 .ctrl = {
694 .hwcontrol = 0, 691 .hwcontrol = 0,
diff --git a/arch/arm/mach-pxa/em-x270.c b/arch/arm/mach-pxa/em-x270.c
index a3a4a38d4972..97f82ad341bf 100644
--- a/arch/arm/mach-pxa/em-x270.c
+++ b/arch/arm/mach-pxa/em-x270.c
@@ -338,8 +338,6 @@ static struct mtd_partition em_x270_partition_info[] = {
338 }, 338 },
339}; 339};
340 340
341static const char *em_x270_part_probes[] = { "cmdlinepart", NULL };
342
343struct platform_nand_data em_x270_nand_platdata = { 341struct platform_nand_data em_x270_nand_platdata = {
344 .chip = { 342 .chip = {
345 .nr_chips = 1, 343 .nr_chips = 1,
@@ -347,7 +345,6 @@ struct platform_nand_data em_x270_nand_platdata = {
347 .nr_partitions = ARRAY_SIZE(em_x270_partition_info), 345 .nr_partitions = ARRAY_SIZE(em_x270_partition_info),
348 .partitions = em_x270_partition_info, 346 .partitions = em_x270_partition_info,
349 .chip_delay = 20, 347 .chip_delay = 20,
350 .part_probe_types = em_x270_part_probes,
351 }, 348 },
352 .ctrl = { 349 .ctrl = {
353 .hwcontrol = 0, 350 .hwcontrol = 0,
diff --git a/arch/arm/mach-pxa/palmtx.c b/arch/arm/mach-pxa/palmtx.c
index 9507605ed547..0da35dccfd89 100644
--- a/arch/arm/mach-pxa/palmtx.c
+++ b/arch/arm/mach-pxa/palmtx.c
@@ -268,8 +268,6 @@ static struct mtd_partition palmtx_partition_info[] = {
268 }, 268 },
269}; 269};
270 270
271static const char *palmtx_part_probes[] = { "cmdlinepart", NULL };
272
273struct platform_nand_data palmtx_nand_platdata = { 271struct platform_nand_data palmtx_nand_platdata = {
274 .chip = { 272 .chip = {
275 .nr_chips = 1, 273 .nr_chips = 1,
@@ -277,7 +275,6 @@ struct platform_nand_data palmtx_nand_platdata = {
277 .nr_partitions = ARRAY_SIZE(palmtx_partition_info), 275 .nr_partitions = ARRAY_SIZE(palmtx_partition_info),
278 .partitions = palmtx_partition_info, 276 .partitions = palmtx_partition_info,
279 .chip_delay = 20, 277 .chip_delay = 20,
280 .part_probe_types = palmtx_part_probes,
281 }, 278 },
282 .ctrl = { 279 .ctrl = {
283 .cmd_ctrl = palmtx_nand_cmd_ctl, 280 .cmd_ctrl = palmtx_nand_cmd_ctl,
diff --git a/arch/arm/mach-s3c24xx/mach-smdk2416.c b/arch/arm/mach-s3c24xx/mach-smdk2416.c
index 30a44f806e01..c3100a044fbe 100644
--- a/arch/arm/mach-s3c24xx/mach-smdk2416.c
+++ b/arch/arm/mach-s3c24xx/mach-smdk2416.c
@@ -148,23 +148,25 @@ static struct s3c24xx_hsudc_platdata smdk2416_hsudc_platdata = {
148 148
149static struct s3c_fb_pd_win smdk2416_fb_win[] = { 149static struct s3c_fb_pd_win smdk2416_fb_win[] = {
150 [0] = { 150 [0] = {
151 /* think this is the same as the smdk6410 */
152 .win_mode = {
153 .pixclock = 41094,
154 .left_margin = 8,
155 .right_margin = 13,
156 .upper_margin = 7,
157 .lower_margin = 5,
158 .hsync_len = 3,
159 .vsync_len = 1,
160 .xres = 800,
161 .yres = 480,
162 },
163 .default_bpp = 16, 151 .default_bpp = 16,
164 .max_bpp = 32, 152 .max_bpp = 32,
153 .xres = 800,
154 .yres = 480,
165 }, 155 },
166}; 156};
167 157
158static struct fb_videomode smdk2416_lcd_timing = {
159 .pixclock = 41094,
160 .left_margin = 8,
161 .right_margin = 13,
162 .upper_margin = 7,
163 .lower_margin = 5,
164 .hsync_len = 3,
165 .vsync_len = 1,
166 .xres = 800,
167 .yres = 480,
168};
169
168static void s3c2416_fb_gpio_setup_24bpp(void) 170static void s3c2416_fb_gpio_setup_24bpp(void)
169{ 171{
170 unsigned int gpio; 172 unsigned int gpio;
@@ -187,6 +189,7 @@ static void s3c2416_fb_gpio_setup_24bpp(void)
187 189
188static struct s3c_fb_platdata smdk2416_fb_platdata = { 190static struct s3c_fb_platdata smdk2416_fb_platdata = {
189 .win[0] = &smdk2416_fb_win[0], 191 .win[0] = &smdk2416_fb_win[0],
192 .vtiming = &smdk2416_lcd_timing,
190 .setup_gpio = s3c2416_fb_gpio_setup_24bpp, 193 .setup_gpio = s3c2416_fb_gpio_setup_24bpp,
191 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 194 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
192 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, 195 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
diff --git a/arch/arm/mach-s3c64xx/mach-anw6410.c b/arch/arm/mach-s3c64xx/mach-anw6410.c
index 314df0518afd..ffa29ddfdfce 100644
--- a/arch/arm/mach-s3c64xx/mach-anw6410.c
+++ b/arch/arm/mach-s3c64xx/mach-anw6410.c
@@ -134,24 +134,27 @@ static struct platform_device anw6410_lcd_powerdev = {
134}; 134};
135 135
136static struct s3c_fb_pd_win anw6410_fb_win0 = { 136static struct s3c_fb_pd_win anw6410_fb_win0 = {
137 /* this is to ensure we use win0 */
138 .win_mode = {
139 .left_margin = 8,
140 .right_margin = 13,
141 .upper_margin = 7,
142 .lower_margin = 5,
143 .hsync_len = 3,
144 .vsync_len = 1,
145 .xres = 800,
146 .yres = 480,
147 },
148 .max_bpp = 32, 137 .max_bpp = 32,
149 .default_bpp = 16, 138 .default_bpp = 16,
139 .xres = 800,
140 .yres = 480,
141};
142
143static struct fb_videomode anw6410_lcd_timing = {
144 .left_margin = 8,
145 .right_margin = 13,
146 .upper_margin = 7,
147 .lower_margin = 5,
148 .hsync_len = 3,
149 .vsync_len = 1,
150 .xres = 800,
151 .yres = 480,
150}; 152};
151 153
152/* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */ 154/* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */
153static struct s3c_fb_platdata anw6410_lcd_pdata __initdata = { 155static struct s3c_fb_platdata anw6410_lcd_pdata __initdata = {
154 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp, 156 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
157 .vtiming = &anw6410_lcd_timing,
155 .win[0] = &anw6410_fb_win0, 158 .win[0] = &anw6410_fb_win0,
156 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 159 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
157 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, 160 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
diff --git a/arch/arm/mach-s3c64xx/mach-crag6410.c b/arch/arm/mach-s3c64xx/mach-crag6410.c
index 6b20a71d7dbf..d0c352d861f8 100644
--- a/arch/arm/mach-s3c64xx/mach-crag6410.c
+++ b/arch/arm/mach-s3c64xx/mach-crag6410.c
@@ -151,26 +151,29 @@ static struct platform_device crag6410_lcd_powerdev = {
151 151
152/* 640x480 URT */ 152/* 640x480 URT */
153static struct s3c_fb_pd_win crag6410_fb_win0 = { 153static struct s3c_fb_pd_win crag6410_fb_win0 = {
154 /* this is to ensure we use win0 */
155 .win_mode = {
156 .left_margin = 150,
157 .right_margin = 80,
158 .upper_margin = 40,
159 .lower_margin = 5,
160 .hsync_len = 40,
161 .vsync_len = 5,
162 .xres = 640,
163 .yres = 480,
164 },
165 .max_bpp = 32, 154 .max_bpp = 32,
166 .default_bpp = 16, 155 .default_bpp = 16,
156 .xres = 640,
157 .yres = 480,
167 .virtual_y = 480 * 2, 158 .virtual_y = 480 * 2,
168 .virtual_x = 640, 159 .virtual_x = 640,
169}; 160};
170 161
162static struct fb_videomode crag6410_lcd_timing = {
163 .left_margin = 150,
164 .right_margin = 80,
165 .upper_margin = 40,
166 .lower_margin = 5,
167 .hsync_len = 40,
168 .vsync_len = 5,
169 .xres = 640,
170 .yres = 480,
171};
172
171/* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */ 173/* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */
172static struct s3c_fb_platdata crag6410_lcd_pdata __initdata = { 174static struct s3c_fb_platdata crag6410_lcd_pdata __initdata = {
173 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp, 175 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
176 .vtiming = &crag6410_lcd_timing,
174 .win[0] = &crag6410_fb_win0, 177 .win[0] = &crag6410_fb_win0,
175 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 178 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
176 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, 179 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
diff --git a/arch/arm/mach-s3c64xx/mach-hmt.c b/arch/arm/mach-s3c64xx/mach-hmt.c
index 1bf6b9da20fc..689088162f77 100644
--- a/arch/arm/mach-s3c64xx/mach-hmt.c
+++ b/arch/arm/mach-s3c64xx/mach-hmt.c
@@ -129,23 +129,27 @@ static struct platform_device hmt_backlight_device = {
129}; 129};
130 130
131static struct s3c_fb_pd_win hmt_fb_win0 = { 131static struct s3c_fb_pd_win hmt_fb_win0 = {
132 .win_mode = {
133 .left_margin = 8,
134 .right_margin = 13,
135 .upper_margin = 7,
136 .lower_margin = 5,
137 .hsync_len = 3,
138 .vsync_len = 1,
139 .xres = 800,
140 .yres = 480,
141 },
142 .max_bpp = 32, 132 .max_bpp = 32,
143 .default_bpp = 16, 133 .default_bpp = 16,
134 .xres = 800,
135 .yres = 480,
136};
137
138static struct fb_videomode hmt_lcd_timing = {
139 .left_margin = 8,
140 .right_margin = 13,
141 .upper_margin = 7,
142 .lower_margin = 5,
143 .hsync_len = 3,
144 .vsync_len = 1,
145 .xres = 800,
146 .yres = 480,
144}; 147};
145 148
146/* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */ 149/* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */
147static struct s3c_fb_platdata hmt_lcd_pdata __initdata = { 150static struct s3c_fb_platdata hmt_lcd_pdata __initdata = {
148 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp, 151 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
152 .vtiming = &hmt_lcd_timing,
149 .win[0] = &hmt_fb_win0, 153 .win[0] = &hmt_fb_win0,
150 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 154 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
151 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, 155 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
diff --git a/arch/arm/mach-s3c64xx/mach-mini6410.c b/arch/arm/mach-s3c64xx/mach-mini6410.c
index f8ea61ea3b33..5539a255a704 100644
--- a/arch/arm/mach-s3c64xx/mach-mini6410.c
+++ b/arch/arm/mach-s3c64xx/mach-mini6410.c
@@ -140,41 +140,59 @@ static struct s3c2410_platform_nand mini6410_nand_info = {
140 .sets = mini6410_nand_sets, 140 .sets = mini6410_nand_sets,
141}; 141};
142 142
143static struct s3c_fb_pd_win mini6410_fb_win[] = { 143static struct s3c_fb_pd_win mini6410_lcd_type0_fb_win = {
144 .max_bpp = 32,
145 .default_bpp = 16,
146 .xres = 480,
147 .yres = 272,
148};
149
150static struct fb_videomode mini6410_lcd_type0_timing = {
151 /* 4.3" 480x272 */
152 .left_margin = 3,
153 .right_margin = 2,
154 .upper_margin = 1,
155 .lower_margin = 1,
156 .hsync_len = 40,
157 .vsync_len = 1,
158 .xres = 480,
159 .yres = 272,
160};
161
162static struct s3c_fb_pd_win mini6410_lcd_type1_fb_win = {
163 .max_bpp = 32,
164 .default_bpp = 16,
165 .xres = 800,
166 .yres = 480,
167};
168
169static struct fb_videomode mini6410_lcd_type1_timing = {
170 /* 7.0" 800x480 */
171 .left_margin = 8,
172 .right_margin = 13,
173 .upper_margin = 7,
174 .lower_margin = 5,
175 .hsync_len = 3,
176 .vsync_len = 1,
177 .xres = 800,
178 .yres = 480,
179};
180
181static struct s3c_fb_platdata mini6410_lcd_pdata[] __initdata = {
144 { 182 {
145 .win_mode = { /* 4.3" 480x272 */ 183 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
146 .left_margin = 3, 184 .vtiming = &mini6410_lcd_type0_timing,
147 .right_margin = 2, 185 .win[0] = &mini6410_lcd_type0_fb_win,
148 .upper_margin = 1, 186 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
149 .lower_margin = 1, 187 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
150 .hsync_len = 40,
151 .vsync_len = 1,
152 .xres = 480,
153 .yres = 272,
154 },
155 .max_bpp = 32,
156 .default_bpp = 16,
157 }, { 188 }, {
158 .win_mode = { /* 7.0" 800x480 */ 189 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
159 .left_margin = 8, 190 .vtiming = &mini6410_lcd_type1_timing,
160 .right_margin = 13, 191 .win[0] = &mini6410_lcd_type1_fb_win,
161 .upper_margin = 7, 192 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
162 .lower_margin = 5, 193 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
163 .hsync_len = 3,
164 .vsync_len = 1,
165 .xres = 800,
166 .yres = 480,
167 },
168 .max_bpp = 32,
169 .default_bpp = 16,
170 }, 194 },
171}; 195 { },
172
173static struct s3c_fb_platdata mini6410_lcd_pdata __initdata = {
174 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
175 .win[0] = &mini6410_fb_win[0],
176 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
177 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
178}; 196};
179 197
180static void mini6410_lcd_power_set(struct plat_lcd_data *pd, 198static void mini6410_lcd_power_set(struct plat_lcd_data *pd,
@@ -272,7 +290,7 @@ static void mini6410_parse_features(
272 "screen type already set\n", f); 290 "screen type already set\n", f);
273 } else { 291 } else {
274 int li = f - '0'; 292 int li = f - '0';
275 if (li >= ARRAY_SIZE(mini6410_fb_win)) 293 if (li >= ARRAY_SIZE(mini6410_lcd_pdata))
276 printk(KERN_INFO "MINI6410: '%c' out " 294 printk(KERN_INFO "MINI6410: '%c' out "
277 "of range LCD mode\n", f); 295 "of range LCD mode\n", f);
278 else { 296 else {
@@ -296,14 +314,12 @@ static void __init mini6410_machine_init(void)
296 /* Parse the feature string */ 314 /* Parse the feature string */
297 mini6410_parse_features(&features, mini6410_features_str); 315 mini6410_parse_features(&features, mini6410_features_str);
298 316
299 mini6410_lcd_pdata.win[0] = &mini6410_fb_win[features.lcd_index];
300
301 printk(KERN_INFO "MINI6410: selected LCD display is %dx%d\n", 317 printk(KERN_INFO "MINI6410: selected LCD display is %dx%d\n",
302 mini6410_lcd_pdata.win[0]->win_mode.xres, 318 mini6410_lcd_pdata[features.lcd_index].win[0]->xres,
303 mini6410_lcd_pdata.win[0]->win_mode.yres); 319 mini6410_lcd_pdata[features.lcd_index].win[0]->yres);
304 320
305 s3c_nand_set_platdata(&mini6410_nand_info); 321 s3c_nand_set_platdata(&mini6410_nand_info);
306 s3c_fb_set_platdata(&mini6410_lcd_pdata); 322 s3c_fb_set_platdata(&mini6410_lcd_pdata[features.lcd_index]);
307 s3c24xx_ts_set_platdata(NULL); 323 s3c24xx_ts_set_platdata(NULL);
308 324
309 /* configure nCS1 width to 16 bits */ 325 /* configure nCS1 width to 16 bits */
diff --git a/arch/arm/mach-s3c64xx/mach-real6410.c b/arch/arm/mach-s3c64xx/mach-real6410.c
index b92d8e17d502..326b21604bc3 100644
--- a/arch/arm/mach-s3c64xx/mach-real6410.c
+++ b/arch/arm/mach-s3c64xx/mach-real6410.c
@@ -106,41 +106,57 @@ static struct platform_device real6410_device_eth = {
106 }, 106 },
107}; 107};
108 108
109static struct s3c_fb_pd_win real6410_fb_win[] = { 109static struct s3c_fb_pd_win real6410_lcd_type0_fb_win = {
110 .max_bpp = 32,
111 .default_bpp = 16,
112 .xres = 480,
113 .yres = 272,
114};
115
116static struct fb_videomode real6410_lcd_type0_timing = {
117 /* 4.3" 480x272 */
118 .left_margin = 3,
119 .right_margin = 2,
120 .upper_margin = 1,
121 .lower_margin = 1,
122 .hsync_len = 40,
123 .vsync_len = 1,
124};
125
126static struct s3c_fb_pd_win real6410_lcd_type1_fb_win = {
127 .max_bpp = 32,
128 .default_bpp = 16,
129 .xres = 800,
130 .yres = 480,
131};
132
133static struct fb_videomode real6410_lcd_type1_timing = {
134 /* 7.0" 800x480 */
135 .left_margin = 8,
136 .right_margin = 13,
137 .upper_margin = 7,
138 .lower_margin = 5,
139 .hsync_len = 3,
140 .vsync_len = 1,
141 .xres = 800,
142 .yres = 480,
143};
144
145static struct s3c_fb_platdata real6410_lcd_pdata[] __initdata = {
110 { 146 {
111 .win_mode = { /* 4.3" 480x272 */ 147 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
112 .left_margin = 3, 148 .vtiming = &real6410_lcd_type0_timing,
113 .right_margin = 2, 149 .win[0] = &real6410_lcd_type0_fb_win,
114 .upper_margin = 1, 150 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
115 .lower_margin = 1, 151 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
116 .hsync_len = 40,
117 .vsync_len = 1,
118 .xres = 480,
119 .yres = 272,
120 },
121 .max_bpp = 32,
122 .default_bpp = 16,
123 }, { 152 }, {
124 .win_mode = { /* 7.0" 800x480 */ 153 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
125 .left_margin = 8, 154 .vtiming = &real6410_lcd_type1_timing,
126 .right_margin = 13, 155 .win[0] = &real6410_lcd_type1_fb_win,
127 .upper_margin = 7, 156 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
128 .lower_margin = 5, 157 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
129 .hsync_len = 3,
130 .vsync_len = 1,
131 .xres = 800,
132 .yres = 480,
133 },
134 .max_bpp = 32,
135 .default_bpp = 16,
136 }, 158 },
137}; 159 { },
138
139static struct s3c_fb_platdata real6410_lcd_pdata __initdata = {
140 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
141 .win[0] = &real6410_fb_win[0],
142 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
143 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
144}; 160};
145 161
146static struct mtd_partition real6410_nand_part[] = { 162static struct mtd_partition real6410_nand_part[] = {
@@ -253,7 +269,7 @@ static void real6410_parse_features(
253 "screen type already set\n", f); 269 "screen type already set\n", f);
254 } else { 270 } else {
255 int li = f - '0'; 271 int li = f - '0';
256 if (li >= ARRAY_SIZE(real6410_fb_win)) 272 if (li >= ARRAY_SIZE(real6410_lcd_pdata))
257 printk(KERN_INFO "REAL6410: '%c' out " 273 printk(KERN_INFO "REAL6410: '%c' out "
258 "of range LCD mode\n", f); 274 "of range LCD mode\n", f);
259 else { 275 else {
@@ -277,13 +293,11 @@ static void __init real6410_machine_init(void)
277 /* Parse the feature string */ 293 /* Parse the feature string */
278 real6410_parse_features(&features, real6410_features_str); 294 real6410_parse_features(&features, real6410_features_str);
279 295
280 real6410_lcd_pdata.win[0] = &real6410_fb_win[features.lcd_index];
281
282 printk(KERN_INFO "REAL6410: selected LCD display is %dx%d\n", 296 printk(KERN_INFO "REAL6410: selected LCD display is %dx%d\n",
283 real6410_lcd_pdata.win[0]->win_mode.xres, 297 real6410_lcd_pdata[features.lcd_index].win[0]->xres,
284 real6410_lcd_pdata.win[0]->win_mode.yres); 298 real6410_lcd_pdata[features.lcd_index].win[0]->yres);
285 299
286 s3c_fb_set_platdata(&real6410_lcd_pdata); 300 s3c_fb_set_platdata(&real6410_lcd_pdata[features.lcd_index]);
287 s3c_nand_set_platdata(&real6410_nand_info); 301 s3c_nand_set_platdata(&real6410_nand_info);
288 s3c24xx_ts_set_platdata(NULL); 302 s3c24xx_ts_set_platdata(NULL);
289 303
diff --git a/arch/arm/mach-s3c64xx/mach-smartq5.c b/arch/arm/mach-s3c64xx/mach-smartq5.c
index c5021d0335c6..d6266d8b43c9 100644
--- a/arch/arm/mach-s3c64xx/mach-smartq5.c
+++ b/arch/arm/mach-s3c64xx/mach-smartq5.c
@@ -108,23 +108,27 @@ static struct platform_device smartq5_buttons_device = {
108}; 108};
109 109
110static struct s3c_fb_pd_win smartq5_fb_win0 = { 110static struct s3c_fb_pd_win smartq5_fb_win0 = {
111 .win_mode = {
112 .left_margin = 216,
113 .right_margin = 40,
114 .upper_margin = 35,
115 .lower_margin = 10,
116 .hsync_len = 1,
117 .vsync_len = 1,
118 .xres = 800,
119 .yres = 480,
120 .refresh = 80,
121 },
122 .max_bpp = 32, 111 .max_bpp = 32,
123 .default_bpp = 16, 112 .default_bpp = 16,
113 .xres = 800,
114 .yres = 480,
115};
116
117static struct fb_videomode smartq5_lcd_timing = {
118 .left_margin = 216,
119 .right_margin = 40,
120 .upper_margin = 35,
121 .lower_margin = 10,
122 .hsync_len = 1,
123 .vsync_len = 1,
124 .xres = 800,
125 .yres = 480,
126 .refresh = 80,
124}; 127};
125 128
126static struct s3c_fb_platdata smartq5_lcd_pdata __initdata = { 129static struct s3c_fb_platdata smartq5_lcd_pdata __initdata = {
127 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp, 130 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
131 .vtiming = &smartq5_lcd_timing,
128 .win[0] = &smartq5_fb_win0, 132 .win[0] = &smartq5_fb_win0,
129 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 133 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
130 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC | 134 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC |
diff --git a/arch/arm/mach-s3c64xx/mach-smartq7.c b/arch/arm/mach-s3c64xx/mach-smartq7.c
index aa9072a4cbef..0957d2a980e1 100644
--- a/arch/arm/mach-s3c64xx/mach-smartq7.c
+++ b/arch/arm/mach-s3c64xx/mach-smartq7.c
@@ -124,23 +124,27 @@ static struct platform_device smartq7_buttons_device = {
124}; 124};
125 125
126static struct s3c_fb_pd_win smartq7_fb_win0 = { 126static struct s3c_fb_pd_win smartq7_fb_win0 = {
127 .win_mode = {
128 .left_margin = 3,
129 .right_margin = 5,
130 .upper_margin = 1,
131 .lower_margin = 20,
132 .hsync_len = 10,
133 .vsync_len = 3,
134 .xres = 800,
135 .yres = 480,
136 .refresh = 80,
137 },
138 .max_bpp = 32, 127 .max_bpp = 32,
139 .default_bpp = 16, 128 .default_bpp = 16,
129 .xres = 800,
130 .yres = 480,
131};
132
133static struct fb_videomode smartq7_lcd_timing = {
134 .left_margin = 3,
135 .right_margin = 5,
136 .upper_margin = 1,
137 .lower_margin = 20,
138 .hsync_len = 10,
139 .vsync_len = 3,
140 .xres = 800,
141 .yres = 480,
142 .refresh = 80,
140}; 143};
141 144
142static struct s3c_fb_platdata smartq7_lcd_pdata __initdata = { 145static struct s3c_fb_platdata smartq7_lcd_pdata __initdata = {
143 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp, 146 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
147 .vtiming = &smartq7_lcd_timing,
144 .win[0] = &smartq7_fb_win0, 148 .win[0] = &smartq7_fb_win0,
145 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 149 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
146 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC | 150 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC |
diff --git a/arch/arm/mach-s3c64xx/mach-smdk6410.c b/arch/arm/mach-s3c64xx/mach-smdk6410.c
index d44319b09412..df3103d450e2 100644
--- a/arch/arm/mach-s3c64xx/mach-smdk6410.c
+++ b/arch/arm/mach-s3c64xx/mach-smdk6410.c
@@ -146,26 +146,29 @@ static struct platform_device smdk6410_lcd_powerdev = {
146}; 146};
147 147
148static struct s3c_fb_pd_win smdk6410_fb_win0 = { 148static struct s3c_fb_pd_win smdk6410_fb_win0 = {
149 /* this is to ensure we use win0 */
150 .win_mode = {
151 .left_margin = 8,
152 .right_margin = 13,
153 .upper_margin = 7,
154 .lower_margin = 5,
155 .hsync_len = 3,
156 .vsync_len = 1,
157 .xres = 800,
158 .yres = 480,
159 },
160 .max_bpp = 32, 149 .max_bpp = 32,
161 .default_bpp = 16, 150 .default_bpp = 16,
151 .xres = 800,
152 .yres = 480,
162 .virtual_y = 480 * 2, 153 .virtual_y = 480 * 2,
163 .virtual_x = 800, 154 .virtual_x = 800,
164}; 155};
165 156
157static struct fb_videomode smdk6410_lcd_timing = {
158 .left_margin = 8,
159 .right_margin = 13,
160 .upper_margin = 7,
161 .lower_margin = 5,
162 .hsync_len = 3,
163 .vsync_len = 1,
164 .xres = 800,
165 .yres = 480,
166};
167
166/* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */ 168/* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */
167static struct s3c_fb_platdata smdk6410_lcd_pdata __initdata = { 169static struct s3c_fb_platdata smdk6410_lcd_pdata __initdata = {
168 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp, 170 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
171 .vtiming = &smdk6410_lcd_timing,
169 .win[0] = &smdk6410_fb_win0, 172 .win[0] = &smdk6410_fb_win0,
170 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 173 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
171 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, 174 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
diff --git a/arch/arm/mach-s5p64x0/mach-smdk6440.c b/arch/arm/mach-s5p64x0/mach-smdk6440.c
index a40e325d62c8..92fefad505cc 100644
--- a/arch/arm/mach-s5p64x0/mach-smdk6440.c
+++ b/arch/arm/mach-s5p64x0/mach-smdk6440.c
@@ -103,22 +103,26 @@ static struct s3c2410_uartcfg smdk6440_uartcfgs[] __initdata = {
103 103
104/* Frame Buffer */ 104/* Frame Buffer */
105static struct s3c_fb_pd_win smdk6440_fb_win0 = { 105static struct s3c_fb_pd_win smdk6440_fb_win0 = {
106 .win_mode = {
107 .left_margin = 8,
108 .right_margin = 13,
109 .upper_margin = 7,
110 .lower_margin = 5,
111 .hsync_len = 3,
112 .vsync_len = 1,
113 .xres = 800,
114 .yres = 480,
115 },
116 .max_bpp = 32, 106 .max_bpp = 32,
117 .default_bpp = 24, 107 .default_bpp = 24,
108 .xres = 800,
109 .yres = 480,
110};
111
112static struct fb_videomode smdk6440_lcd_timing = {
113 .left_margin = 8,
114 .right_margin = 13,
115 .upper_margin = 7,
116 .lower_margin = 5,
117 .hsync_len = 3,
118 .vsync_len = 1,
119 .xres = 800,
120 .yres = 480,
118}; 121};
119 122
120static struct s3c_fb_platdata smdk6440_lcd_pdata __initdata = { 123static struct s3c_fb_platdata smdk6440_lcd_pdata __initdata = {
121 .win[0] = &smdk6440_fb_win0, 124 .win[0] = &smdk6440_fb_win0,
125 .vtiming = &smdk6440_lcd_timing,
122 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 126 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
123 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, 127 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
124 .setup_gpio = s5p64x0_fb_gpio_setup_24bpp, 128 .setup_gpio = s5p64x0_fb_gpio_setup_24bpp,
diff --git a/arch/arm/mach-s5p64x0/mach-smdk6450.c b/arch/arm/mach-s5p64x0/mach-smdk6450.c
index efb69e2f2afe..e2335ecf6eae 100644
--- a/arch/arm/mach-s5p64x0/mach-smdk6450.c
+++ b/arch/arm/mach-s5p64x0/mach-smdk6450.c
@@ -121,22 +121,26 @@ static struct s3c2410_uartcfg smdk6450_uartcfgs[] __initdata = {
121 121
122/* Frame Buffer */ 122/* Frame Buffer */
123static struct s3c_fb_pd_win smdk6450_fb_win0 = { 123static struct s3c_fb_pd_win smdk6450_fb_win0 = {
124 .win_mode = {
125 .left_margin = 8,
126 .right_margin = 13,
127 .upper_margin = 7,
128 .lower_margin = 5,
129 .hsync_len = 3,
130 .vsync_len = 1,
131 .xres = 800,
132 .yres = 480,
133 },
134 .max_bpp = 32, 124 .max_bpp = 32,
135 .default_bpp = 24, 125 .default_bpp = 24,
126 .xres = 800,
127 .yres = 480,
128};
129
130static struct fb_videomode smdk6450_lcd_timing = {
131 .left_margin = 8,
132 .right_margin = 13,
133 .upper_margin = 7,
134 .lower_margin = 5,
135 .hsync_len = 3,
136 .vsync_len = 1,
137 .xres = 800,
138 .yres = 480,
136}; 139};
137 140
138static struct s3c_fb_platdata smdk6450_lcd_pdata __initdata = { 141static struct s3c_fb_platdata smdk6450_lcd_pdata __initdata = {
139 .win[0] = &smdk6450_fb_win0, 142 .win[0] = &smdk6450_fb_win0,
143 .vtiming = &smdk6450_lcd_timing,
140 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 144 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
141 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, 145 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
142 .setup_gpio = s5p64x0_fb_gpio_setup_24bpp, 146 .setup_gpio = s5p64x0_fb_gpio_setup_24bpp,
diff --git a/arch/arm/mach-s5pc100/mach-smdkc100.c b/arch/arm/mach-s5pc100/mach-smdkc100.c
index 674d22992f3c..0c3ae38d27ca 100644
--- a/arch/arm/mach-s5pc100/mach-smdkc100.c
+++ b/arch/arm/mach-s5pc100/mach-smdkc100.c
@@ -136,24 +136,27 @@ static struct platform_device smdkc100_lcd_powerdev = {
136 136
137/* Frame Buffer */ 137/* Frame Buffer */
138static struct s3c_fb_pd_win smdkc100_fb_win0 = { 138static struct s3c_fb_pd_win smdkc100_fb_win0 = {
139 /* this is to ensure we use win0 */
140 .win_mode = {
141 .left_margin = 8,
142 .right_margin = 13,
143 .upper_margin = 7,
144 .lower_margin = 5,
145 .hsync_len = 3,
146 .vsync_len = 1,
147 .xres = 800,
148 .yres = 480,
149 .refresh = 80,
150 },
151 .max_bpp = 32, 139 .max_bpp = 32,
152 .default_bpp = 16, 140 .default_bpp = 16,
141 .xres = 800,
142 .yres = 480,
143};
144
145static struct fb_videomode smdkc100_lcd_timing = {
146 .left_margin = 8,
147 .right_margin = 13,
148 .upper_margin = 7,
149 .lower_margin = 5,
150 .hsync_len = 3,
151 .vsync_len = 1,
152 .xres = 800,
153 .yres = 480,
154 .refresh = 80,
153}; 155};
154 156
155static struct s3c_fb_platdata smdkc100_lcd_pdata __initdata = { 157static struct s3c_fb_platdata smdkc100_lcd_pdata __initdata = {
156 .win[0] = &smdkc100_fb_win0, 158 .win[0] = &smdkc100_fb_win0,
159 .vtiming = &smdkc100_lcd_timing,
157 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 160 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
158 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, 161 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
159 .setup_gpio = s5pc100_fb_gpio_setup_24bpp, 162 .setup_gpio = s5pc100_fb_gpio_setup_24bpp,
diff --git a/arch/arm/mach-s5pv210/mach-aquila.c b/arch/arm/mach-s5pv210/mach-aquila.c
index 48d018f2332b..af528f9e97f9 100644
--- a/arch/arm/mach-s5pv210/mach-aquila.c
+++ b/arch/arm/mach-s5pv210/mach-aquila.c
@@ -96,38 +96,34 @@ static struct s3c2410_uartcfg aquila_uartcfgs[] __initdata = {
96 96
97/* Frame Buffer */ 97/* Frame Buffer */
98static struct s3c_fb_pd_win aquila_fb_win0 = { 98static struct s3c_fb_pd_win aquila_fb_win0 = {
99 .win_mode = {
100 .left_margin = 16,
101 .right_margin = 16,
102 .upper_margin = 3,
103 .lower_margin = 28,
104 .hsync_len = 2,
105 .vsync_len = 2,
106 .xres = 480,
107 .yres = 800,
108 },
109 .max_bpp = 32, 99 .max_bpp = 32,
110 .default_bpp = 16, 100 .default_bpp = 16,
101 .xres = 480,
102 .yres = 800,
111}; 103};
112 104
113static struct s3c_fb_pd_win aquila_fb_win1 = { 105static struct s3c_fb_pd_win aquila_fb_win1 = {
114 .win_mode = {
115 .left_margin = 16,
116 .right_margin = 16,
117 .upper_margin = 3,
118 .lower_margin = 28,
119 .hsync_len = 2,
120 .vsync_len = 2,
121 .xres = 480,
122 .yres = 800,
123 },
124 .max_bpp = 32, 106 .max_bpp = 32,
125 .default_bpp = 16, 107 .default_bpp = 16,
108 .xres = 480,
109 .yres = 800,
110};
111
112static struct fb_videomode aquila_lcd_timing = {
113 .left_margin = 16,
114 .right_margin = 16,
115 .upper_margin = 3,
116 .lower_margin = 28,
117 .hsync_len = 2,
118 .vsync_len = 2,
119 .xres = 480,
120 .yres = 800,
126}; 121};
127 122
128static struct s3c_fb_platdata aquila_lcd_pdata __initdata = { 123static struct s3c_fb_platdata aquila_lcd_pdata __initdata = {
129 .win[0] = &aquila_fb_win0, 124 .win[0] = &aquila_fb_win0,
130 .win[1] = &aquila_fb_win1, 125 .win[1] = &aquila_fb_win1,
126 .vtiming = &aquila_lcd_timing,
131 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 127 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
132 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC | 128 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC |
133 VIDCON1_INV_VCLK | VIDCON1_INV_VDEN, 129 VIDCON1_INV_VCLK | VIDCON1_INV_VDEN,
diff --git a/arch/arm/mach-s5pv210/mach-goni.c b/arch/arm/mach-s5pv210/mach-goni.c
index f20a97c8e411..bf5087c2b7fe 100644
--- a/arch/arm/mach-s5pv210/mach-goni.c
+++ b/arch/arm/mach-s5pv210/mach-goni.c
@@ -107,25 +107,29 @@ static struct s3c2410_uartcfg goni_uartcfgs[] __initdata = {
107 107
108/* Frame Buffer */ 108/* Frame Buffer */
109static struct s3c_fb_pd_win goni_fb_win0 = { 109static struct s3c_fb_pd_win goni_fb_win0 = {
110 .win_mode = {
111 .left_margin = 16,
112 .right_margin = 16,
113 .upper_margin = 2,
114 .lower_margin = 28,
115 .hsync_len = 2,
116 .vsync_len = 1,
117 .xres = 480,
118 .yres = 800,
119 .refresh = 55,
120 },
121 .max_bpp = 32, 110 .max_bpp = 32,
122 .default_bpp = 16, 111 .default_bpp = 16,
112 .xres = 480,
113 .yres = 800,
123 .virtual_x = 480, 114 .virtual_x = 480,
124 .virtual_y = 2 * 800, 115 .virtual_y = 2 * 800,
125}; 116};
126 117
118static struct fb_videomode goni_lcd_timing = {
119 .left_margin = 16,
120 .right_margin = 16,
121 .upper_margin = 2,
122 .lower_margin = 28,
123 .hsync_len = 2,
124 .vsync_len = 1,
125 .xres = 480,
126 .yres = 800,
127 .refresh = 55,
128};
129
127static struct s3c_fb_platdata goni_lcd_pdata __initdata = { 130static struct s3c_fb_platdata goni_lcd_pdata __initdata = {
128 .win[0] = &goni_fb_win0, 131 .win[0] = &goni_fb_win0,
132 .vtiming = &goni_lcd_timing,
129 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB | 133 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB |
130 VIDCON0_CLKSEL_LCD, 134 VIDCON0_CLKSEL_LCD,
131 .vidcon1 = VIDCON1_INV_VCLK | VIDCON1_INV_VDEN 135 .vidcon1 = VIDCON1_INV_VCLK | VIDCON1_INV_VDEN
diff --git a/arch/arm/mach-s5pv210/mach-smdkv210.c b/arch/arm/mach-s5pv210/mach-smdkv210.c
index fa1b61209fd9..0d7ddec88eb7 100644
--- a/arch/arm/mach-s5pv210/mach-smdkv210.c
+++ b/arch/arm/mach-s5pv210/mach-smdkv210.c
@@ -178,22 +178,26 @@ static struct platform_device smdkv210_lcd_lte480wv = {
178}; 178};
179 179
180static struct s3c_fb_pd_win smdkv210_fb_win0 = { 180static struct s3c_fb_pd_win smdkv210_fb_win0 = {
181 .win_mode = {
182 .left_margin = 13,
183 .right_margin = 8,
184 .upper_margin = 7,
185 .lower_margin = 5,
186 .hsync_len = 3,
187 .vsync_len = 1,
188 .xres = 800,
189 .yres = 480,
190 },
191 .max_bpp = 32, 181 .max_bpp = 32,
192 .default_bpp = 24, 182 .default_bpp = 24,
183 .xres = 800,
184 .yres = 480,
185};
186
187static struct fb_videomode smdkv210_lcd_timing = {
188 .left_margin = 13,
189 .right_margin = 8,
190 .upper_margin = 7,
191 .lower_margin = 5,
192 .hsync_len = 3,
193 .vsync_len = 1,
194 .xres = 800,
195 .yres = 480,
193}; 196};
194 197
195static struct s3c_fb_platdata smdkv210_lcd0_pdata __initdata = { 198static struct s3c_fb_platdata smdkv210_lcd0_pdata __initdata = {
196 .win[0] = &smdkv210_fb_win0, 199 .win[0] = &smdkv210_fb_win0,
200 .vtiming = &smdkv210_lcd_timing,
197 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, 201 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
198 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, 202 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
199 .setup_gpio = s5pv210_fb_gpio_setup_24bpp, 203 .setup_gpio = s5pv210_fb_gpio_setup_24bpp,
diff --git a/arch/arm/mach-ux500/board-mop500-uib.c b/arch/arm/mach-ux500/board-mop500-uib.c
index b29a788f498c..1f47d962e3a1 100644
--- a/arch/arm/mach-ux500/board-mop500-uib.c
+++ b/arch/arm/mach-ux500/board-mop500-uib.c
@@ -96,7 +96,7 @@ static void __init __mop500_uib_init(struct uib *uib, const char *why)
96/* 96/*
97 * Detect the UIB attached based on the presence or absence of i2c devices. 97 * Detect the UIB attached based on the presence or absence of i2c devices.
98 */ 98 */
99static int __init mop500_uib_init(void) 99int __init mop500_uib_init(void)
100{ 100{
101 struct uib *uib = mop500_uib; 101 struct uib *uib = mop500_uib;
102 struct i2c_adapter *i2c0; 102 struct i2c_adapter *i2c0;
@@ -131,5 +131,3 @@ static int __init mop500_uib_init(void)
131 131
132 return 0; 132 return 0;
133} 133}
134
135module_init(mop500_uib_init);
diff --git a/arch/arm/mach-ux500/board-mop500.c b/arch/arm/mach-ux500/board-mop500.c
index fba8adea421e..9c74ac545849 100644
--- a/arch/arm/mach-ux500/board-mop500.c
+++ b/arch/arm/mach-ux500/board-mop500.c
@@ -673,9 +673,15 @@ static void __init u8500_cryp1_hash1_init(struct device *parent)
673static struct platform_device *snowball_platform_devs[] __initdata = { 673static struct platform_device *snowball_platform_devs[] __initdata = {
674 &snowball_led_dev, 674 &snowball_led_dev,
675 &snowball_key_dev, 675 &snowball_key_dev,
676 &snowball_sbnet_dev,
676 &ab8500_device, 677 &ab8500_device,
677}; 678};
678 679
680static struct platform_device *snowball_of_platform_devs[] __initdata = {
681 &snowball_led_dev,
682 &snowball_key_dev,
683};
684
679static void __init mop500_init_machine(void) 685static void __init mop500_init_machine(void)
680{ 686{
681 struct device *parent = NULL; 687 struct device *parent = NULL;
@@ -710,6 +716,8 @@ static void __init mop500_init_machine(void)
710 716
711 /* This board has full regulator constraints */ 717 /* This board has full regulator constraints */
712 regulator_has_full_constraints(); 718 regulator_has_full_constraints();
719
720 mop500_uib_init();
713} 721}
714 722
715static void __init snowball_init_machine(void) 723static void __init snowball_init_machine(void)
@@ -774,6 +782,8 @@ static void __init hrefv60_init_machine(void)
774 782
775 /* This board has full regulator constraints */ 783 /* This board has full regulator constraints */
776 regulator_has_full_constraints(); 784 regulator_has_full_constraints();
785
786 mop500_uib_init();
777} 787}
778 788
779MACHINE_START(U8500, "ST-Ericsson MOP500 platform") 789MACHINE_START(U8500, "ST-Ericsson MOP500 platform")
@@ -834,6 +844,10 @@ struct of_dev_auxdata u8500_auxdata_lookup[] __initdata = {
834static const struct of_device_id u8500_local_bus_nodes[] = { 844static const struct of_device_id u8500_local_bus_nodes[] = {
835 /* only create devices below soc node */ 845 /* only create devices below soc node */
836 { .compatible = "stericsson,db8500", }, 846 { .compatible = "stericsson,db8500", },
847 { .compatible = "stericsson,db8500-prcmu", },
848 { .compatible = "stericsson,db8500-prcmu-regulator", },
849 { .compatible = "stericsson,ab8500", },
850 { .compatible = "stericsson,ab8500-regulator", },
837 { .compatible = "simple-bus"}, 851 { .compatible = "simple-bus"},
838 { }, 852 { },
839}; 853};
@@ -852,7 +866,7 @@ static void __init u8500_init_machine(void)
852 else if (of_machine_is_compatible("st-ericsson,hrefv60+")) 866 else if (of_machine_is_compatible("st-ericsson,hrefv60+"))
853 hrefv60_pinmaps_init(); 867 hrefv60_pinmaps_init();
854 868
855 parent = u8500_init_devices(); 869 parent = u8500_of_init_devices();
856 870
857 for (i = 0; i < ARRAY_SIZE(mop500_platform_devs); i++) 871 for (i = 0; i < ARRAY_SIZE(mop500_platform_devs); i++)
858 mop500_platform_devs[i]->dev.parent = parent; 872 mop500_platform_devs[i]->dev.parent = parent;
@@ -869,15 +883,23 @@ static void __init u8500_init_machine(void)
869 ARRAY_SIZE(mop500_platform_devs)); 883 ARRAY_SIZE(mop500_platform_devs));
870 884
871 mop500_sdi_init(parent); 885 mop500_sdi_init(parent);
872
873 i2c0_devs = ARRAY_SIZE(mop500_i2c0_devices); 886 i2c0_devs = ARRAY_SIZE(mop500_i2c0_devices);
874 i2c_register_board_info(0, mop500_i2c0_devices, i2c0_devs); 887 i2c_register_board_info(0, mop500_i2c0_devices, i2c0_devs);
875 i2c_register_board_info(2, mop500_i2c2_devices, 888 i2c_register_board_info(2, mop500_i2c2_devices,
876 ARRAY_SIZE(mop500_i2c2_devices)); 889 ARRAY_SIZE(mop500_i2c2_devices));
877 890
891 mop500_uib_init();
892
878 } else if (of_machine_is_compatible("calaosystems,snowball-a9500")) { 893 } else if (of_machine_is_compatible("calaosystems,snowball-a9500")) {
879 platform_add_devices(snowball_platform_devs, 894 /*
880 ARRAY_SIZE(snowball_platform_devs)); 895 * Devices to be DT:ed:
896 * snowball_led_dev = todo
897 * snowball_key_dev = todo
898 * snowball_sbnet_dev = done
899 * ab8500_device = done
900 */
901 platform_add_devices(snowball_of_platform_devs,
902 ARRAY_SIZE(snowball_of_platform_devs));
881 903
882 snowball_sdi_init(parent); 904 snowball_sdi_init(parent);
883 } else if (of_machine_is_compatible("st-ericsson,hrefv60+")) { 905 } else if (of_machine_is_compatible("st-ericsson,hrefv60+")) {
@@ -898,6 +920,8 @@ static void __init u8500_init_machine(void)
898 i2c_register_board_info(0, mop500_i2c0_devices, i2c0_devs); 920 i2c_register_board_info(0, mop500_i2c0_devices, i2c0_devs);
899 i2c_register_board_info(2, mop500_i2c2_devices, 921 i2c_register_board_info(2, mop500_i2c2_devices,
900 ARRAY_SIZE(mop500_i2c2_devices)); 922 ARRAY_SIZE(mop500_i2c2_devices));
923
924 mop500_uib_init();
901 } 925 }
902 mop500_i2c_init(parent); 926 mop500_i2c_init(parent);
903 927
diff --git a/arch/arm/mach-ux500/board-mop500.h b/arch/arm/mach-ux500/board-mop500.h
index bc44c07c71a9..2f87b25a908a 100644
--- a/arch/arm/mach-ux500/board-mop500.h
+++ b/arch/arm/mach-ux500/board-mop500.h
@@ -89,7 +89,11 @@ void __init mop500_pinmaps_init(void);
89void __init snowball_pinmaps_init(void); 89void __init snowball_pinmaps_init(void);
90void __init hrefv60_pinmaps_init(void); 90void __init hrefv60_pinmaps_init(void);
91 91
92int __init mop500_uib_init(void);
92void mop500_uib_i2c_add(int busnum, struct i2c_board_info *info, 93void mop500_uib_i2c_add(int busnum, struct i2c_board_info *info,
93 unsigned n); 94 unsigned n);
94 95
96/* TODO: Once all pieces are DT:ed, remove completely. */
97struct device * __init u8500_of_init_devices(void);
98
95#endif 99#endif
diff --git a/arch/arm/mach-ux500/cpu-db8500.c b/arch/arm/mach-ux500/cpu-db8500.c
index 16169c4bf6ca..33275eb4c689 100644
--- a/arch/arm/mach-ux500/cpu-db8500.c
+++ b/arch/arm/mach-ux500/cpu-db8500.c
@@ -140,7 +140,6 @@ static struct platform_device *platform_devs[] __initdata = {
140static struct platform_device *of_platform_devs[] __initdata = { 140static struct platform_device *of_platform_devs[] __initdata = {
141 &u8500_dma40_device, 141 &u8500_dma40_device,
142 &db8500_pmu_device, 142 &db8500_pmu_device,
143 &db8500_prcmu_device,
144}; 143};
145 144
146static resource_size_t __initdata db8500_gpio_base[] = { 145static resource_size_t __initdata db8500_gpio_base[] = {
@@ -222,6 +221,28 @@ struct device * __init u8500_init_devices(void)
222 platform_device_register_data(parent, 221 platform_device_register_data(parent,
223 "cpufreq-u8500", -1, NULL, 0); 222 "cpufreq-u8500", -1, NULL, 0);
224 223
224 for (i = 0; i < ARRAY_SIZE(platform_devs); i++)
225 platform_devs[i]->dev.parent = parent;
226
227 platform_add_devices(platform_devs, ARRAY_SIZE(platform_devs));
228
229 return parent;
230}
231
232/* TODO: Once all pieces are DT:ed, remove completely. */
233struct device * __init u8500_of_init_devices(void)
234{
235 struct device *parent;
236 int i;
237
238 parent = db8500_soc_device_init();
239
240 db8500_add_rtc(parent);
241 db8500_add_usb(parent, usb_db8500_rx_dma_cfg, usb_db8500_tx_dma_cfg);
242
243 platform_device_register_data(parent,
244 "cpufreq-u8500", -1, NULL, 0);
245
225 for (i = 0; i < ARRAY_SIZE(of_platform_devs); i++) 246 for (i = 0; i < ARRAY_SIZE(of_platform_devs); i++)
226 of_platform_devs[i]->dev.parent = parent; 247 of_platform_devs[i]->dev.parent = parent;
227 248
@@ -229,7 +250,7 @@ struct device * __init u8500_init_devices(void)
229 * Devices to be DT:ed: 250 * Devices to be DT:ed:
230 * u8500_dma40_device = todo 251 * u8500_dma40_device = todo
231 * db8500_pmu_device = todo 252 * db8500_pmu_device = todo
232 * db8500_prcmu_device = todo 253 * db8500_prcmu_device = done
233 */ 254 */
234 platform_add_devices(of_platform_devs, ARRAY_SIZE(of_platform_devs)); 255 platform_add_devices(of_platform_devs, ARRAY_SIZE(of_platform_devs));
235 256
diff --git a/arch/arm/plat-omap/include/plat/gpmc.h b/arch/arm/plat-omap/include/plat/gpmc.h
index 1527929b445a..f37764a36072 100644
--- a/arch/arm/plat-omap/include/plat/gpmc.h
+++ b/arch/arm/plat-omap/include/plat/gpmc.h
@@ -92,6 +92,8 @@ enum omap_ecc {
92 OMAP_ECC_HAMMING_CODE_HW, /* gpmc to detect the error */ 92 OMAP_ECC_HAMMING_CODE_HW, /* gpmc to detect the error */
93 /* 1-bit ecc: stored at beginning of spare area as romcode */ 93 /* 1-bit ecc: stored at beginning of spare area as romcode */
94 OMAP_ECC_HAMMING_CODE_HW_ROMCODE, /* gpmc method & romcode layout */ 94 OMAP_ECC_HAMMING_CODE_HW_ROMCODE, /* gpmc method & romcode layout */
95 OMAP_ECC_BCH4_CODE_HW, /* 4-bit BCH ecc code */
96 OMAP_ECC_BCH8_CODE_HW, /* 8-bit BCH ecc code */
95}; 97};
96 98
97/* 99/*
@@ -157,4 +159,13 @@ extern int gpmc_nand_write(int cs, int cmd, int wval);
157 159
158int gpmc_enable_hwecc(int cs, int mode, int dev_width, int ecc_size); 160int gpmc_enable_hwecc(int cs, int mode, int dev_width, int ecc_size);
159int gpmc_calculate_ecc(int cs, const u_char *dat, u_char *ecc_code); 161int gpmc_calculate_ecc(int cs, const u_char *dat, u_char *ecc_code);
162
163#ifdef CONFIG_ARCH_OMAP3
164int gpmc_init_hwecc_bch(int cs, int nsectors, int nerrors);
165int gpmc_enable_hwecc_bch(int cs, int mode, int dev_width, int nsectors,
166 int nerrors);
167int gpmc_calculate_ecc_bch4(int cs, const u_char *dat, u_char *ecc);
168int gpmc_calculate_ecc_bch8(int cs, const u_char *dat, u_char *ecc);
169#endif /* CONFIG_ARCH_OMAP3 */
170
160#endif 171#endif
diff --git a/arch/arm/plat-samsung/include/plat/fb.h b/arch/arm/plat-samsung/include/plat/fb.h
index 0fedf47fa502..536002ff2ab8 100644
--- a/arch/arm/plat-samsung/include/plat/fb.h
+++ b/arch/arm/plat-samsung/include/plat/fb.h
@@ -24,15 +24,16 @@
24 24
25/** 25/**
26 * struct s3c_fb_pd_win - per window setup data 26 * struct s3c_fb_pd_win - per window setup data
27 * @win_mode: The display parameters to initialise (not for window 0) 27 * @xres : The window X size.
28 * @yres : The window Y size.
28 * @virtual_x: The virtual X size. 29 * @virtual_x: The virtual X size.
29 * @virtual_y: The virtual Y size. 30 * @virtual_y: The virtual Y size.
30 */ 31 */
31struct s3c_fb_pd_win { 32struct s3c_fb_pd_win {
32 struct fb_videomode win_mode;
33
34 unsigned short default_bpp; 33 unsigned short default_bpp;
35 unsigned short max_bpp; 34 unsigned short max_bpp;
35 unsigned short xres;
36 unsigned short yres;
36 unsigned short virtual_x; 37 unsigned short virtual_x;
37 unsigned short virtual_y; 38 unsigned short virtual_y;
38}; 39};
@@ -45,6 +46,7 @@ struct s3c_fb_pd_win {
45 * @default_win: default window layer number to be used for UI layer. 46 * @default_win: default window layer number to be used for UI layer.
46 * @vidcon0: The base vidcon0 values to control the panel data format. 47 * @vidcon0: The base vidcon0 values to control the panel data format.
47 * @vidcon1: The base vidcon1 values to control the panel data output. 48 * @vidcon1: The base vidcon1 values to control the panel data output.
49 * @vtiming: Video timing when connected to a RGB type panel.
48 * @win: The setup data for each hardware window, or NULL for unused. 50 * @win: The setup data for each hardware window, or NULL for unused.
49 * @display_mode: The LCD output display mode. 51 * @display_mode: The LCD output display mode.
50 * 52 *
@@ -58,8 +60,7 @@ struct s3c_fb_platdata {
58 void (*setup_gpio)(void); 60 void (*setup_gpio)(void);
59 61
60 struct s3c_fb_pd_win *win[S3C_FB_MAX_WIN]; 62 struct s3c_fb_pd_win *win[S3C_FB_MAX_WIN];
61 63 struct fb_videomode *vtiming;
62 u32 default_win;
63 64
64 u32 vidcon0; 65 u32 vidcon0;
65 u32 vidcon1; 66 u32 vidcon1;
diff --git a/arch/avr32/include/asm/posix_types.h b/arch/avr32/include/asm/posix_types.h
index 74667bfc88cc..9ba9e749b3f3 100644
--- a/arch/avr32/include/asm/posix_types.h
+++ b/arch/avr32/include/asm/posix_types.h
@@ -17,9 +17,6 @@
17typedef unsigned short __kernel_mode_t; 17typedef unsigned short __kernel_mode_t;
18#define __kernel_mode_t __kernel_mode_t 18#define __kernel_mode_t __kernel_mode_t
19 19
20typedef unsigned short __kernel_nlink_t;
21#define __kernel_nlink_t __kernel_nlink_t
22
23typedef unsigned short __kernel_ipc_pid_t; 20typedef unsigned short __kernel_ipc_pid_t;
24#define __kernel_ipc_pid_t __kernel_ipc_pid_t 21#define __kernel_ipc_pid_t __kernel_ipc_pid_t
25 22
diff --git a/arch/avr32/kernel/entry-avr32b.S b/arch/avr32/kernel/entry-avr32b.S
index 169268c40ae2..df2884181313 100644
--- a/arch/avr32/kernel/entry-avr32b.S
+++ b/arch/avr32/kernel/entry-avr32b.S
@@ -281,7 +281,7 @@ syscall_exit_work:
281 ld.w r1, r0[TI_flags] 281 ld.w r1, r0[TI_flags]
282 rjmp 1b 282 rjmp 1b
283 283
2842: mov r2, _TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NOTIFY_RESUME 2842: mov r2, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
285 tst r1, r2 285 tst r1, r2
286 breq 3f 286 breq 3f
287 unmask_interrupts 287 unmask_interrupts
@@ -587,7 +587,7 @@ fault_exit_work:
587 ld.w r1, r0[TI_flags] 587 ld.w r1, r0[TI_flags]
588 rjmp fault_exit_work 588 rjmp fault_exit_work
589 589
5901: mov r2, _TIF_SIGPENDING | _TIF_RESTORE_SIGMASK 5901: mov r2, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
591 tst r1, r2 591 tst r1, r2
592 breq 2f 592 breq 2f
593 unmask_interrupts 593 unmask_interrupts
diff --git a/arch/avr32/kernel/signal.c b/arch/avr32/kernel/signal.c
index ae386c304bee..c140f9b41dce 100644
--- a/arch/avr32/kernel/signal.c
+++ b/arch/avr32/kernel/signal.c
@@ -22,8 +22,6 @@
22#include <asm/ucontext.h> 22#include <asm/ucontext.h>
23#include <asm/syscalls.h> 23#include <asm/syscalls.h>
24 24
25#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
26
27asmlinkage int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, 25asmlinkage int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
28 struct pt_regs *regs) 26 struct pt_regs *regs)
29{ 27{
@@ -89,7 +87,6 @@ asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
89 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 87 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
90 goto badframe; 88 goto badframe;
91 89
92 sigdelsetmask(&set, ~_BLOCKABLE);
93 set_current_blocked(&set); 90 set_current_blocked(&set);
94 91
95 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 92 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -224,30 +221,27 @@ static inline void setup_syscall_restart(struct pt_regs *regs)
224 221
225static inline void 222static inline void
226handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info, 223handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
227 sigset_t *oldset, struct pt_regs *regs, int syscall) 224 struct pt_regs *regs, int syscall)
228{ 225{
229 int ret; 226 int ret;
230 227
231 /* 228 /*
232 * Set up the stack frame 229 * Set up the stack frame
233 */ 230 */
234 ret = setup_rt_frame(sig, ka, info, oldset, regs); 231 ret = setup_rt_frame(sig, ka, info, sigmask_to_save(), regs);
235 232
236 /* 233 /*
237 * Check that the resulting registers are sane 234 * Check that the resulting registers are sane
238 */ 235 */
239 ret |= !valid_user_regs(regs); 236 ret |= !valid_user_regs(regs);
240 237
241 if (ret != 0) {
242 force_sigsegv(sig, current);
243 return;
244 }
245
246 /* 238 /*
247 * Block the signal if we were successful. 239 * Block the signal if we were successful.
248 */ 240 */
249 block_sigmask(ka, sig); 241 if (ret != 0)
250 clear_thread_flag(TIF_RESTORE_SIGMASK); 242 force_sigsegv(sig, current);
243 else
244 signal_delivered(sig, info, ka, regs, 0);
251} 245}
252 246
253/* 247/*
@@ -255,7 +249,7 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
255 * doesn't want to handle. Thus you cannot kill init even with a 249 * doesn't want to handle. Thus you cannot kill init even with a
256 * SIGKILL even by mistake. 250 * SIGKILL even by mistake.
257 */ 251 */
258int do_signal(struct pt_regs *regs, sigset_t *oldset, int syscall) 252static void do_signal(struct pt_regs *regs, int syscall)
259{ 253{
260 siginfo_t info; 254 siginfo_t info;
261 int signr; 255 int signr;
@@ -267,12 +261,7 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset, int syscall)
267 * without doing anything if so. 261 * without doing anything if so.
268 */ 262 */
269 if (!user_mode(regs)) 263 if (!user_mode(regs))
270 return 0; 264 return;
271
272 if (test_thread_flag(TIF_RESTORE_SIGMASK))
273 oldset = &current->saved_sigmask;
274 else if (!oldset)
275 oldset = &current->blocked;
276 265
277 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 266 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
278 if (syscall) { 267 if (syscall) {
@@ -297,15 +286,11 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset, int syscall)
297 286
298 if (signr == 0) { 287 if (signr == 0) {
299 /* No signal to deliver -- put the saved sigmask back */ 288 /* No signal to deliver -- put the saved sigmask back */
300 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 289 restore_saved_sigmask();
301 clear_thread_flag(TIF_RESTORE_SIGMASK); 290 return;
302 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
303 }
304 return 0;
305 } 291 }
306 292
307 handle_signal(signr, &ka, &info, oldset, regs, syscall); 293 handle_signal(signr, &ka, &info, regs, syscall);
308 return 1;
309} 294}
310 295
311asmlinkage void do_notify_resume(struct pt_regs *regs, struct thread_info *ti) 296asmlinkage void do_notify_resume(struct pt_regs *regs, struct thread_info *ti)
@@ -315,13 +300,11 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, struct thread_info *ti)
315 if ((sysreg_read(SR) & MODE_MASK) == MODE_SUPERVISOR) 300 if ((sysreg_read(SR) & MODE_MASK) == MODE_SUPERVISOR)
316 syscall = 1; 301 syscall = 1;
317 302
318 if (ti->flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 303 if (ti->flags & _TIF_SIGPENDING))
319 do_signal(regs, &current->blocked, syscall); 304 do_signal(regs, syscall);
320 305
321 if (ti->flags & _TIF_NOTIFY_RESUME) { 306 if (ti->flags & _TIF_NOTIFY_RESUME) {
322 clear_thread_flag(TIF_NOTIFY_RESUME); 307 clear_thread_flag(TIF_NOTIFY_RESUME);
323 tracehook_notify_resume(regs); 308 tracehook_notify_resume(regs);
324 if (current->replacement_session_keyring)
325 key_replace_session_keyring();
326 } 309 }
327} 310}
diff --git a/arch/blackfin/include/asm/posix_types.h b/arch/blackfin/include/asm/posix_types.h
index 41bc1875c4d7..1bd3436db6a7 100644
--- a/arch/blackfin/include/asm/posix_types.h
+++ b/arch/blackfin/include/asm/posix_types.h
@@ -10,9 +10,6 @@
10typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t 11#define __kernel_mode_t __kernel_mode_t
12 12
13typedef unsigned short __kernel_nlink_t;
14#define __kernel_nlink_t __kernel_nlink_t
15
16typedef unsigned int __kernel_ipc_pid_t; 13typedef unsigned int __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t 14#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18 15
diff --git a/arch/blackfin/include/asm/thread_info.h b/arch/blackfin/include/asm/thread_info.h
index 02560fd8a121..53ad10005ae3 100644
--- a/arch/blackfin/include/asm/thread_info.h
+++ b/arch/blackfin/include/asm/thread_info.h
@@ -100,7 +100,6 @@ static inline struct thread_info *current_thread_info(void)
100 TIF_NEED_RESCHED */ 100 TIF_NEED_RESCHED */
101#define TIF_MEMDIE 4 /* is terminating due to OOM killer */ 101#define TIF_MEMDIE 4 /* is terminating due to OOM killer */
102#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */ 102#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */
103#define TIF_FREEZE 6 /* is freezing for suspend */
104#define TIF_IRQ_SYNC 7 /* sync pipeline stage */ 103#define TIF_IRQ_SYNC 7 /* sync pipeline stage */
105#define TIF_NOTIFY_RESUME 8 /* callback before returning to user */ 104#define TIF_NOTIFY_RESUME 8 /* callback before returning to user */
106#define TIF_SINGLESTEP 9 105#define TIF_SINGLESTEP 9
@@ -111,7 +110,6 @@ static inline struct thread_info *current_thread_info(void)
111#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED) 110#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
112#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG) 111#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
113#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK) 112#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)
114#define _TIF_FREEZE (1<<TIF_FREEZE)
115#define _TIF_IRQ_SYNC (1<<TIF_IRQ_SYNC) 113#define _TIF_IRQ_SYNC (1<<TIF_IRQ_SYNC)
116#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME) 114#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
117#define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP) 115#define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)
diff --git a/arch/blackfin/kernel/signal.c b/arch/blackfin/kernel/signal.c
index e5bbc1a5edc2..6682b73a8523 100644
--- a/arch/blackfin/kernel/signal.c
+++ b/arch/blackfin/kernel/signal.c
@@ -19,8 +19,6 @@
19#include <asm/fixed_code.h> 19#include <asm/fixed_code.h>
20#include <asm/syscall.h> 20#include <asm/syscall.h>
21 21
22#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
23
24/* Location of the trace bit in SYSCFG. */ 22/* Location of the trace bit in SYSCFG. */
25#define TRACE_BITS 0x0001 23#define TRACE_BITS 0x0001
26 24
@@ -98,7 +96,6 @@ asmlinkage int do_rt_sigreturn(unsigned long __unused)
98 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 96 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
99 goto badframe; 97 goto badframe;
100 98
101 sigdelsetmask(&set, ~_BLOCKABLE);
102 set_current_blocked(&set); 99 set_current_blocked(&set);
103 100
104 if (rt_restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0)) 101 if (rt_restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0))
@@ -190,17 +187,22 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t * info,
190 err |= copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); 187 err |= copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
191 188
192 if (err) 189 if (err)
193 goto give_sigsegv; 190 return -EFAULT;
194 191
195 /* Set up registers for signal handler */ 192 /* Set up registers for signal handler */
196 wrusp((unsigned long)frame);
197 if (current->personality & FDPIC_FUNCPTRS) { 193 if (current->personality & FDPIC_FUNCPTRS) {
198 struct fdpic_func_descriptor __user *funcptr = 194 struct fdpic_func_descriptor __user *funcptr =
199 (struct fdpic_func_descriptor *) ka->sa.sa_handler; 195 (struct fdpic_func_descriptor *) ka->sa.sa_handler;
200 __get_user(regs->pc, &funcptr->text); 196 u32 pc, p3;
201 __get_user(regs->p3, &funcptr->GOT); 197 err |= __get_user(pc, &funcptr->text);
198 err |= __get_user(p3, &funcptr->GOT);
199 if (err)
200 return -EFAULT;
201 regs->pc = pc;
202 regs->p3 = p3;
202 } else 203 } else
203 regs->pc = (unsigned long)ka->sa.sa_handler; 204 regs->pc = (unsigned long)ka->sa.sa_handler;
205 wrusp((unsigned long)frame);
204 regs->rets = SIGRETURN_STUB; 206 regs->rets = SIGRETURN_STUB;
205 207
206 regs->r0 = frame->sig; 208 regs->r0 = frame->sig;
@@ -208,10 +210,6 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t * info,
208 regs->r2 = (unsigned long)(&frame->uc); 210 regs->r2 = (unsigned long)(&frame->uc);
209 211
210 return 0; 212 return 0;
211
212 give_sigsegv:
213 force_sigsegv(sig, current);
214 return -EFAULT;
215} 213}
216 214
217static inline void 215static inline void
@@ -247,24 +245,21 @@ handle_restart(struct pt_regs *regs, struct k_sigaction *ka, int has_handler)
247/* 245/*
248 * OK, we're invoking a handler 246 * OK, we're invoking a handler
249 */ 247 */
250static int 248static void
251handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka, 249handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka,
252 sigset_t *oldset, struct pt_regs *regs) 250 struct pt_regs *regs)
253{ 251{
254 int ret;
255
256 /* are we from a system call? to see pt_regs->orig_p0 */ 252 /* are we from a system call? to see pt_regs->orig_p0 */
257 if (regs->orig_p0 >= 0) 253 if (regs->orig_p0 >= 0)
258 /* If so, check system call restarting.. */ 254 /* If so, check system call restarting.. */
259 handle_restart(regs, ka, 1); 255 handle_restart(regs, ka, 1);
260 256
261 /* set up the stack frame */ 257 /* set up the stack frame */
262 ret = setup_rt_frame(sig, ka, info, oldset, regs); 258 if (setup_rt_frame(sig, ka, info, sigmask_to_save(), regs) < 0)
263 259 force_sigsegv(sig, current);
264 if (ret == 0) 260 else
265 block_sigmask(ka, sig); 261 signal_delivered(sig, info, ka, regs,
266 262 test_thread_flag(TIF_SINGLESTEP));
267 return ret;
268} 263}
269 264
270/* 265/*
@@ -281,37 +276,16 @@ asmlinkage void do_signal(struct pt_regs *regs)
281 siginfo_t info; 276 siginfo_t info;
282 int signr; 277 int signr;
283 struct k_sigaction ka; 278 struct k_sigaction ka;
284 sigset_t *oldset;
285 279
286 current->thread.esp0 = (unsigned long)regs; 280 current->thread.esp0 = (unsigned long)regs;
287 281
288 if (try_to_freeze())
289 goto no_signal;
290
291 if (test_thread_flag(TIF_RESTORE_SIGMASK))
292 oldset = &current->saved_sigmask;
293 else
294 oldset = &current->blocked;
295
296 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 282 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
297 if (signr > 0) { 283 if (signr > 0) {
298 /* Whee! Actually deliver the signal. */ 284 /* Whee! Actually deliver the signal. */
299 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 285 handle_signal(signr, &info, &ka, regs);
300 /* a signal was successfully delivered; the saved
301 * sigmask will have been stored in the signal frame,
302 * and will be restored by sigreturn, so we can simply
303 * clear the TIF_RESTORE_SIGMASK flag */
304 if (test_thread_flag(TIF_RESTORE_SIGMASK))
305 clear_thread_flag(TIF_RESTORE_SIGMASK);
306
307 tracehook_signal_handler(signr, &info, &ka, regs,
308 test_thread_flag(TIF_SINGLESTEP));
309 }
310
311 return; 286 return;
312 } 287 }
313 288
314 no_signal:
315 /* Did we come from a system call? */ 289 /* Did we come from a system call? */
316 if (regs->orig_p0 >= 0) 290 if (regs->orig_p0 >= 0)
317 /* Restart the system call - no handlers present */ 291 /* Restart the system call - no handlers present */
@@ -319,10 +293,7 @@ asmlinkage void do_signal(struct pt_regs *regs)
319 293
320 /* if there's no signal to deliver, we just put the saved sigmask 294 /* if there's no signal to deliver, we just put the saved sigmask
321 * back */ 295 * back */
322 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 296 restore_saved_sigmask();
323 clear_thread_flag(TIF_RESTORE_SIGMASK);
324 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
325 }
326} 297}
327 298
328/* 299/*
@@ -330,14 +301,12 @@ asmlinkage void do_signal(struct pt_regs *regs)
330 */ 301 */
331asmlinkage void do_notify_resume(struct pt_regs *regs) 302asmlinkage void do_notify_resume(struct pt_regs *regs)
332{ 303{
333 if (test_thread_flag(TIF_SIGPENDING) || test_thread_flag(TIF_RESTORE_SIGMASK)) 304 if (test_thread_flag(TIF_SIGPENDING))
334 do_signal(regs); 305 do_signal(regs);
335 306
336 if (test_thread_flag(TIF_NOTIFY_RESUME)) { 307 if (test_thread_flag(TIF_NOTIFY_RESUME)) {
337 clear_thread_flag(TIF_NOTIFY_RESUME); 308 clear_thread_flag(TIF_NOTIFY_RESUME);
338 tracehook_notify_resume(regs); 309 tracehook_notify_resume(regs);
339 if (current->replacement_session_keyring)
340 key_replace_session_keyring();
341 } 310 }
342} 311}
343 312
diff --git a/arch/blackfin/kernel/trace.c b/arch/blackfin/kernel/trace.c
index 44bbf2f564cb..f7f7a18abca9 100644
--- a/arch/blackfin/kernel/trace.c
+++ b/arch/blackfin/kernel/trace.c
@@ -10,6 +10,8 @@
10#include <linux/hardirq.h> 10#include <linux/hardirq.h>
11#include <linux/thread_info.h> 11#include <linux/thread_info.h>
12#include <linux/mm.h> 12#include <linux/mm.h>
13#include <linux/oom.h>
14#include <linux/sched.h>
13#include <linux/uaccess.h> 15#include <linux/uaccess.h>
14#include <linux/module.h> 16#include <linux/module.h>
15#include <linux/kallsyms.h> 17#include <linux/kallsyms.h>
@@ -27,8 +29,7 @@ void decode_address(char *buf, unsigned long address)
27{ 29{
28 struct task_struct *p; 30 struct task_struct *p;
29 struct mm_struct *mm; 31 struct mm_struct *mm;
30 unsigned long flags, offset; 32 unsigned long offset;
31 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
32 struct rb_node *n; 33 struct rb_node *n;
33 34
34#ifdef CONFIG_KALLSYMS 35#ifdef CONFIG_KALLSYMS
@@ -112,17 +113,17 @@ void decode_address(char *buf, unsigned long address)
112 * mappings of all our processes and see if we can't be a whee 113 * mappings of all our processes and see if we can't be a whee
113 * bit more specific 114 * bit more specific
114 */ 115 */
115 write_lock_irqsave(&tasklist_lock, flags); 116 read_lock(&tasklist_lock);
116 for_each_process(p) { 117 for_each_process(p) {
117 mm = (in_atomic ? p->mm : get_task_mm(p)); 118 struct task_struct *t;
118 if (!mm)
119 continue;
120 119
121 if (!down_read_trylock(&mm->mmap_sem)) { 120 t = find_lock_task_mm(p);
122 if (!in_atomic) 121 if (!t)
123 mmput(mm);
124 continue; 122 continue;
125 } 123
124 mm = t->mm;
125 if (!down_read_trylock(&mm->mmap_sem))
126 goto __continue;
126 127
127 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) { 128 for (n = rb_first(&mm->mm_rb); n; n = rb_next(n)) {
128 struct vm_area_struct *vma; 129 struct vm_area_struct *vma;
@@ -131,7 +132,7 @@ void decode_address(char *buf, unsigned long address)
131 132
132 if (address >= vma->vm_start && address < vma->vm_end) { 133 if (address >= vma->vm_start && address < vma->vm_end) {
133 char _tmpbuf[256]; 134 char _tmpbuf[256];
134 char *name = p->comm; 135 char *name = t->comm;
135 struct file *file = vma->vm_file; 136 struct file *file = vma->vm_file;
136 137
137 if (file) { 138 if (file) {
@@ -164,8 +165,7 @@ void decode_address(char *buf, unsigned long address)
164 name, vma->vm_start, vma->vm_end); 165 name, vma->vm_start, vma->vm_end);
165 166
166 up_read(&mm->mmap_sem); 167 up_read(&mm->mmap_sem);
167 if (!in_atomic) 168 task_unlock(t);
168 mmput(mm);
169 169
170 if (buf[0] == '\0') 170 if (buf[0] == '\0')
171 sprintf(buf, "[ %s ] dynamic memory", name); 171 sprintf(buf, "[ %s ] dynamic memory", name);
@@ -175,8 +175,8 @@ void decode_address(char *buf, unsigned long address)
175 } 175 }
176 176
177 up_read(&mm->mmap_sem); 177 up_read(&mm->mmap_sem);
178 if (!in_atomic) 178__continue:
179 mmput(mm); 179 task_unlock(t);
180 } 180 }
181 181
182 /* 182 /*
@@ -186,7 +186,7 @@ void decode_address(char *buf, unsigned long address)
186 sprintf(buf, "/* kernel dynamic memory */"); 186 sprintf(buf, "/* kernel dynamic memory */");
187 187
188done: 188done:
189 write_unlock_irqrestore(&tasklist_lock, flags); 189 read_unlock(&tasklist_lock);
190} 190}
191 191
192#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1) 192#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
diff --git a/arch/blackfin/mach-bf561/boards/acvilon.c b/arch/blackfin/mach-bf561/boards/acvilon.c
index f6ffd6f054c3..0b74218fdd3a 100644
--- a/arch/blackfin/mach-bf561/boards/acvilon.c
+++ b/arch/blackfin/mach-bf561/boards/acvilon.c
@@ -248,8 +248,6 @@ static struct platform_device bfin_uart0_device = {
248 248
249#if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE) 249#if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
250 250
251const char *part_probes[] = { "cmdlinepart", NULL };
252
253static struct mtd_partition bfin_plat_nand_partitions[] = { 251static struct mtd_partition bfin_plat_nand_partitions[] = {
254 { 252 {
255 .name = "params(nand)", 253 .name = "params(nand)",
@@ -289,7 +287,6 @@ static struct platform_nand_data bfin_plat_nand_data = {
289 .chip = { 287 .chip = {
290 .nr_chips = 1, 288 .nr_chips = 1,
291 .chip_delay = 30, 289 .chip_delay = 30,
292 .part_probe_types = part_probes,
293 .partitions = bfin_plat_nand_partitions, 290 .partitions = bfin_plat_nand_partitions,
294 .nr_partitions = ARRAY_SIZE(bfin_plat_nand_partitions), 291 .nr_partitions = ARRAY_SIZE(bfin_plat_nand_partitions),
295 }, 292 },
diff --git a/arch/blackfin/mach-common/entry.S b/arch/blackfin/mach-common/entry.S
index 80aa2535e2c9..04c2fbe41a7f 100644
--- a/arch/blackfin/mach-common/entry.S
+++ b/arch/blackfin/mach-common/entry.S
@@ -711,8 +711,6 @@ ENTRY(_system_call)
711 jump .Lresume_userspace_1; 711 jump .Lresume_userspace_1;
712 712
713.Lsyscall_sigpending: 713.Lsyscall_sigpending:
714 cc = BITTST(r7, TIF_RESTORE_SIGMASK);
715 if cc jump .Lsyscall_do_signals;
716 cc = BITTST(r7, TIF_SIGPENDING); 714 cc = BITTST(r7, TIF_SIGPENDING);
717 if cc jump .Lsyscall_do_signals; 715 if cc jump .Lsyscall_do_signals;
718 cc = BITTST(r7, TIF_NOTIFY_RESUME); 716 cc = BITTST(r7, TIF_NOTIFY_RESUME);
diff --git a/arch/c6x/kernel/signal.c b/arch/c6x/kernel/signal.c
index cf37478c1169..3d8f3c22a94f 100644
--- a/arch/c6x/kernel/signal.c
+++ b/arch/c6x/kernel/signal.c
@@ -20,8 +20,6 @@
20#include <asm/cacheflush.h> 20#include <asm/cacheflush.h>
21 21
22 22
23#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
24
25/* 23/*
26 * Do a signal return, undo the signal stack. 24 * Do a signal return, undo the signal stack.
27 */ 25 */
@@ -87,7 +85,6 @@ asmlinkage int do_rt_sigreturn(struct pt_regs *regs)
87 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 85 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
88 goto badframe; 86 goto badframe;
89 87
90 sigdelsetmask(&set, ~_BLOCKABLE);
91 set_current_blocked(&set); 88 set_current_blocked(&set);
92 89
93 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 90 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -248,10 +245,9 @@ do_restart:
248/* 245/*
249 * handle the actual delivery of a signal to userspace 246 * handle the actual delivery of a signal to userspace
250 */ 247 */
251static int handle_signal(int sig, 248static void handle_signal(int sig,
252 siginfo_t *info, struct k_sigaction *ka, 249 siginfo_t *info, struct k_sigaction *ka,
253 sigset_t *oldset, struct pt_regs *regs, 250 struct pt_regs *regs, int syscall)
254 int syscall)
255{ 251{
256 int ret; 252 int ret;
257 253
@@ -278,11 +274,9 @@ static int handle_signal(int sig,
278 } 274 }
279 275
280 /* Set up the stack frame */ 276 /* Set up the stack frame */
281 ret = setup_rt_frame(sig, ka, info, oldset, regs); 277 if (setup_rt_frame(sig, ka, info, sigmask_to_save(), regs) < 0)
282 if (ret == 0) 278 return;
283 block_sigmask(ka, sig); 279 signal_delivered(sig, info, ka, regs, 0);
284
285 return ret;
286} 280}
287 281
288/* 282/*
@@ -292,7 +286,6 @@ static void do_signal(struct pt_regs *regs, int syscall)
292{ 286{
293 struct k_sigaction ka; 287 struct k_sigaction ka;
294 siginfo_t info; 288 siginfo_t info;
295 sigset_t *oldset;
296 int signr; 289 int signr;
297 290
298 /* we want the common case to go fast, which is why we may in certain 291 /* we want the common case to go fast, which is why we may in certain
@@ -300,25 +293,9 @@ static void do_signal(struct pt_regs *regs, int syscall)
300 if (!user_mode(regs)) 293 if (!user_mode(regs))
301 return; 294 return;
302 295
303 if (test_thread_flag(TIF_RESTORE_SIGMASK))
304 oldset = &current->saved_sigmask;
305 else
306 oldset = &current->blocked;
307
308 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 296 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
309 if (signr > 0) { 297 if (signr > 0) {
310 if (handle_signal(signr, &info, &ka, oldset, 298 handle_signal(signr, &info, &ka, regs, syscall);
311 regs, syscall) == 0) {
312 /* a signal was successfully delivered; the saved
313 * sigmask will have been stored in the signal frame,
314 * and will be restored by sigreturn, so we can simply
315 * clear the TIF_RESTORE_SIGMASK flag */
316 if (test_thread_flag(TIF_RESTORE_SIGMASK))
317 clear_thread_flag(TIF_RESTORE_SIGMASK);
318
319 tracehook_signal_handler(signr, &info, &ka, regs, 0);
320 }
321
322 return; 299 return;
323 } 300 }
324 301
@@ -343,10 +320,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
343 320
344 /* if there's no signal to deliver, we just put the saved sigmask 321 /* if there's no signal to deliver, we just put the saved sigmask
345 * back */ 322 * back */
346 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 323 restore_saved_sigmask();
347 clear_thread_flag(TIF_RESTORE_SIGMASK);
348 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
349 }
350} 324}
351 325
352/* 326/*
@@ -357,14 +331,11 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags,
357 int syscall) 331 int syscall)
358{ 332{
359 /* deal with pending signal delivery */ 333 /* deal with pending signal delivery */
360 if (thread_info_flags & ((1 << TIF_SIGPENDING) | 334 if (thread_info_flags & (1 << TIF_SIGPENDING))
361 (1 << TIF_RESTORE_SIGMASK)))
362 do_signal(regs, syscall); 335 do_signal(regs, syscall);
363 336
364 if (thread_info_flags & (1 << TIF_NOTIFY_RESUME)) { 337 if (thread_info_flags & (1 << TIF_NOTIFY_RESUME)) {
365 clear_thread_flag(TIF_NOTIFY_RESUME); 338 clear_thread_flag(TIF_NOTIFY_RESUME);
366 tracehook_notify_resume(regs); 339 tracehook_notify_resume(regs);
367 if (current->replacement_session_keyring)
368 key_replace_session_keyring();
369 } 340 }
370} 341}
diff --git a/arch/cris/arch-v10/kernel/signal.c b/arch/cris/arch-v10/kernel/signal.c
index e16f8f297f61..0bb477c13a4e 100644
--- a/arch/cris/arch-v10/kernel/signal.c
+++ b/arch/cris/arch-v10/kernel/signal.c
@@ -31,8 +31,6 @@
31 31
32#define DEBUG_SIG 0 32#define DEBUG_SIG 0
33 33
34#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
35
36/* a syscall in Linux/CRIS is a break 13 instruction which is 2 bytes */ 34/* a syscall in Linux/CRIS is a break 13 instruction which is 2 bytes */
37/* manipulate regs so that upon return, it will be re-executed */ 35/* manipulate regs so that upon return, it will be re-executed */
38 36
@@ -176,7 +174,6 @@ asmlinkage int sys_sigreturn(long r10, long r11, long r12, long r13, long mof,
176 sizeof(frame->extramask)))) 174 sizeof(frame->extramask))))
177 goto badframe; 175 goto badframe;
178 176
179 sigdelsetmask(&set, ~_BLOCKABLE);
180 set_current_blocked(&set); 177 set_current_blocked(&set);
181 178
182 if (restore_sigcontext(regs, &frame->sc)) 179 if (restore_sigcontext(regs, &frame->sc))
@@ -212,7 +209,6 @@ asmlinkage int sys_rt_sigreturn(long r10, long r11, long r12, long r13,
212 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 209 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
213 goto badframe; 210 goto badframe;
214 211
215 sigdelsetmask(&set, ~_BLOCKABLE);
216 set_current_blocked(&set); 212 set_current_blocked(&set);
217 213
218 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 214 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -415,10 +411,11 @@ give_sigsegv:
415 * OK, we're invoking a handler 411 * OK, we're invoking a handler
416 */ 412 */
417 413
418static inline int handle_signal(int canrestart, unsigned long sig, 414static inline void handle_signal(int canrestart, unsigned long sig,
419 siginfo_t *info, struct k_sigaction *ka, 415 siginfo_t *info, struct k_sigaction *ka,
420 sigset_t *oldset, struct pt_regs *regs) 416 struct pt_regs *regs)
421{ 417{
418 sigset_t *oldset = sigmask_to_save();
422 int ret; 419 int ret;
423 420
424 /* Are we from a system call? */ 421 /* Are we from a system call? */
@@ -456,9 +453,7 @@ static inline int handle_signal(int canrestart, unsigned long sig,
456 ret = setup_frame(sig, ka, oldset, regs); 453 ret = setup_frame(sig, ka, oldset, regs);
457 454
458 if (ret == 0) 455 if (ret == 0)
459 block_sigmask(ka, sig); 456 signal_delivered(sig, info, ka, regs, 0);
460
461 return ret;
462} 457}
463 458
464/* 459/*
@@ -478,7 +473,6 @@ void do_signal(int canrestart, struct pt_regs *regs)
478 siginfo_t info; 473 siginfo_t info;
479 int signr; 474 int signr;
480 struct k_sigaction ka; 475 struct k_sigaction ka;
481 sigset_t *oldset;
482 476
483 /* 477 /*
484 * We want the common case to go fast, which 478 * We want the common case to go fast, which
@@ -489,23 +483,10 @@ void do_signal(int canrestart, struct pt_regs *regs)
489 if (!user_mode(regs)) 483 if (!user_mode(regs))
490 return; 484 return;
491 485
492 if (test_thread_flag(TIF_RESTORE_SIGMASK))
493 oldset = &current->saved_sigmask;
494 else
495 oldset = &current->blocked;
496
497 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 486 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
498 if (signr > 0) { 487 if (signr > 0) {
499 /* Whee! Actually deliver the signal. */ 488 /* Whee! Actually deliver the signal. */
500 if (handle_signal(canrestart, signr, &info, &ka, 489 handle_signal(canrestart, signr, &info, &ka, regs);
501 oldset, regs)) {
502 /* a signal was successfully delivered; the saved
503 * sigmask will have been stored in the signal frame,
504 * and will be restored by sigreturn, so we can simply
505 * clear the TIF_RESTORE_SIGMASK flag */
506 if (test_thread_flag(TIF_RESTORE_SIGMASK))
507 clear_thread_flag(TIF_RESTORE_SIGMASK);
508 }
509 return; 490 return;
510 } 491 }
511 492
@@ -525,8 +506,5 @@ void do_signal(int canrestart, struct pt_regs *regs)
525 506
526 /* if there's no signal to deliver, we just put the saved sigmask 507 /* if there's no signal to deliver, we just put the saved sigmask
527 * back */ 508 * back */
528 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 509 restore_saved_sigmask();
529 clear_thread_flag(TIF_RESTORE_SIGMASK);
530 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
531 }
532} 510}
diff --git a/arch/cris/arch-v32/kernel/signal.c b/arch/cris/arch-v32/kernel/signal.c
index b338d8fc0c12..b60d1b65a426 100644
--- a/arch/cris/arch-v32/kernel/signal.c
+++ b/arch/cris/arch-v32/kernel/signal.c
@@ -24,9 +24,6 @@
24 24
25extern unsigned long cris_signal_return_page; 25extern unsigned long cris_signal_return_page;
26 26
27/* Flag to check if a signal is blockable. */
28#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
29
30/* 27/*
31 * A syscall in CRIS is really a "break 13" instruction, which is 2 28 * A syscall in CRIS is really a "break 13" instruction, which is 2
32 * bytes. The registers is manipulated so upon return the instruction 29 * bytes. The registers is manipulated so upon return the instruction
@@ -167,7 +164,6 @@ sys_sigreturn(long r10, long r11, long r12, long r13, long mof, long srp,
167 sizeof(frame->extramask)))) 164 sizeof(frame->extramask))))
168 goto badframe; 165 goto badframe;
169 166
170 sigdelsetmask(&set, ~_BLOCKABLE);
171 set_current_blocked(&set); 167 set_current_blocked(&set);
172 168
173 if (restore_sigcontext(regs, &frame->sc)) 169 if (restore_sigcontext(regs, &frame->sc))
@@ -208,7 +204,6 @@ sys_rt_sigreturn(long r10, long r11, long r12, long r13, long mof, long srp,
208 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 204 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
209 goto badframe; 205 goto badframe;
210 206
211 sigdelsetmask(&set, ~_BLOCKABLE);
212 set_current_blocked(&set); 207 set_current_blocked(&set);
213 208
214 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 209 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -434,11 +429,12 @@ give_sigsegv:
434} 429}
435 430
436/* Invoke a signal handler to, well, handle the signal. */ 431/* Invoke a signal handler to, well, handle the signal. */
437static inline int 432static inline void
438handle_signal(int canrestart, unsigned long sig, 433handle_signal(int canrestart, unsigned long sig,
439 siginfo_t *info, struct k_sigaction *ka, 434 siginfo_t *info, struct k_sigaction *ka,
440 sigset_t *oldset, struct pt_regs * regs) 435 struct pt_regs * regs)
441{ 436{
437 sigset_t *oldset = sigmask_to_save();
442 int ret; 438 int ret;
443 439
444 /* Check if this got called from a system call. */ 440 /* Check if this got called from a system call. */
@@ -489,9 +485,7 @@ handle_signal(int canrestart, unsigned long sig,
489 ret = setup_frame(sig, ka, oldset, regs); 485 ret = setup_frame(sig, ka, oldset, regs);
490 486
491 if (ret == 0) 487 if (ret == 0)
492 block_sigmask(ka, sig); 488 signal_delivered(sig, info, ka, regs, 0);
493
494 return ret;
495} 489}
496 490
497/* 491/*
@@ -511,7 +505,6 @@ do_signal(int canrestart, struct pt_regs *regs)
511 int signr; 505 int signr;
512 siginfo_t info; 506 siginfo_t info;
513 struct k_sigaction ka; 507 struct k_sigaction ka;
514 sigset_t *oldset;
515 508
516 /* 509 /*
517 * The common case should go fast, which is why this point is 510 * The common case should go fast, which is why this point is
@@ -521,25 +514,11 @@ do_signal(int canrestart, struct pt_regs *regs)
521 if (!user_mode(regs)) 514 if (!user_mode(regs))
522 return; 515 return;
523 516
524 if (test_thread_flag(TIF_RESTORE_SIGMASK))
525 oldset = &current->saved_sigmask;
526 else
527 oldset = &current->blocked;
528
529 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 517 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
530 518
531 if (signr > 0) { 519 if (signr > 0) {
532 /* Whee! Actually deliver the signal. */ 520 /* Whee! Actually deliver the signal. */
533 if (handle_signal(canrestart, signr, &info, &ka, 521 handle_signal(canrestart, signr, &info, &ka, regs);
534 oldset, regs)) {
535 /* a signal was successfully delivered; the saved
536 * sigmask will have been stored in the signal frame,
537 * and will be restored by sigreturn, so we can simply
538 * clear the TIF_RESTORE_SIGMASK flag */
539 if (test_thread_flag(TIF_RESTORE_SIGMASK))
540 clear_thread_flag(TIF_RESTORE_SIGMASK);
541 }
542
543 return; 522 return;
544 } 523 }
545 524
@@ -560,10 +539,7 @@ do_signal(int canrestart, struct pt_regs *regs)
560 539
561 /* if there's no signal to deliver, we just put the saved sigmask 540 /* if there's no signal to deliver, we just put the saved sigmask
562 * back */ 541 * back */
563 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 542 restore_saved_sigmask();
564 clear_thread_flag(TIF_RESTORE_SIGMASK);
565 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
566 }
567} 543}
568 544
569asmlinkage void 545asmlinkage void
diff --git a/arch/cris/include/asm/posix_types.h b/arch/cris/include/asm/posix_types.h
index 234891c74e2b..ce4e51793151 100644
--- a/arch/cris/include/asm/posix_types.h
+++ b/arch/cris/include/asm/posix_types.h
@@ -15,9 +15,6 @@
15typedef unsigned short __kernel_mode_t; 15typedef unsigned short __kernel_mode_t;
16#define __kernel_mode_t __kernel_mode_t 16#define __kernel_mode_t __kernel_mode_t
17 17
18typedef unsigned short __kernel_nlink_t;
19#define __kernel_nlink_t __kernel_nlink_t
20
21typedef unsigned short __kernel_ipc_pid_t; 18typedef unsigned short __kernel_ipc_pid_t;
22#define __kernel_ipc_pid_t __kernel_ipc_pid_t 19#define __kernel_ipc_pid_t __kernel_ipc_pid_t
23 20
diff --git a/arch/cris/kernel/ptrace.c b/arch/cris/kernel/ptrace.c
index d114ad3da9b1..58d44ee1a71f 100644
--- a/arch/cris/kernel/ptrace.c
+++ b/arch/cris/kernel/ptrace.c
@@ -40,7 +40,5 @@ void do_notify_resume(int canrestart, struct pt_regs *regs,
40 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 40 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
41 clear_thread_flag(TIF_NOTIFY_RESUME); 41 clear_thread_flag(TIF_NOTIFY_RESUME);
42 tracehook_notify_resume(regs); 42 tracehook_notify_resume(regs);
43 if (current->replacement_session_keyring)
44 key_replace_session_keyring();
45 } 43 }
46} 44}
diff --git a/arch/frv/include/asm/posix_types.h b/arch/frv/include/asm/posix_types.h
index 3f34cb45fbb3..fe512af74a5a 100644
--- a/arch/frv/include/asm/posix_types.h
+++ b/arch/frv/include/asm/posix_types.h
@@ -10,9 +10,6 @@
10typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t 11#define __kernel_mode_t __kernel_mode_t
12 12
13typedef unsigned short __kernel_nlink_t;
14#define __kernel_nlink_t __kernel_nlink_t
15
16typedef unsigned short __kernel_ipc_pid_t; 13typedef unsigned short __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t 14#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18 15
diff --git a/arch/frv/include/asm/thread_info.h b/arch/frv/include/asm/thread_info.h
index 54ab13a0de41..0ff03a33c81e 100644
--- a/arch/frv/include/asm/thread_info.h
+++ b/arch/frv/include/asm/thread_info.h
@@ -94,8 +94,8 @@ register struct thread_info *__current_thread_info asm("gr15");
94#define TIF_NEED_RESCHED 3 /* rescheduling necessary */ 94#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
95#define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */ 95#define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */
96#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */ 96#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */
97#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */ 97#define TIF_POLLING_NRFLAG 6 /* true if poll_idle() is polling TIF_NEED_RESCHED */
98#define TIF_MEMDIE 17 /* is terminating due to OOM killer */ 98#define TIF_MEMDIE 7 /* is terminating due to OOM killer */
99 99
100#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) 100#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
101#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) 101#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
@@ -105,8 +105,16 @@ register struct thread_info *__current_thread_info asm("gr15");
105#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK) 105#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
106#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) 106#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
107 107
108#define _TIF_WORK_MASK 0x0000FFFE /* work to do on interrupt/exception return */ 108/* work to do on interrupt/exception return */
109#define _TIF_ALLWORK_MASK 0x0000FFFF /* work to do on any return to u-space */ 109#define _TIF_WORK_MASK \
110 (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_SINGLESTEP)
111
112/* work to do on any return to u-space */
113#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_SYSCALL_TRACE)
114
115#if _TIF_ALLWORK_MASK >= 0x2000
116#error "_TIF_ALLWORK_MASK won't fit in an ANDI now (see entry.S)"
117#endif
110 118
111/* 119/*
112 * Thread-synchronous status. 120 * Thread-synchronous status.
diff --git a/arch/frv/kernel/entry.S b/arch/frv/kernel/entry.S
index 5ba23f715ea5..7d5e000fd32e 100644
--- a/arch/frv/kernel/entry.S
+++ b/arch/frv/kernel/entry.S
@@ -905,18 +905,19 @@ __syscall_call:
905__syscall_exit: 905__syscall_exit:
906 LEDS 0x6300 906 LEDS 0x6300
907 907
908 sti gr8,@(gr28,#REG_GR(8)) ; save return value 908 # keep current PSR in GR23
909 movsg psr,gr23
909 910
910 # rebuild saved psr - execve will change it for init/main.c
911 ldi @(gr28,#REG_PSR),gr22 911 ldi @(gr28,#REG_PSR),gr22
912
913 sti.p gr8,@(gr28,#REG_GR(8)) ; save return value
914
915 # rebuild saved psr - execve will change it for init/main.c
912 srli gr22,#1,gr5 916 srli gr22,#1,gr5
913 andi.p gr22,#~PSR_PS,gr22 917 andi.p gr22,#~PSR_PS,gr22
914 andi gr5,#PSR_PS,gr5 918 andi gr5,#PSR_PS,gr5
915 or gr5,gr22,gr22 919 or gr5,gr22,gr22
916 ori gr22,#PSR_S,gr22 920 ori.p gr22,#PSR_S,gr22
917
918 # keep current PSR in GR23
919 movsg psr,gr23
920 921
921 # make sure we don't miss an interrupt setting need_resched or sigpending between 922 # make sure we don't miss an interrupt setting need_resched or sigpending between
922 # sampling and the RETT 923 # sampling and the RETT
@@ -924,9 +925,7 @@ __syscall_exit:
924 movgs gr23,psr 925 movgs gr23,psr
925 926
926 ldi @(gr15,#TI_FLAGS),gr4 927 ldi @(gr15,#TI_FLAGS),gr4
927 sethi.p %hi(_TIF_ALLWORK_MASK),gr5 928 andicc gr4,#_TIF_ALLWORK_MASK,gr0,icc0
928 setlo %lo(_TIF_ALLWORK_MASK),gr5
929 andcc gr4,gr5,gr0,icc0
930 bne icc0,#0,__syscall_exit_work 929 bne icc0,#0,__syscall_exit_work
931 930
932 # restore all registers and return 931 # restore all registers and return
@@ -1111,9 +1110,7 @@ __entry_resume_userspace:
1111__entry_return_from_user_interrupt: 1110__entry_return_from_user_interrupt:
1112 LEDS 0x6402 1111 LEDS 0x6402
1113 ldi @(gr15,#TI_FLAGS),gr4 1112 ldi @(gr15,#TI_FLAGS),gr4
1114 sethi.p %hi(_TIF_WORK_MASK),gr5 1113 andicc gr4,#_TIF_WORK_MASK,gr0,icc0
1115 setlo %lo(_TIF_WORK_MASK),gr5
1116 andcc gr4,gr5,gr0,icc0
1117 beq icc0,#1,__entry_return_direct 1114 beq icc0,#1,__entry_return_direct
1118 1115
1119__entry_work_pending: 1116__entry_work_pending:
@@ -1133,9 +1130,7 @@ __entry_work_resched:
1133 1130
1134 LEDS 0x6401 1131 LEDS 0x6401
1135 ldi @(gr15,#TI_FLAGS),gr4 1132 ldi @(gr15,#TI_FLAGS),gr4
1136 sethi.p %hi(_TIF_WORK_MASK),gr5 1133 andicc gr4,#_TIF_WORK_MASK,gr0,icc0
1137 setlo %lo(_TIF_WORK_MASK),gr5
1138 andcc gr4,gr5,gr0,icc0
1139 beq icc0,#1,__entry_return_direct 1134 beq icc0,#1,__entry_return_direct
1140 andicc gr4,#_TIF_NEED_RESCHED,gr0,icc0 1135 andicc gr4,#_TIF_NEED_RESCHED,gr0,icc0
1141 bne icc0,#1,__entry_work_resched 1136 bne icc0,#1,__entry_work_resched
@@ -1163,7 +1158,9 @@ __syscall_trace_entry:
1163 # perform syscall exit tracing 1158 # perform syscall exit tracing
1164__syscall_exit_work: 1159__syscall_exit_work:
1165 LEDS 0x6340 1160 LEDS 0x6340
1166 andicc gr4,#_TIF_SYSCALL_TRACE,gr0,icc0 1161 andicc gr22,#PSR_PS,gr0,icc1 ; don't handle on return to kernel mode
1162 andicc.p gr4,#_TIF_SYSCALL_TRACE,gr0,icc0
1163 bne icc1,#0,__entry_return_direct
1167 beq icc0,#1,__entry_work_pending 1164 beq icc0,#1,__entry_work_pending
1168 1165
1169 movsg psr,gr23 1166 movsg psr,gr23
diff --git a/arch/frv/kernel/signal.c b/arch/frv/kernel/signal.c
index 8cf5dca01758..864c2f0d497b 100644
--- a/arch/frv/kernel/signal.c
+++ b/arch/frv/kernel/signal.c
@@ -28,8 +28,6 @@
28 28
29#define DEBUG_SIG 0 29#define DEBUG_SIG 0
30 30
31#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
32
33struct fdpic_func_descriptor { 31struct fdpic_func_descriptor {
34 unsigned long text; 32 unsigned long text;
35 unsigned long GOT; 33 unsigned long GOT;
@@ -149,7 +147,6 @@ asmlinkage int sys_sigreturn(void)
149 __copy_from_user(&set.sig[1], &frame->extramask, sizeof(frame->extramask))) 147 __copy_from_user(&set.sig[1], &frame->extramask, sizeof(frame->extramask)))
150 goto badframe; 148 goto badframe;
151 149
152 sigdelsetmask(&set, ~_BLOCKABLE);
153 set_current_blocked(&set); 150 set_current_blocked(&set);
154 151
155 if (restore_sigcontext(&frame->sc, &gr8)) 152 if (restore_sigcontext(&frame->sc, &gr8))
@@ -172,7 +169,6 @@ asmlinkage int sys_rt_sigreturn(void)
172 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 169 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
173 goto badframe; 170 goto badframe;
174 171
175 sigdelsetmask(&set, ~_BLOCKABLE);
176 set_current_blocked(&set); 172 set_current_blocked(&set);
177 173
178 if (restore_sigcontext(&frame->uc.uc_mcontext, &gr8)) 174 if (restore_sigcontext(&frame->uc.uc_mcontext, &gr8))
@@ -426,9 +422,10 @@ give_sigsegv:
426/* 422/*
427 * OK, we're invoking a handler 423 * OK, we're invoking a handler
428 */ 424 */
429static int handle_signal(unsigned long sig, siginfo_t *info, 425static void handle_signal(unsigned long sig, siginfo_t *info,
430 struct k_sigaction *ka, sigset_t *oldset) 426 struct k_sigaction *ka)
431{ 427{
428 sigset_t *oldset = sigmask_to_save();
432 int ret; 429 int ret;
433 430
434 /* Are we from a system call? */ 431 /* Are we from a system call? */
@@ -460,11 +457,11 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
460 else 457 else
461 ret = setup_frame(sig, ka, oldset); 458 ret = setup_frame(sig, ka, oldset);
462 459
463 if (ret == 0) 460 if (ret)
464 block_sigmask(ka, sig); 461 return;
465
466 return ret;
467 462
463 signal_delivered(sig, info, ka, __frame,
464 test_thread_flag(TIF_SINGLESTEP));
468} /* end handle_signal() */ 465} /* end handle_signal() */
469 466
470/*****************************************************************************/ 467/*****************************************************************************/
@@ -477,44 +474,14 @@ static void do_signal(void)
477{ 474{
478 struct k_sigaction ka; 475 struct k_sigaction ka;
479 siginfo_t info; 476 siginfo_t info;
480 sigset_t *oldset;
481 int signr; 477 int signr;
482 478
483 /*
484 * We want the common case to go fast, which
485 * is why we may in certain cases get here from
486 * kernel mode. Just return without doing anything
487 * if so.
488 */
489 if (!user_mode(__frame))
490 return;
491
492 if (try_to_freeze())
493 goto no_signal;
494
495 if (test_thread_flag(TIF_RESTORE_SIGMASK))
496 oldset = &current->saved_sigmask;
497 else
498 oldset = &current->blocked;
499
500 signr = get_signal_to_deliver(&info, &ka, __frame, NULL); 479 signr = get_signal_to_deliver(&info, &ka, __frame, NULL);
501 if (signr > 0) { 480 if (signr > 0) {
502 if (handle_signal(signr, &info, &ka, oldset) == 0) { 481 handle_signal(signr, &info, &ka);
503 /* a signal was successfully delivered; the saved
504 * sigmask will have been stored in the signal frame,
505 * and will be restored by sigreturn, so we can simply
506 * clear the TIF_RESTORE_SIGMASK flag */
507 if (test_thread_flag(TIF_RESTORE_SIGMASK))
508 clear_thread_flag(TIF_RESTORE_SIGMASK);
509
510 tracehook_signal_handler(signr, &info, &ka, __frame,
511 test_thread_flag(TIF_SINGLESTEP));
512 }
513
514 return; 482 return;
515 } 483 }
516 484
517no_signal:
518 /* Did we come from a system call? */ 485 /* Did we come from a system call? */
519 if (__frame->syscallno != -1) { 486 if (__frame->syscallno != -1) {
520 /* Restart the system call - no handlers present */ 487 /* Restart the system call - no handlers present */
@@ -536,11 +503,7 @@ no_signal:
536 503
537 /* if there's no signal to deliver, we just put the saved sigmask 504 /* if there's no signal to deliver, we just put the saved sigmask
538 * back */ 505 * back */
539 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 506 restore_saved_sigmask();
540 clear_thread_flag(TIF_RESTORE_SIGMASK);
541 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
542 }
543
544} /* end do_signal() */ 507} /* end do_signal() */
545 508
546/*****************************************************************************/ 509/*****************************************************************************/
@@ -555,15 +518,13 @@ asmlinkage void do_notify_resume(__u32 thread_info_flags)
555 clear_thread_flag(TIF_SINGLESTEP); 518 clear_thread_flag(TIF_SINGLESTEP);
556 519
557 /* deal with pending signal delivery */ 520 /* deal with pending signal delivery */
558 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 521 if (thread_info_flags & _TIF_SIGPENDING)
559 do_signal(); 522 do_signal();
560 523
561 /* deal with notification on about to resume userspace execution */ 524 /* deal with notification on about to resume userspace execution */
562 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 525 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
563 clear_thread_flag(TIF_NOTIFY_RESUME); 526 clear_thread_flag(TIF_NOTIFY_RESUME);
564 tracehook_notify_resume(__frame); 527 tracehook_notify_resume(__frame);
565 if (current->replacement_session_keyring)
566 key_replace_session_keyring();
567 } 528 }
568 529
569} /* end do_notify_resume() */ 530} /* end do_notify_resume() */
diff --git a/arch/h8300/include/asm/posix_types.h b/arch/h8300/include/asm/posix_types.h
index bc4c34efb1ad..91e62ba4c7b0 100644
--- a/arch/h8300/include/asm/posix_types.h
+++ b/arch/h8300/include/asm/posix_types.h
@@ -10,9 +10,6 @@
10typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t 11#define __kernel_mode_t __kernel_mode_t
12 12
13typedef unsigned short __kernel_nlink_t;
14#define __kernel_nlink_t __kernel_nlink_t
15
16typedef unsigned short __kernel_ipc_pid_t; 13typedef unsigned short __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t 14#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18 15
diff --git a/arch/h8300/kernel/signal.c b/arch/h8300/kernel/signal.c
index d4b0555d2904..fca10378701b 100644
--- a/arch/h8300/kernel/signal.c
+++ b/arch/h8300/kernel/signal.c
@@ -47,8 +47,6 @@
47#include <asm/traps.h> 47#include <asm/traps.h>
48#include <asm/ucontext.h> 48#include <asm/ucontext.h>
49 49
50#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
51
52/* 50/*
53 * Atomically swap in the new signal mask, and wait for a signal. 51 * Atomically swap in the new signal mask, and wait for a signal.
54 */ 52 */
@@ -186,7 +184,6 @@ asmlinkage int do_sigreturn(unsigned long __unused,...)
186 sizeof(frame->extramask)))) 184 sizeof(frame->extramask))))
187 goto badframe; 185 goto badframe;
188 186
189 sigdelsetmask(&set, ~_BLOCKABLE);
190 set_current_blocked(&set); 187 set_current_blocked(&set);
191 188
192 if (restore_sigcontext(regs, &frame->sc, &er0)) 189 if (restore_sigcontext(regs, &frame->sc, &er0))
@@ -211,7 +208,6 @@ asmlinkage int do_rt_sigreturn(unsigned long __unused,...)
211 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 208 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
212 goto badframe; 209 goto badframe;
213 210
214 sigdelsetmask(&set, ~_BLOCKABLE);
215 set_current_blocked(&set); 211 set_current_blocked(&set);
216 212
217 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &er0)) 213 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &er0))
@@ -412,8 +408,9 @@ give_sigsegv:
412 */ 408 */
413static void 409static void
414handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, 410handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
415 sigset_t *oldset, struct pt_regs * regs) 411 struct pt_regs * regs)
416{ 412{
413 sigset_t *oldset = sigmask_to_save();
417 int ret; 414 int ret;
418 /* are we from a system call? */ 415 /* are we from a system call? */
419 if (regs->orig_er0 >= 0) { 416 if (regs->orig_er0 >= 0) {
@@ -441,10 +438,8 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
441 else 438 else
442 ret = setup_frame(sig, ka, oldset, regs); 439 ret = setup_frame(sig, ka, oldset, regs);
443 440
444 if (!ret) { 441 if (!ret)
445 block_sigmask(ka, sig); 442 signal_delivered(sig, info, ka, regs, 0);
446 clear_thread_flag(TIF_RESTORE_SIGMASK);
447 }
448} 443}
449 444
450/* 445/*
@@ -457,7 +452,6 @@ statis void do_signal(struct pt_regs *regs)
457 siginfo_t info; 452 siginfo_t info;
458 int signr; 453 int signr;
459 struct k_sigaction ka; 454 struct k_sigaction ka;
460 sigset_t *oldset;
461 455
462 /* 456 /*
463 * We want the common case to go fast, which 457 * We want the common case to go fast, which
@@ -468,23 +462,14 @@ statis void do_signal(struct pt_regs *regs)
468 if ((regs->ccr & 0x10)) 462 if ((regs->ccr & 0x10))
469 return; 463 return;
470 464
471 if (try_to_freeze())
472 goto no_signal;
473
474 current->thread.esp0 = (unsigned long) regs; 465 current->thread.esp0 = (unsigned long) regs;
475 466
476 if (test_thread_flag(TIF_RESTORE_SIGMASK))
477 oldset = &current->saved_sigmask;
478 else
479 oldset = &current->blocked;
480
481 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 467 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
482 if (signr > 0) { 468 if (signr > 0) {
483 /* Whee! Actually deliver the signal. */ 469 /* Whee! Actually deliver the signal. */
484 handle_signal(signr, &info, &ka, oldset, regs); 470 handle_signal(signr, &info, &ka, regs);
485 return; 471 return;
486 } 472 }
487 no_signal:
488 /* Did we come from a system call? */ 473 /* Did we come from a system call? */
489 if (regs->orig_er0 >= 0) { 474 if (regs->orig_er0 >= 0) {
490 /* Restart the system call - no handlers present */ 475 /* Restart the system call - no handlers present */
@@ -501,8 +486,7 @@ statis void do_signal(struct pt_regs *regs)
501 } 486 }
502 487
503 /* If there's no signal to deliver, we just restore the saved mask. */ 488 /* If there's no signal to deliver, we just restore the saved mask. */
504 if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK)) 489 restore_saved_sigmask();
505 set_current_blocked(&current->saved_sigmask);
506} 490}
507 491
508asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags) 492asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags)
@@ -513,7 +497,5 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags)
513 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 497 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
514 clear_thread_flag(TIF_NOTIFY_RESUME); 498 clear_thread_flag(TIF_NOTIFY_RESUME);
515 tracehook_notify_resume(regs); 499 tracehook_notify_resume(regs);
516 if (current->replacement_session_keyring)
517 key_replace_session_keyring();
518 } 500 }
519} 501}
diff --git a/arch/hexagon/kernel/signal.c b/arch/hexagon/kernel/signal.c
index 434866eb0f1c..304b0808d072 100644
--- a/arch/hexagon/kernel/signal.c
+++ b/arch/hexagon/kernel/signal.c
@@ -31,8 +31,6 @@
31#include <asm/signal.h> 31#include <asm/signal.h>
32#include <asm/vdso.h> 32#include <asm/vdso.h>
33 33
34#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
35
36struct rt_sigframe { 34struct rt_sigframe {
37 unsigned long tramp[2]; 35 unsigned long tramp[2];
38 struct siginfo info; 36 struct siginfo info;
@@ -149,11 +147,9 @@ sigsegv:
149/* 147/*
150 * Setup invocation of signal handler 148 * Setup invocation of signal handler
151 */ 149 */
152static int handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka, 150static void handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka,
153 sigset_t *oldset, struct pt_regs *regs) 151 struct pt_regs *regs)
154{ 152{
155 int rc;
156
157 /* 153 /*
158 * If we're handling a signal that aborted a system call, 154 * If we're handling a signal that aborted a system call,
159 * set up the error return value before adding the signal 155 * set up the error return value before adding the signal
@@ -186,15 +182,12 @@ static int handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka,
186 * Set up the stack frame; not doing the SA_SIGINFO thing. We 182 * Set up the stack frame; not doing the SA_SIGINFO thing. We
187 * only set up the rt_frame flavor. 183 * only set up the rt_frame flavor.
188 */ 184 */
189 rc = setup_rt_frame(sig, ka, info, oldset, regs);
190
191 /* If there was an error on setup, no signal was delivered. */ 185 /* If there was an error on setup, no signal was delivered. */
192 if (rc) 186 if (setup_rt_frame(sig, ka, info, sigmask_to_save(), regs) < 0)
193 return rc; 187 return;
194
195 block_sigmask(ka, sig);
196 188
197 return 0; 189 signal_delivered(sig, info, ka, regs,
190 test_thread_flag(TIF_SINGLESTEP));
198} 191}
199 192
200/* 193/*
@@ -209,34 +202,13 @@ static void do_signal(struct pt_regs *regs)
209 if (!user_mode(regs)) 202 if (!user_mode(regs))
210 return; 203 return;
211 204
212 if (try_to_freeze())
213 goto no_signal;
214
215 signo = get_signal_to_deliver(&info, &sigact, regs, NULL); 205 signo = get_signal_to_deliver(&info, &sigact, regs, NULL);
216 206
217 if (signo > 0) { 207 if (signo > 0) {
218 sigset_t *oldset; 208 handle_signal(signo, &info, &sigact, regs);
219
220 if (test_thread_flag(TIF_RESTORE_SIGMASK))
221 oldset = &current->saved_sigmask;
222 else
223 oldset = &current->blocked;
224
225 if (handle_signal(signo, &info, &sigact, oldset, regs) == 0) {
226 /*
227 * Successful delivery case. The saved sigmask is
228 * stored in the signal frame, and will be restored
229 * by sigreturn. We can clear the TIF flag.
230 */
231 clear_thread_flag(TIF_RESTORE_SIGMASK);
232
233 tracehook_signal_handler(signo, &info, &sigact, regs,
234 test_thread_flag(TIF_SINGLESTEP));
235 }
236 return; 209 return;
237 } 210 }
238 211
239no_signal:
240 /* 212 /*
241 * If we came from a system call, handle the restart. 213 * If we came from a system call, handle the restart.
242 */ 214 */
@@ -259,10 +231,7 @@ no_signal:
259 231
260no_restart: 232no_restart:
261 /* If there's no signal to deliver, put the saved sigmask back */ 233 /* If there's no signal to deliver, put the saved sigmask back */
262 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 234 restore_saved_sigmask();
263 clear_thread_flag(TIF_RESTORE_SIGMASK);
264 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
265 }
266} 235}
267 236
268void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags) 237void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
@@ -273,8 +242,6 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
273 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 242 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
274 clear_thread_flag(TIF_NOTIFY_RESUME); 243 clear_thread_flag(TIF_NOTIFY_RESUME);
275 tracehook_notify_resume(regs); 244 tracehook_notify_resume(regs);
276 if (current->replacement_session_keyring)
277 key_replace_session_keyring();
278 } 245 }
279} 246}
280 247
@@ -303,7 +270,6 @@ asmlinkage int sys_rt_sigreturn(void)
303 if (__copy_from_user(&blocked, &frame->uc.uc_sigmask, sizeof(blocked))) 270 if (__copy_from_user(&blocked, &frame->uc.uc_sigmask, sizeof(blocked)))
304 goto badframe; 271 goto badframe;
305 272
306 sigdelsetmask(&blocked, ~_BLOCKABLE);
307 set_current_blocked(&blocked); 273 set_current_blocked(&blocked);
308 274
309 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 275 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
diff --git a/arch/ia64/include/asm/posix_types.h b/arch/ia64/include/asm/posix_types.h
index 7323ab9467eb..99ee1d6510cf 100644
--- a/arch/ia64/include/asm/posix_types.h
+++ b/arch/ia64/include/asm/posix_types.h
@@ -1,9 +1,6 @@
1#ifndef _ASM_IA64_POSIX_TYPES_H 1#ifndef _ASM_IA64_POSIX_TYPES_H
2#define _ASM_IA64_POSIX_TYPES_H 2#define _ASM_IA64_POSIX_TYPES_H
3 3
4typedef unsigned int __kernel_nlink_t;
5#define __kernel_nlink_t __kernel_nlink_t
6
7typedef unsigned long __kernel_sigset_t; /* at least 32 bits */ 4typedef unsigned long __kernel_sigset_t; /* at least 32 bits */
8 5
9#include <asm-generic/posix_types.h> 6#include <asm-generic/posix_types.h>
diff --git a/arch/ia64/include/asm/thread_info.h b/arch/ia64/include/asm/thread_info.h
index 310d9734f02d..f7ee85378311 100644
--- a/arch/ia64/include/asm/thread_info.h
+++ b/arch/ia64/include/asm/thread_info.h
@@ -141,7 +141,23 @@ static inline void set_restore_sigmask(void)
141{ 141{
142 struct thread_info *ti = current_thread_info(); 142 struct thread_info *ti = current_thread_info();
143 ti->status |= TS_RESTORE_SIGMASK; 143 ti->status |= TS_RESTORE_SIGMASK;
144 set_bit(TIF_SIGPENDING, &ti->flags); 144 WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
145}
146static inline void clear_restore_sigmask(void)
147{
148 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
149}
150static inline bool test_restore_sigmask(void)
151{
152 return current_thread_info()->status & TS_RESTORE_SIGMASK;
153}
154static inline bool test_and_clear_restore_sigmask(void)
155{
156 struct thread_info *ti = current_thread_info();
157 if (!(ti->status & TS_RESTORE_SIGMASK))
158 return false;
159 ti->status &= ~TS_RESTORE_SIGMASK;
160 return true;
145} 161}
146#endif /* !__ASSEMBLY__ */ 162#endif /* !__ASSEMBLY__ */
147 163
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index f00ba025375d..d7f558c1e711 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -604,12 +604,6 @@ pfm_unprotect_ctx_ctxsw(pfm_context_t *x, unsigned long f)
604 spin_unlock(&(x)->ctx_lock); 604 spin_unlock(&(x)->ctx_lock);
605} 605}
606 606
607static inline unsigned long
608pfm_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags, unsigned long exec)
609{
610 return get_unmapped_area(file, addr, len, pgoff, flags);
611}
612
613/* forward declaration */ 607/* forward declaration */
614static const struct dentry_operations pfmfs_dentry_operations; 608static const struct dentry_operations pfmfs_dentry_operations;
615 609
@@ -2333,8 +2327,8 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t
2333 down_write(&task->mm->mmap_sem); 2327 down_write(&task->mm->mmap_sem);
2334 2328
2335 /* find some free area in address space, must have mmap sem held */ 2329 /* find some free area in address space, must have mmap sem held */
2336 vma->vm_start = pfm_get_unmapped_area(NULL, 0, size, 0, MAP_PRIVATE|MAP_ANONYMOUS, 0); 2330 vma->vm_start = get_unmapped_area(NULL, 0, size, 0, MAP_PRIVATE|MAP_ANONYMOUS);
2337 if (vma->vm_start == 0UL) { 2331 if (IS_ERR_VALUE(vma->vm_start)) {
2338 DPRINT(("Cannot find unmapped area for size %ld\n", size)); 2332 DPRINT(("Cannot find unmapped area for size %ld\n", size));
2339 up_write(&task->mm->mmap_sem); 2333 up_write(&task->mm->mmap_sem);
2340 goto error; 2334 goto error;
diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index 5e0e86ddb12f..dd6fc1449741 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -199,8 +199,6 @@ do_notify_resume_user(sigset_t *unused, struct sigscratch *scr, long in_syscall)
199 if (test_thread_flag(TIF_NOTIFY_RESUME)) { 199 if (test_thread_flag(TIF_NOTIFY_RESUME)) {
200 clear_thread_flag(TIF_NOTIFY_RESUME); 200 clear_thread_flag(TIF_NOTIFY_RESUME);
201 tracehook_notify_resume(&scr->pt); 201 tracehook_notify_resume(&scr->pt);
202 if (current->replacement_session_keyring)
203 key_replace_session_keyring();
204 } 202 }
205 203
206 /* copy user rbs to kernel rbs */ 204 /* copy user rbs to kernel rbs */
diff --git a/arch/ia64/kernel/signal.c b/arch/ia64/kernel/signal.c
index 7523501d3bc0..a199be1fe619 100644
--- a/arch/ia64/kernel/signal.c
+++ b/arch/ia64/kernel/signal.c
@@ -30,7 +30,6 @@
30 30
31#define DEBUG_SIG 0 31#define DEBUG_SIG 0
32#define STACK_ALIGN 16 /* minimal alignment for stack pointer */ 32#define STACK_ALIGN 16 /* minimal alignment for stack pointer */
33#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
34 33
35#if _NSIG_WORDS > 1 34#if _NSIG_WORDS > 1
36# define PUT_SIGSET(k,u) __copy_to_user((u)->sig, (k)->sig, sizeof(sigset_t)) 35# define PUT_SIGSET(k,u) __copy_to_user((u)->sig, (k)->sig, sizeof(sigset_t))
@@ -200,7 +199,6 @@ ia64_rt_sigreturn (struct sigscratch *scr)
200 if (GET_SIGSET(&set, &sc->sc_mask)) 199 if (GET_SIGSET(&set, &sc->sc_mask))
201 goto give_sigsegv; 200 goto give_sigsegv;
202 201
203 sigdelsetmask(&set, ~_BLOCKABLE);
204 set_current_blocked(&set); 202 set_current_blocked(&set);
205 203
206 if (restore_sigcontext(sc, scr)) 204 if (restore_sigcontext(sc, scr))
@@ -415,18 +413,13 @@ setup_frame (int sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *set,
415} 413}
416 414
417static long 415static long
418handle_signal (unsigned long sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *oldset, 416handle_signal (unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
419 struct sigscratch *scr) 417 struct sigscratch *scr)
420{ 418{
421 if (!setup_frame(sig, ka, info, oldset, scr)) 419 if (!setup_frame(sig, ka, info, sigmask_to_save(), scr))
422 return 0; 420 return 0;
423 421
424 block_sigmask(ka, sig); 422 signal_delivered(sig, info, ka, &scr->pt,
425
426 /*
427 * Let tracing know that we've done the handler setup.
428 */
429 tracehook_signal_handler(sig, info, ka, &scr->pt,
430 test_thread_flag(TIF_SINGLESTEP)); 423 test_thread_flag(TIF_SINGLESTEP));
431 424
432 return 1; 425 return 1;
@@ -440,7 +433,6 @@ void
440ia64_do_signal (struct sigscratch *scr, long in_syscall) 433ia64_do_signal (struct sigscratch *scr, long in_syscall)
441{ 434{
442 struct k_sigaction ka; 435 struct k_sigaction ka;
443 sigset_t *oldset;
444 siginfo_t info; 436 siginfo_t info;
445 long restart = in_syscall; 437 long restart = in_syscall;
446 long errno = scr->pt.r8; 438 long errno = scr->pt.r8;
@@ -453,11 +445,6 @@ ia64_do_signal (struct sigscratch *scr, long in_syscall)
453 if (!user_mode(&scr->pt)) 445 if (!user_mode(&scr->pt))
454 return; 446 return;
455 447
456 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
457 oldset = &current->saved_sigmask;
458 else
459 oldset = &current->blocked;
460
461 /* 448 /*
462 * This only loops in the rare cases of handle_signal() failing, in which case we 449 * This only loops in the rare cases of handle_signal() failing, in which case we
463 * need to push through a forced SIGSEGV. 450 * need to push through a forced SIGSEGV.
@@ -507,16 +494,8 @@ ia64_do_signal (struct sigscratch *scr, long in_syscall)
507 * Whee! Actually deliver the signal. If the delivery failed, we need to 494 * Whee! Actually deliver the signal. If the delivery failed, we need to
508 * continue to iterate in this loop so we can deliver the SIGSEGV... 495 * continue to iterate in this loop so we can deliver the SIGSEGV...
509 */ 496 */
510 if (handle_signal(signr, &ka, &info, oldset, scr)) { 497 if (handle_signal(signr, &ka, &info, scr))
511 /*
512 * A signal was successfully delivered; the saved
513 * sigmask will have been stored in the signal frame,
514 * and will be restored by sigreturn, so we can simply
515 * clear the TS_RESTORE_SIGMASK flag.
516 */
517 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
518 return; 498 return;
519 }
520 } 499 }
521 500
522 /* Did we come from a system call? */ 501 /* Did we come from a system call? */
@@ -538,8 +517,5 @@ ia64_do_signal (struct sigscratch *scr, long in_syscall)
538 517
539 /* if there's no signal to deliver, we just put the saved sigmask 518 /* if there's no signal to deliver, we just put the saved sigmask
540 * back */ 519 * back */
541 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 520 restore_saved_sigmask();
542 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
543 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
544 }
545} 521}
diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
index 609d50056a6c..d9439ef2f661 100644
--- a/arch/ia64/kernel/sys_ia64.c
+++ b/arch/ia64/kernel/sys_ia64.c
@@ -171,22 +171,9 @@ asmlinkage unsigned long
171ia64_mremap (unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flags, 171ia64_mremap (unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flags,
172 unsigned long new_addr) 172 unsigned long new_addr)
173{ 173{
174 extern unsigned long do_mremap (unsigned long addr, 174 addr = sys_mremap(addr, old_len, new_len, flags, new_addr);
175 unsigned long old_len, 175 if (!IS_ERR((void *) addr))
176 unsigned long new_len, 176 force_successful_syscall_return();
177 unsigned long flags,
178 unsigned long new_addr);
179
180 down_write(&current->mm->mmap_sem);
181 {
182 addr = do_mremap(addr, old_len, new_len, flags, new_addr);
183 }
184 up_write(&current->mm->mmap_sem);
185
186 if (IS_ERR((void *) addr))
187 return addr;
188
189 force_successful_syscall_return();
190 return addr; 177 return addr;
191} 178}
192 179
diff --git a/arch/m32r/include/asm/posix_types.h b/arch/m32r/include/asm/posix_types.h
index 0195850e1f88..236de26a409b 100644
--- a/arch/m32r/include/asm/posix_types.h
+++ b/arch/m32r/include/asm/posix_types.h
@@ -10,9 +10,6 @@
10typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t 11#define __kernel_mode_t __kernel_mode_t
12 12
13typedef unsigned short __kernel_nlink_t;
14#define __kernel_nlink_t __kernel_nlink_t
15
16typedef unsigned short __kernel_ipc_pid_t; 13typedef unsigned short __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t 14#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18 15
diff --git a/arch/m32r/kernel/signal.c b/arch/m32r/kernel/signal.c
index f54d96993ea1..f3fb2c029cfc 100644
--- a/arch/m32r/kernel/signal.c
+++ b/arch/m32r/kernel/signal.c
@@ -28,8 +28,6 @@
28 28
29#define DEBUG_SIG 0 29#define DEBUG_SIG 0
30 30
31#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
32
33asmlinkage int 31asmlinkage int
34sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, 32sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
35 unsigned long r2, unsigned long r3, unsigned long r4, 33 unsigned long r2, unsigned long r3, unsigned long r4,
@@ -111,7 +109,6 @@ sys_rt_sigreturn(unsigned long r0, unsigned long r1,
111 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 109 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
112 goto badframe; 110 goto badframe;
113 111
114 sigdelsetmask(&set, ~_BLOCKABLE);
115 set_current_blocked(&set); 112 set_current_blocked(&set);
116 113
117 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &result)) 114 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &result))
@@ -267,9 +264,9 @@ static int prev_insn(struct pt_regs *regs)
267 * OK, we're invoking a handler 264 * OK, we're invoking a handler
268 */ 265 */
269 266
270static int 267static void
271handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info, 268handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
272 sigset_t *oldset, struct pt_regs *regs) 269 struct pt_regs *regs)
273{ 270{
274 /* Are we from a system call? */ 271 /* Are we from a system call? */
275 if (regs->syscall_nr >= 0) { 272 if (regs->syscall_nr >= 0) {
@@ -294,11 +291,10 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
294 } 291 }
295 292
296 /* Set up the stack frame */ 293 /* Set up the stack frame */
297 if (setup_rt_frame(sig, ka, info, oldset, regs)) 294 if (setup_rt_frame(sig, ka, info, sigmask_to_save(), regs))
298 return -EFAULT; 295 return;
299 296
300 block_sigmask(ka, sig); 297 signal_delivered(sig, info, ka, regs, 0);
301 return 0;
302} 298}
303 299
304/* 300/*
@@ -311,7 +307,6 @@ static void do_signal(struct pt_regs *regs)
311 siginfo_t info; 307 siginfo_t info;
312 int signr; 308 int signr;
313 struct k_sigaction ka; 309 struct k_sigaction ka;
314 sigset_t *oldset;
315 310
316 /* 311 /*
317 * We want the common case to go fast, which 312 * We want the common case to go fast, which
@@ -322,14 +317,6 @@ static void do_signal(struct pt_regs *regs)
322 if (!user_mode(regs)) 317 if (!user_mode(regs))
323 return; 318 return;
324 319
325 if (try_to_freeze())
326 goto no_signal;
327
328 if (test_thread_flag(TIF_RESTORE_SIGMASK))
329 oldset = &current->saved_sigmask;
330 else
331 oldset = &current->blocked;
332
333 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 320 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
334 if (signr > 0) { 321 if (signr > 0) {
335 /* Re-enable any watchpoints before delivering the 322 /* Re-enable any watchpoints before delivering the
@@ -339,13 +326,11 @@ static void do_signal(struct pt_regs *regs)
339 */ 326 */
340 327
341 /* Whee! Actually deliver the signal. */ 328 /* Whee! Actually deliver the signal. */
342 if (handle_signal(signr, &ka, &info, oldset, regs) == 0) 329 handle_signal(signr, &ka, &info, regs);
343 clear_thread_flag(TIF_RESTORE_SIGMASK);
344 330
345 return; 331 return;
346 } 332 }
347 333
348 no_signal:
349 /* Did we come from a system call? */ 334 /* Did we come from a system call? */
350 if (regs->syscall_nr >= 0) { 335 if (regs->syscall_nr >= 0) {
351 /* Restart the system call - no handlers present */ 336 /* Restart the system call - no handlers present */
@@ -360,10 +345,7 @@ static void do_signal(struct pt_regs *regs)
360 prev_insn(regs); 345 prev_insn(regs);
361 } 346 }
362 } 347 }
363 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 348 restore_saved_sigmask();
364 clear_thread_flag(TIF_RESTORE_SIGMASK);
365 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
366 }
367} 349}
368 350
369/* 351/*
@@ -383,8 +365,6 @@ void do_notify_resume(struct pt_regs *regs, __u32 thread_info_flags)
383 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 365 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
384 clear_thread_flag(TIF_NOTIFY_RESUME); 366 clear_thread_flag(TIF_NOTIFY_RESUME);
385 tracehook_notify_resume(regs); 367 tracehook_notify_resume(regs);
386 if (current->replacement_session_keyring)
387 key_replace_session_keyring();
388 } 368 }
389 369
390 clear_thread_flag(TIF_IRET); 370 clear_thread_flag(TIF_IRET);
diff --git a/arch/m68k/include/asm/posix_types.h b/arch/m68k/include/asm/posix_types.h
index 6373093be72b..cf4dbf70fdc7 100644
--- a/arch/m68k/include/asm/posix_types.h
+++ b/arch/m68k/include/asm/posix_types.h
@@ -10,9 +10,6 @@
10typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t 11#define __kernel_mode_t __kernel_mode_t
12 12
13typedef unsigned short __kernel_nlink_t;
14#define __kernel_nlink_t __kernel_nlink_t
15
16typedef unsigned short __kernel_ipc_pid_t; 13typedef unsigned short __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t 14#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18 15
diff --git a/arch/m68k/kernel/signal.c b/arch/m68k/kernel/signal.c
index d9f3d1900eed..710a528b928b 100644
--- a/arch/m68k/kernel/signal.c
+++ b/arch/m68k/kernel/signal.c
@@ -51,8 +51,6 @@
51#include <asm/traps.h> 51#include <asm/traps.h>
52#include <asm/ucontext.h> 52#include <asm/ucontext.h>
53 53
54#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
55
56#ifdef CONFIG_MMU 54#ifdef CONFIG_MMU
57 55
58/* 56/*
@@ -795,7 +793,6 @@ asmlinkage int do_sigreturn(unsigned long __unused)
795 sizeof(frame->extramask)))) 793 sizeof(frame->extramask))))
796 goto badframe; 794 goto badframe;
797 795
798 sigdelsetmask(&set, ~_BLOCKABLE);
799 set_current_blocked(&set); 796 set_current_blocked(&set);
800 797
801 if (restore_sigcontext(regs, &frame->sc, frame + 1)) 798 if (restore_sigcontext(regs, &frame->sc, frame + 1))
@@ -820,7 +817,6 @@ asmlinkage int do_rt_sigreturn(unsigned long __unused)
820 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 817 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
821 goto badframe; 818 goto badframe;
822 819
823 sigdelsetmask(&set, ~_BLOCKABLE);
824 set_current_blocked(&set); 820 set_current_blocked(&set);
825 821
826 if (rt_restore_ucontext(regs, sw, &frame->uc)) 822 if (rt_restore_ucontext(regs, sw, &frame->uc))
@@ -1123,8 +1119,9 @@ handle_restart(struct pt_regs *regs, struct k_sigaction *ka, int has_handler)
1123 */ 1119 */
1124static void 1120static void
1125handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info, 1121handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
1126 sigset_t *oldset, struct pt_regs *regs) 1122 struct pt_regs *regs)
1127{ 1123{
1124 sigset_t *oldset = sigmask_to_save();
1128 int err; 1125 int err;
1129 /* are we from a system call? */ 1126 /* are we from a system call? */
1130 if (regs->orig_d0 >= 0) 1127 if (regs->orig_d0 >= 0)
@@ -1140,14 +1137,12 @@ handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
1140 if (err) 1137 if (err)
1141 return; 1138 return;
1142 1139
1143 block_sigmask(ka, sig); 1140 signal_delivered(sig, info, ka, regs, 0);
1144 1141
1145 if (test_thread_flag(TIF_DELAYED_TRACE)) { 1142 if (test_thread_flag(TIF_DELAYED_TRACE)) {
1146 regs->sr &= ~0x8000; 1143 regs->sr &= ~0x8000;
1147 send_sig(SIGTRAP, current, 1); 1144 send_sig(SIGTRAP, current, 1);
1148 } 1145 }
1149
1150 clear_thread_flag(TIF_RESTORE_SIGMASK);
1151} 1146}
1152 1147
1153/* 1148/*
@@ -1160,19 +1155,13 @@ static void do_signal(struct pt_regs *regs)
1160 siginfo_t info; 1155 siginfo_t info;
1161 struct k_sigaction ka; 1156 struct k_sigaction ka;
1162 int signr; 1157 int signr;
1163 sigset_t *oldset;
1164 1158
1165 current->thread.esp0 = (unsigned long) regs; 1159 current->thread.esp0 = (unsigned long) regs;
1166 1160
1167 if (test_thread_flag(TIF_RESTORE_SIGMASK))
1168 oldset = &current->saved_sigmask;
1169 else
1170 oldset = &current->blocked;
1171
1172 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 1161 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
1173 if (signr > 0) { 1162 if (signr > 0) {
1174 /* Whee! Actually deliver the signal. */ 1163 /* Whee! Actually deliver the signal. */
1175 handle_signal(signr, &ka, &info, oldset, regs); 1164 handle_signal(signr, &ka, &info, regs);
1176 return; 1165 return;
1177 } 1166 }
1178 1167
@@ -1182,10 +1171,7 @@ static void do_signal(struct pt_regs *regs)
1182 handle_restart(regs, NULL, 0); 1171 handle_restart(regs, NULL, 0);
1183 1172
1184 /* If there's no signal to deliver, we just restore the saved mask. */ 1173 /* If there's no signal to deliver, we just restore the saved mask. */
1185 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 1174 restore_saved_sigmask();
1186 clear_thread_flag(TIF_RESTORE_SIGMASK);
1187 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
1188 }
1189} 1175}
1190 1176
1191void do_notify_resume(struct pt_regs *regs) 1177void do_notify_resume(struct pt_regs *regs)
@@ -1193,9 +1179,6 @@ void do_notify_resume(struct pt_regs *regs)
1193 if (test_thread_flag(TIF_SIGPENDING)) 1179 if (test_thread_flag(TIF_SIGPENDING))
1194 do_signal(regs); 1180 do_signal(regs);
1195 1181
1196 if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME)) { 1182 if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
1197 tracehook_notify_resume(regs); 1183 tracehook_notify_resume(regs);
1198 if (current->replacement_session_keyring)
1199 key_replace_session_keyring();
1200 }
1201} 1184}
diff --git a/arch/microblaze/include/asm/thread_info.h b/arch/microblaze/include/asm/thread_info.h
index 1a8ab6a5c03f..6c610234ffab 100644
--- a/arch/microblaze/include/asm/thread_info.h
+++ b/arch/microblaze/include/asm/thread_info.h
@@ -166,7 +166,23 @@ static inline void set_restore_sigmask(void)
166{ 166{
167 struct thread_info *ti = current_thread_info(); 167 struct thread_info *ti = current_thread_info();
168 ti->status |= TS_RESTORE_SIGMASK; 168 ti->status |= TS_RESTORE_SIGMASK;
169 set_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags); 169 WARN_ON(!test_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags));
170}
171static inline void clear_restore_sigmask(void)
172{
173 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
174}
175static inline bool test_restore_sigmask(void)
176{
177 return current_thread_info()->status & TS_RESTORE_SIGMASK;
178}
179static inline bool test_and_clear_restore_sigmask(void)
180{
181 struct thread_info *ti = current_thread_info();
182 if (!(ti->status & TS_RESTORE_SIGMASK))
183 return false;
184 ti->status &= ~TS_RESTORE_SIGMASK;
185 return true;
170} 186}
171#endif 187#endif
172 188
diff --git a/arch/microblaze/kernel/signal.c b/arch/microblaze/kernel/signal.c
index 7f4c7bef1642..76b9722557db 100644
--- a/arch/microblaze/kernel/signal.c
+++ b/arch/microblaze/kernel/signal.c
@@ -41,8 +41,6 @@
41#include <asm/cacheflush.h> 41#include <asm/cacheflush.h>
42#include <asm/syscalls.h> 42#include <asm/syscalls.h>
43 43
44#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
45
46asmlinkage long 44asmlinkage long
47sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, 45sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
48 struct pt_regs *regs) 46 struct pt_regs *regs)
@@ -106,7 +104,6 @@ asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
106 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 104 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
107 goto badframe; 105 goto badframe;
108 106
109 sigdelsetmask(&set, ~_BLOCKABLE);
110 set_current_blocked(&set); 107 set_current_blocked(&set);
111 108
112 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &rval)) 109 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &rval))
@@ -310,10 +307,11 @@ do_restart:
310 * OK, we're invoking a handler 307 * OK, we're invoking a handler
311 */ 308 */
312 309
313static int 310static void
314handle_signal(unsigned long sig, struct k_sigaction *ka, 311handle_signal(unsigned long sig, struct k_sigaction *ka,
315 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) 312 siginfo_t *info, struct pt_regs *regs)
316{ 313{
314 sigset_t *oldset = sigmask_to_save();
317 int ret; 315 int ret;
318 316
319 /* Set up the stack frame */ 317 /* Set up the stack frame */
@@ -323,11 +321,9 @@ handle_signal(unsigned long sig, struct k_sigaction *ka,
323 ret = setup_rt_frame(sig, ka, NULL, oldset, regs); 321 ret = setup_rt_frame(sig, ka, NULL, oldset, regs);
324 322
325 if (ret) 323 if (ret)
326 return ret; 324 return;
327
328 block_sigmask(ka, sig);
329 325
330 return 0; 326 signal_delivered(sig, info, ka, regs, 0);
331} 327}
332 328
333/* 329/*
@@ -344,33 +340,18 @@ static void do_signal(struct pt_regs *regs, int in_syscall)
344 siginfo_t info; 340 siginfo_t info;
345 int signr; 341 int signr;
346 struct k_sigaction ka; 342 struct k_sigaction ka;
347 sigset_t *oldset;
348#ifdef DEBUG_SIG 343#ifdef DEBUG_SIG
349 printk(KERN_INFO "do signal: %p %d\n", regs, in_syscall); 344 printk(KERN_INFO "do signal: %p %d\n", regs, in_syscall);
350 printk(KERN_INFO "do signal2: %lx %lx %ld [%lx]\n", regs->pc, regs->r1, 345 printk(KERN_INFO "do signal2: %lx %lx %ld [%lx]\n", regs->pc, regs->r1,
351 regs->r12, current_thread_info()->flags); 346 regs->r12, current_thread_info()->flags);
352#endif 347#endif
353 348
354 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
355 oldset = &current->saved_sigmask;
356 else
357 oldset = &current->blocked;
358
359 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 349 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
360 if (signr > 0) { 350 if (signr > 0) {
361 /* Whee! Actually deliver the signal. */ 351 /* Whee! Actually deliver the signal. */
362 if (in_syscall) 352 if (in_syscall)
363 handle_restart(regs, &ka, 1); 353 handle_restart(regs, &ka, 1);
364 if (!handle_signal(signr, &ka, &info, oldset, regs)) { 354 handle_signal(signr, &ka, &info, regs);
365 /*
366 * A signal was successfully delivered; the saved
367 * sigmask will have been stored in the signal frame,
368 * and will be restored by sigreturn, so we can simply
369 * clear the TS_RESTORE_SIGMASK flag.
370 */
371 current_thread_info()->status &=
372 ~TS_RESTORE_SIGMASK;
373 }
374 return; 355 return;
375 } 356 }
376 357
@@ -381,10 +362,7 @@ static void do_signal(struct pt_regs *regs, int in_syscall)
381 * If there's no signal to deliver, we just put the saved sigmask 362 * If there's no signal to deliver, we just put the saved sigmask
382 * back. 363 * back.
383 */ 364 */
384 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 365 restore_saved_sigmask();
385 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
386 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
387 }
388} 366}
389 367
390void do_notify_resume(struct pt_regs *regs, int in_syscall) 368void do_notify_resume(struct pt_regs *regs, int in_syscall)
@@ -401,9 +379,6 @@ void do_notify_resume(struct pt_regs *regs, int in_syscall)
401 if (test_thread_flag(TIF_SIGPENDING)) 379 if (test_thread_flag(TIF_SIGPENDING))
402 do_signal(regs, in_syscall); 380 do_signal(regs, in_syscall);
403 381
404 if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME)) { 382 if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
405 tracehook_notify_resume(regs); 383 tracehook_notify_resume(regs);
406 if (current->replacement_session_keyring)
407 key_replace_session_keyring();
408 }
409} 384}
diff --git a/arch/mips/alchemy/devboards/db1200.c b/arch/mips/alchemy/devboards/db1200.c
index 7dde01642d6b..bf2248474fa8 100644
--- a/arch/mips/alchemy/devboards/db1200.c
+++ b/arch/mips/alchemy/devboards/db1200.c
@@ -213,8 +213,6 @@ static int au1200_nand_device_ready(struct mtd_info *mtd)
213 return __raw_readl((void __iomem *)MEM_STSTAT) & 1; 213 return __raw_readl((void __iomem *)MEM_STSTAT) & 1;
214} 214}
215 215
216static const char *db1200_part_probes[] = { "cmdlinepart", NULL };
217
218static struct mtd_partition db1200_nand_parts[] = { 216static struct mtd_partition db1200_nand_parts[] = {
219 { 217 {
220 .name = "NAND FS 0", 218 .name = "NAND FS 0",
@@ -235,7 +233,6 @@ struct platform_nand_data db1200_nand_platdata = {
235 .nr_partitions = ARRAY_SIZE(db1200_nand_parts), 233 .nr_partitions = ARRAY_SIZE(db1200_nand_parts),
236 .partitions = db1200_nand_parts, 234 .partitions = db1200_nand_parts,
237 .chip_delay = 20, 235 .chip_delay = 20,
238 .part_probe_types = db1200_part_probes,
239 }, 236 },
240 .ctrl = { 237 .ctrl = {
241 .dev_ready = au1200_nand_device_ready, 238 .dev_ready = au1200_nand_device_ready,
diff --git a/arch/mips/alchemy/devboards/db1300.c b/arch/mips/alchemy/devboards/db1300.c
index 0893f2af0d01..c56e0246694e 100644
--- a/arch/mips/alchemy/devboards/db1300.c
+++ b/arch/mips/alchemy/devboards/db1300.c
@@ -145,8 +145,6 @@ static int au1300_nand_device_ready(struct mtd_info *mtd)
145 return __raw_readl((void __iomem *)MEM_STSTAT) & 1; 145 return __raw_readl((void __iomem *)MEM_STSTAT) & 1;
146} 146}
147 147
148static const char *db1300_part_probes[] = { "cmdlinepart", NULL };
149
150static struct mtd_partition db1300_nand_parts[] = { 148static struct mtd_partition db1300_nand_parts[] = {
151 { 149 {
152 .name = "NAND FS 0", 150 .name = "NAND FS 0",
@@ -167,7 +165,6 @@ struct platform_nand_data db1300_nand_platdata = {
167 .nr_partitions = ARRAY_SIZE(db1300_nand_parts), 165 .nr_partitions = ARRAY_SIZE(db1300_nand_parts),
168 .partitions = db1300_nand_parts, 166 .partitions = db1300_nand_parts,
169 .chip_delay = 20, 167 .chip_delay = 20,
170 .part_probe_types = db1300_part_probes,
171 }, 168 },
172 .ctrl = { 169 .ctrl = {
173 .dev_ready = au1300_nand_device_ready, 170 .dev_ready = au1300_nand_device_ready,
diff --git a/arch/mips/alchemy/devboards/db1550.c b/arch/mips/alchemy/devboards/db1550.c
index 6815d0783cd8..9eb79062f46e 100644
--- a/arch/mips/alchemy/devboards/db1550.c
+++ b/arch/mips/alchemy/devboards/db1550.c
@@ -149,8 +149,6 @@ static int au1550_nand_device_ready(struct mtd_info *mtd)
149 return __raw_readl((void __iomem *)MEM_STSTAT) & 1; 149 return __raw_readl((void __iomem *)MEM_STSTAT) & 1;
150} 150}
151 151
152static const char *db1550_part_probes[] = { "cmdlinepart", NULL };
153
154static struct mtd_partition db1550_nand_parts[] = { 152static struct mtd_partition db1550_nand_parts[] = {
155 { 153 {
156 .name = "NAND FS 0", 154 .name = "NAND FS 0",
@@ -171,7 +169,6 @@ struct platform_nand_data db1550_nand_platdata = {
171 .nr_partitions = ARRAY_SIZE(db1550_nand_parts), 169 .nr_partitions = ARRAY_SIZE(db1550_nand_parts),
172 .partitions = db1550_nand_parts, 170 .partitions = db1550_nand_parts,
173 .chip_delay = 20, 171 .chip_delay = 20,
174 .part_probe_types = db1550_part_probes,
175 }, 172 },
176 .ctrl = { 173 .ctrl = {
177 .dev_ready = au1550_nand_device_ready, 174 .dev_ready = au1550_nand_device_ready,
diff --git a/arch/mips/include/asm/posix_types.h b/arch/mips/include/asm/posix_types.h
index e0308dcca135..fa03ec3fbf89 100644
--- a/arch/mips/include/asm/posix_types.h
+++ b/arch/mips/include/asm/posix_types.h
@@ -17,11 +17,6 @@
17 * assume GCC is being used. 17 * assume GCC is being used.
18 */ 18 */
19 19
20#if (_MIPS_SZLONG == 64)
21typedef unsigned int __kernel_nlink_t;
22#define __kernel_nlink_t __kernel_nlink_t
23#endif
24
25typedef long __kernel_daddr_t; 20typedef long __kernel_daddr_t;
26#define __kernel_daddr_t __kernel_daddr_t 21#define __kernel_daddr_t __kernel_daddr_t
27 22
diff --git a/arch/mips/include/asm/stat.h b/arch/mips/include/asm/stat.h
index 6e00f751ab6d..fe9a4c3ec5a1 100644
--- a/arch/mips/include/asm/stat.h
+++ b/arch/mips/include/asm/stat.h
@@ -20,7 +20,7 @@ struct stat {
20 long st_pad1[3]; /* Reserved for network id */ 20 long st_pad1[3]; /* Reserved for network id */
21 ino_t st_ino; 21 ino_t st_ino;
22 mode_t st_mode; 22 mode_t st_mode;
23 nlink_t st_nlink; 23 __u32 st_nlink;
24 uid_t st_uid; 24 uid_t st_uid;
25 gid_t st_gid; 25 gid_t st_gid;
26 unsigned st_rdev; 26 unsigned st_rdev;
@@ -55,7 +55,7 @@ struct stat64 {
55 unsigned long long st_ino; 55 unsigned long long st_ino;
56 56
57 mode_t st_mode; 57 mode_t st_mode;
58 nlink_t st_nlink; 58 __u32 st_nlink;
59 59
60 uid_t st_uid; 60 uid_t st_uid;
61 gid_t st_gid; 61 gid_t st_gid;
@@ -96,7 +96,7 @@ struct stat {
96 unsigned long st_ino; 96 unsigned long st_ino;
97 97
98 mode_t st_mode; 98 mode_t st_mode;
99 nlink_t st_nlink; 99 __u32 st_nlink;
100 100
101 uid_t st_uid; 101 uid_t st_uid;
102 gid_t st_gid; 102 gid_t st_gid;
diff --git a/arch/mips/kernel/signal-common.h b/arch/mips/kernel/signal-common.h
index 10263b405981..9c60d09e62a7 100644
--- a/arch/mips/kernel/signal-common.h
+++ b/arch/mips/kernel/signal-common.h
@@ -19,8 +19,6 @@
19# define DEBUGP(fmt, args...) 19# define DEBUGP(fmt, args...)
20#endif 20#endif
21 21
22#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
23
24/* 22/*
25 * Determine which stack to use.. 23 * Determine which stack to use..
26 */ 24 */
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 17f6ee30ad0d..f2c09cfc60ac 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -339,7 +339,6 @@ asmlinkage void sys_sigreturn(nabi_no_regargs struct pt_regs regs)
339 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked))) 339 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
340 goto badframe; 340 goto badframe;
341 341
342 sigdelsetmask(&blocked, ~_BLOCKABLE);
343 set_current_blocked(&blocked); 342 set_current_blocked(&blocked);
344 343
345 sig = restore_sigcontext(&regs, &frame->sf_sc); 344 sig = restore_sigcontext(&regs, &frame->sf_sc);
@@ -375,7 +374,6 @@ asmlinkage void sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
375 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set))) 374 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
376 goto badframe; 375 goto badframe;
377 376
378 sigdelsetmask(&set, ~_BLOCKABLE);
379 set_current_blocked(&set); 377 set_current_blocked(&set);
380 378
381 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext); 379 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext);
@@ -514,9 +512,10 @@ struct mips_abi mips_abi = {
514 .restart = __NR_restart_syscall 512 .restart = __NR_restart_syscall
515}; 513};
516 514
517static int handle_signal(unsigned long sig, siginfo_t *info, 515static void handle_signal(unsigned long sig, siginfo_t *info,
518 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs) 516 struct k_sigaction *ka, struct pt_regs *regs)
519{ 517{
518 sigset_t *oldset = sigmask_to_save();
520 int ret; 519 int ret;
521 struct mips_abi *abi = current->thread.abi; 520 struct mips_abi *abi = current->thread.abi;
522 void *vdso = current->mm->context.vdso; 521 void *vdso = current->mm->context.vdso;
@@ -550,17 +549,14 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
550 ka, regs, sig, oldset); 549 ka, regs, sig, oldset);
551 550
552 if (ret) 551 if (ret)
553 return ret; 552 return;
554
555 block_sigmask(ka, sig);
556 553
557 return ret; 554 signal_delivered(sig, info, ka, regs, 0);
558} 555}
559 556
560static void do_signal(struct pt_regs *regs) 557static void do_signal(struct pt_regs *regs)
561{ 558{
562 struct k_sigaction ka; 559 struct k_sigaction ka;
563 sigset_t *oldset;
564 siginfo_t info; 560 siginfo_t info;
565 int signr; 561 int signr;
566 562
@@ -572,25 +568,10 @@ static void do_signal(struct pt_regs *regs)
572 if (!user_mode(regs)) 568 if (!user_mode(regs))
573 return; 569 return;
574 570
575 if (test_thread_flag(TIF_RESTORE_SIGMASK))
576 oldset = &current->saved_sigmask;
577 else
578 oldset = &current->blocked;
579
580 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 571 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
581 if (signr > 0) { 572 if (signr > 0) {
582 /* Whee! Actually deliver the signal. */ 573 /* Whee! Actually deliver the signal. */
583 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 574 handle_signal(signr, &info, &ka, regs);
584 /*
585 * A signal was successfully delivered; the saved
586 * sigmask will have been stored in the signal frame,
587 * and will be restored by sigreturn, so we can simply
588 * clear the TIF_RESTORE_SIGMASK flag.
589 */
590 if (test_thread_flag(TIF_RESTORE_SIGMASK))
591 clear_thread_flag(TIF_RESTORE_SIGMASK);
592 }
593
594 return; 575 return;
595 } 576 }
596 577
@@ -614,10 +595,7 @@ static void do_signal(struct pt_regs *regs)
614 * If there's no signal to deliver, we just put the saved sigmask 595 * If there's no signal to deliver, we just put the saved sigmask
615 * back 596 * back
616 */ 597 */
617 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 598 restore_saved_sigmask();
618 clear_thread_flag(TIF_RESTORE_SIGMASK);
619 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
620 }
621} 599}
622 600
623/* 601/*
@@ -630,14 +608,12 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
630 local_irq_enable(); 608 local_irq_enable();
631 609
632 /* deal with pending signal delivery */ 610 /* deal with pending signal delivery */
633 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 611 if (thread_info_flags & _TIF_SIGPENDING)
634 do_signal(regs); 612 do_signal(regs);
635 613
636 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 614 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
637 clear_thread_flag(TIF_NOTIFY_RESUME); 615 clear_thread_flag(TIF_NOTIFY_RESUME);
638 tracehook_notify_resume(regs); 616 tracehook_notify_resume(regs);
639 if (current->replacement_session_keyring)
640 key_replace_session_keyring();
641 } 617 }
642} 618}
643 619
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index b4fe2eacbd5d..da1b56a39ac7 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -465,7 +465,6 @@ asmlinkage void sys32_sigreturn(nabi_no_regargs struct pt_regs regs)
465 if (__copy_conv_sigset_from_user(&blocked, &frame->sf_mask)) 465 if (__copy_conv_sigset_from_user(&blocked, &frame->sf_mask))
466 goto badframe; 466 goto badframe;
467 467
468 sigdelsetmask(&blocked, ~_BLOCKABLE);
469 set_current_blocked(&blocked); 468 set_current_blocked(&blocked);
470 469
471 sig = restore_sigcontext32(&regs, &frame->sf_sc); 470 sig = restore_sigcontext32(&regs, &frame->sf_sc);
@@ -503,7 +502,6 @@ asmlinkage void sys32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
503 if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask)) 502 if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask))
504 goto badframe; 503 goto badframe;
505 504
506 sigdelsetmask(&set, ~_BLOCKABLE);
507 set_current_blocked(&set); 505 set_current_blocked(&set);
508 506
509 sig = restore_sigcontext32(&regs, &frame->rs_uc.uc_mcontext); 507 sig = restore_sigcontext32(&regs, &frame->rs_uc.uc_mcontext);
diff --git a/arch/mips/kernel/signal_n32.c b/arch/mips/kernel/signal_n32.c
index 63ffac9af7c5..3574c145511b 100644
--- a/arch/mips/kernel/signal_n32.c
+++ b/arch/mips/kernel/signal_n32.c
@@ -109,7 +109,6 @@ asmlinkage void sysn32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
109 if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask)) 109 if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask))
110 goto badframe; 110 goto badframe;
111 111
112 sigdelsetmask(&set, ~_BLOCKABLE);
113 set_current_blocked(&set); 112 set_current_blocked(&set);
114 113
115 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext); 114 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext);
diff --git a/arch/mips/pnx833x/common/platform.c b/arch/mips/pnx833x/common/platform.c
index 87167dcc79fa..05a1d922cd60 100644
--- a/arch/mips/pnx833x/common/platform.c
+++ b/arch/mips/pnx833x/common/platform.c
@@ -244,11 +244,6 @@ static struct platform_device pnx833x_sata_device = {
244 .resource = pnx833x_sata_resources, 244 .resource = pnx833x_sata_resources,
245}; 245};
246 246
247static const char *part_probes[] = {
248 "cmdlinepart",
249 NULL
250};
251
252static void 247static void
253pnx833x_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 248pnx833x_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
254{ 249{
@@ -268,7 +263,6 @@ static struct platform_nand_data pnx833x_flash_nand_data = {
268 .chip = { 263 .chip = {
269 .nr_chips = 1, 264 .nr_chips = 1,
270 .chip_delay = 25, 265 .chip_delay = 25,
271 .part_probe_types = part_probes,
272 }, 266 },
273 .ctrl = { 267 .ctrl = {
274 .cmd_ctrl = pnx833x_flash_nand_cmd_ctrl 268 .cmd_ctrl = pnx833x_flash_nand_cmd_ctrl
diff --git a/arch/mips/rb532/devices.c b/arch/mips/rb532/devices.c
index ea774285e6c5..716e9a12f0e7 100644
--- a/arch/mips/rb532/devices.c
+++ b/arch/mips/rb532/devices.c
@@ -293,7 +293,6 @@ static void __init rb532_nand_setup(void)
293 rb532_nand_data.chip.nr_partitions = ARRAY_SIZE(rb532_partition_info); 293 rb532_nand_data.chip.nr_partitions = ARRAY_SIZE(rb532_partition_info);
294 rb532_nand_data.chip.partitions = rb532_partition_info; 294 rb532_nand_data.chip.partitions = rb532_partition_info;
295 rb532_nand_data.chip.chip_delay = NAND_CHIP_DELAY; 295 rb532_nand_data.chip.chip_delay = NAND_CHIP_DELAY;
296 rb532_nand_data.chip.options = NAND_NO_AUTOINCR;
297} 296}
298 297
299 298
diff --git a/arch/mn10300/include/asm/posix_types.h b/arch/mn10300/include/asm/posix_types.h
index ab506181ec31..d31eeea480cf 100644
--- a/arch/mn10300/include/asm/posix_types.h
+++ b/arch/mn10300/include/asm/posix_types.h
@@ -20,9 +20,6 @@
20typedef unsigned short __kernel_mode_t; 20typedef unsigned short __kernel_mode_t;
21#define __kernel_mode_t __kernel_mode_t 21#define __kernel_mode_t __kernel_mode_t
22 22
23typedef unsigned short __kernel_nlink_t;
24#define __kernel_nlink_t __kernel_nlink_t
25
26typedef unsigned short __kernel_ipc_pid_t; 23typedef unsigned short __kernel_ipc_pid_t;
27#define __kernel_ipc_pid_t __kernel_ipc_pid_t 24#define __kernel_ipc_pid_t __kernel_ipc_pid_t
28 25
diff --git a/arch/mn10300/kernel/signal.c b/arch/mn10300/kernel/signal.c
index 890cf91767cc..6ab0bee2a54f 100644
--- a/arch/mn10300/kernel/signal.c
+++ b/arch/mn10300/kernel/signal.c
@@ -31,8 +31,6 @@
31 31
32#define DEBUG_SIG 0 32#define DEBUG_SIG 0
33 33
34#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
35
36/* 34/*
37 * atomically swap in the new signal mask, and wait for a signal. 35 * atomically swap in the new signal mask, and wait for a signal.
38 */ 36 */
@@ -163,7 +161,6 @@ asmlinkage long sys_sigreturn(void)
163 sizeof(frame->extramask))) 161 sizeof(frame->extramask)))
164 goto badframe; 162 goto badframe;
165 163
166 sigdelsetmask(&set, ~_BLOCKABLE);
167 set_current_blocked(&set); 164 set_current_blocked(&set);
168 165
169 if (restore_sigcontext(current_frame(), &frame->sc, &d0)) 166 if (restore_sigcontext(current_frame(), &frame->sc, &d0))
@@ -191,7 +188,6 @@ asmlinkage long sys_rt_sigreturn(void)
191 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 188 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
192 goto badframe; 189 goto badframe;
193 190
194 sigdelsetmask(&set, ~_BLOCKABLE);
195 set_current_blocked(&set); 191 set_current_blocked(&set);
196 192
197 if (restore_sigcontext(current_frame(), &frame->uc.uc_mcontext, &d0)) 193 if (restore_sigcontext(current_frame(), &frame->uc.uc_mcontext, &d0))
@@ -430,8 +426,9 @@ static inline void stepback(struct pt_regs *regs)
430 */ 426 */
431static int handle_signal(int sig, 427static int handle_signal(int sig,
432 siginfo_t *info, struct k_sigaction *ka, 428 siginfo_t *info, struct k_sigaction *ka,
433 sigset_t *oldset, struct pt_regs *regs) 429 struct pt_regs *regs)
434{ 430{
431 sigset_t *oldset = sigmask_to_save();
435 int ret; 432 int ret;
436 433
437 /* Are we from a system call? */ 434 /* Are we from a system call? */
@@ -461,11 +458,11 @@ static int handle_signal(int sig,
461 ret = setup_rt_frame(sig, ka, info, oldset, regs); 458 ret = setup_rt_frame(sig, ka, info, oldset, regs);
462 else 459 else
463 ret = setup_frame(sig, ka, oldset, regs); 460 ret = setup_frame(sig, ka, oldset, regs);
461 if (ret)
462 return;
464 463
465 if (ret == 0) 464 signal_delivered(sig, info, ka, regs,
466 block_sigmask(ka, sig); 465 test_thread_flag(TIF_SINGLESTEP));
467
468 return ret;
469} 466}
470 467
471/* 468/*
@@ -475,7 +472,6 @@ static void do_signal(struct pt_regs *regs)
475{ 472{
476 struct k_sigaction ka; 473 struct k_sigaction ka;
477 siginfo_t info; 474 siginfo_t info;
478 sigset_t *oldset;
479 int signr; 475 int signr;
480 476
481 /* we want the common case to go fast, which is why we may in certain 477 /* we want the common case to go fast, which is why we may in certain
@@ -483,23 +479,9 @@ static void do_signal(struct pt_regs *regs)
483 if (!user_mode(regs)) 479 if (!user_mode(regs))
484 return; 480 return;
485 481
486 if (test_thread_flag(TIF_RESTORE_SIGMASK))
487 oldset = &current->saved_sigmask;
488 else
489 oldset = &current->blocked;
490
491 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 482 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
492 if (signr > 0) { 483 if (signr > 0) {
493 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 484 if (handle_signal(signr, &info, &ka, regs) == 0) {
494 /* a signal was successfully delivered; the saved
495 * sigmask will have been stored in the signal frame,
496 * and will be restored by sigreturn, so we can simply
497 * clear the TIF_RESTORE_SIGMASK flag */
498 if (test_thread_flag(TIF_RESTORE_SIGMASK))
499 clear_thread_flag(TIF_RESTORE_SIGMASK);
500
501 tracehook_signal_handler(signr, &info, &ka, regs,
502 test_thread_flag(TIF_SINGLESTEP));
503 } 485 }
504 486
505 return; 487 return;
@@ -525,10 +507,7 @@ static void do_signal(struct pt_regs *regs)
525 507
526 /* if there's no signal to deliver, we just put the saved sigmask 508 /* if there's no signal to deliver, we just put the saved sigmask
527 * back */ 509 * back */
528 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 510 restore_saved_sigmask();
529 clear_thread_flag(TIF_RESTORE_SIGMASK);
530 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
531 }
532} 511}
533 512
534/* 513/*
@@ -548,13 +527,11 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags)
548 } 527 }
549 528
550 /* deal with pending signal delivery */ 529 /* deal with pending signal delivery */
551 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 530 if (thread_info_flags & _TIF_SIGPENDING)
552 do_signal(regs); 531 do_signal(regs);
553 532
554 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 533 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
555 clear_thread_flag(TIF_NOTIFY_RESUME); 534 clear_thread_flag(TIF_NOTIFY_RESUME);
556 tracehook_notify_resume(current_frame()); 535 tracehook_notify_resume(current_frame());
557 if (current->replacement_session_keyring)
558 key_replace_session_keyring();
559 } 536 }
560} 537}
diff --git a/arch/openrisc/kernel/signal.c b/arch/openrisc/kernel/signal.c
index e970743251ae..30110297f4f9 100644
--- a/arch/openrisc/kernel/signal.c
+++ b/arch/openrisc/kernel/signal.c
@@ -33,8 +33,6 @@
33 33
34#define DEBUG_SIG 0 34#define DEBUG_SIG 0
35 35
36#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
37
38asmlinkage long 36asmlinkage long
39_sys_sigaltstack(const stack_t *uss, stack_t *uoss, struct pt_regs *regs) 37_sys_sigaltstack(const stack_t *uss, stack_t *uoss, struct pt_regs *regs)
40{ 38{
@@ -101,7 +99,6 @@ asmlinkage long _sys_rt_sigreturn(struct pt_regs *regs)
101 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 99 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
102 goto badframe; 100 goto badframe;
103 101
104 sigdelsetmask(&set, ~_BLOCKABLE);
105 set_current_blocked(&set); 102 set_current_blocked(&set);
106 103
107 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 104 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -251,20 +248,19 @@ give_sigsegv:
251 return -EFAULT; 248 return -EFAULT;
252} 249}
253 250
254static inline int 251static inline void
255handle_signal(unsigned long sig, 252handle_signal(unsigned long sig,
256 siginfo_t *info, struct k_sigaction *ka, 253 siginfo_t *info, struct k_sigaction *ka,
257 sigset_t *oldset, struct pt_regs *regs) 254 struct pt_regs *regs)
258{ 255{
259 int ret; 256 int ret;
260 257
261 ret = setup_rt_frame(sig, ka, info, oldset, regs); 258 ret = setup_rt_frame(sig, ka, info, sigmask_to_save(), regs);
262 if (ret) 259 if (ret)
263 return ret; 260 return;
264
265 block_sigmask(ka, sig);
266 261
267 return 0; 262 signal_delivered(sig, info, ka, regs,
263 test_thread_flag(TIF_SINGLESTEP));
268} 264}
269 265
270/* 266/*
@@ -339,30 +335,10 @@ void do_signal(struct pt_regs *regs)
339 if (signr <= 0) { 335 if (signr <= 0) {
340 /* no signal to deliver so we just put the saved sigmask 336 /* no signal to deliver so we just put the saved sigmask
341 * back */ 337 * back */
342 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 338 restore_saved_sigmask();
343 clear_thread_flag(TIF_RESTORE_SIGMASK);
344 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
345 }
346
347 } else { /* signr > 0 */ 339 } else { /* signr > 0 */
348 sigset_t *oldset;
349
350 if (current_thread_info()->flags & _TIF_RESTORE_SIGMASK)
351 oldset = &current->saved_sigmask;
352 else
353 oldset = &current->blocked;
354
355 /* Whee! Actually deliver the signal. */ 340 /* Whee! Actually deliver the signal. */
356 if (!handle_signal(signr, &info, &ka, oldset, regs)) { 341 handle_signal(signr, &info, &ka, regs);
357 /* a signal was successfully delivered; the saved
358 * sigmask will have been stored in the signal frame,
359 * and will be restored by sigreturn, so we can simply
360 * clear the TIF_RESTORE_SIGMASK flag */
361 clear_thread_flag(TIF_RESTORE_SIGMASK);
362 }
363
364 tracehook_signal_handler(signr, &info, &ka, regs,
365 test_thread_flag(TIF_SINGLESTEP));
366 } 342 }
367 343
368 return; 344 return;
@@ -376,7 +352,5 @@ asmlinkage void do_notify_resume(struct pt_regs *regs)
376 if (current_thread_info()->flags & _TIF_NOTIFY_RESUME) { 352 if (current_thread_info()->flags & _TIF_NOTIFY_RESUME) {
377 clear_thread_flag(TIF_NOTIFY_RESUME); 353 clear_thread_flag(TIF_NOTIFY_RESUME);
378 tracehook_notify_resume(regs); 354 tracehook_notify_resume(regs);
379 if (current->replacement_session_keyring)
380 key_replace_session_keyring();
381 } 355 }
382} 356}
diff --git a/arch/parisc/include/asm/posix_types.h b/arch/parisc/include/asm/posix_types.h
index 5212b0357daf..b9344256f76b 100644
--- a/arch/parisc/include/asm/posix_types.h
+++ b/arch/parisc/include/asm/posix_types.h
@@ -10,9 +10,6 @@
10typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t 11#define __kernel_mode_t __kernel_mode_t
12 12
13typedef unsigned short __kernel_nlink_t;
14#define __kernel_nlink_t __kernel_nlink_t
15
16typedef unsigned short __kernel_ipc_pid_t; 13typedef unsigned short __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t 14#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18 15
diff --git a/arch/parisc/include/asm/stat.h b/arch/parisc/include/asm/stat.h
index 9d5fbbc5c31f..d76fbda5d62c 100644
--- a/arch/parisc/include/asm/stat.h
+++ b/arch/parisc/include/asm/stat.h
@@ -7,7 +7,7 @@ struct stat {
7 unsigned int st_dev; /* dev_t is 32 bits on parisc */ 7 unsigned int st_dev; /* dev_t is 32 bits on parisc */
8 ino_t st_ino; /* 32 bits */ 8 ino_t st_ino; /* 32 bits */
9 mode_t st_mode; /* 16 bits */ 9 mode_t st_mode; /* 16 bits */
10 nlink_t st_nlink; /* 16 bits */ 10 unsigned short st_nlink; /* 16 bits */
11 unsigned short st_reserved1; /* old st_uid */ 11 unsigned short st_reserved1; /* old st_uid */
12 unsigned short st_reserved2; /* old st_gid */ 12 unsigned short st_reserved2; /* old st_gid */
13 unsigned int st_rdev; 13 unsigned int st_rdev;
@@ -42,7 +42,7 @@ struct hpux_stat64 {
42 unsigned int st_dev; /* dev_t is 32 bits on parisc */ 42 unsigned int st_dev; /* dev_t is 32 bits on parisc */
43 ino_t st_ino; /* 32 bits */ 43 ino_t st_ino; /* 32 bits */
44 mode_t st_mode; /* 16 bits */ 44 mode_t st_mode; /* 16 bits */
45 nlink_t st_nlink; /* 16 bits */ 45 unsigned short st_nlink; /* 16 bits */
46 unsigned short st_reserved1; /* old st_uid */ 46 unsigned short st_reserved1; /* old st_uid */
47 unsigned short st_reserved2; /* old st_gid */ 47 unsigned short st_reserved2; /* old st_gid */
48 unsigned int st_rdev; 48 unsigned int st_rdev;
diff --git a/arch/parisc/include/asm/thread_info.h b/arch/parisc/include/asm/thread_info.h
index 83ae7dd4d99e..22b4726dee49 100644
--- a/arch/parisc/include/asm/thread_info.h
+++ b/arch/parisc/include/asm/thread_info.h
@@ -74,7 +74,7 @@ struct thread_info {
74#define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP) 74#define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP)
75 75
76#define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | \ 76#define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | \
77 _TIF_NEED_RESCHED | _TIF_RESTORE_SIGMASK) 77 _TIF_NEED_RESCHED)
78 78
79#endif /* __KERNEL__ */ 79#endif /* __KERNEL__ */
80 80
diff --git a/arch/parisc/kernel/entry.S b/arch/parisc/kernel/entry.S
index 07ef351edd57..18670a078849 100644
--- a/arch/parisc/kernel/entry.S
+++ b/arch/parisc/kernel/entry.S
@@ -924,7 +924,7 @@ intr_check_sig:
924 /* As above */ 924 /* As above */
925 mfctl %cr30,%r1 925 mfctl %cr30,%r1
926 LDREG TI_FLAGS(%r1),%r19 926 LDREG TI_FLAGS(%r1),%r19
927 ldi (_TIF_SIGPENDING|_TIF_RESTORE_SIGMASK|_TIF_NOTIFY_RESUME), %r20 927 ldi (_TIF_SIGPENDING|_TIF_NOTIFY_RESUME), %r20
928 and,COND(<>) %r19, %r20, %r0 928 and,COND(<>) %r19, %r20, %r0
929 b,n intr_restore /* skip past if we've nothing to do */ 929 b,n intr_restore /* skip past if we've nothing to do */
930 930
@@ -2032,7 +2032,7 @@ syscall_check_resched:
2032 .import do_signal,code 2032 .import do_signal,code
2033syscall_check_sig: 2033syscall_check_sig:
2034 LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19 2034 LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19
2035 ldi (_TIF_SIGPENDING|_TIF_RESTORE_SIGMASK), %r26 2035 ldi (_TIF_SIGPENDING|_TIF_NOTIFY_RESUME), %r26
2036 and,COND(<>) %r19, %r26, %r0 2036 and,COND(<>) %r19, %r26, %r0
2037 b,n syscall_restore /* skip past if we've nothing to do */ 2037 b,n syscall_restore /* skip past if we've nothing to do */
2038 2038
diff --git a/arch/parisc/kernel/signal.c b/arch/parisc/kernel/signal.c
index 4b9cb0d546d1..594459bde14e 100644
--- a/arch/parisc/kernel/signal.c
+++ b/arch/parisc/kernel/signal.c
@@ -48,9 +48,6 @@
48#define DBG(LEVEL, ...) 48#define DBG(LEVEL, ...)
49#endif 49#endif
50 50
51
52#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
53
54/* gcc will complain if a pointer is cast to an integer of different 51/* gcc will complain if a pointer is cast to an integer of different
55 * size. If you really need to do this (and we do for an ELF32 user 52 * size. If you really need to do this (and we do for an ELF32 user
56 * application in an ELF64 kernel) then you have to do a cast to an 53 * application in an ELF64 kernel) then you have to do a cast to an
@@ -131,7 +128,6 @@ sys_rt_sigreturn(struct pt_regs *regs, int in_syscall)
131 goto give_sigsegv; 128 goto give_sigsegv;
132 } 129 }
133 130
134 sigdelsetmask(&set, ~_BLOCKABLE);
135 set_current_blocked(&set); 131 set_current_blocked(&set);
136 132
137 /* Good thing we saved the old gr[30], eh? */ 133 /* Good thing we saved the old gr[30], eh? */
@@ -443,8 +439,9 @@ give_sigsegv:
443 439
444static long 440static long
445handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, 441handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
446 sigset_t *oldset, struct pt_regs *regs, int in_syscall) 442 struct pt_regs *regs, int in_syscall)
447{ 443{
444 sigset_t *oldset = sigmask_to_save();
448 DBG(1,"handle_signal: sig=%ld, ka=%p, info=%p, oldset=%p, regs=%p\n", 445 DBG(1,"handle_signal: sig=%ld, ka=%p, info=%p, oldset=%p, regs=%p\n",
449 sig, ka, info, oldset, regs); 446 sig, ka, info, oldset, regs);
450 447
@@ -452,12 +449,13 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
452 if (!setup_rt_frame(sig, ka, info, oldset, regs, in_syscall)) 449 if (!setup_rt_frame(sig, ka, info, oldset, regs, in_syscall))
453 return 0; 450 return 0;
454 451
455 block_sigmask(ka, sig); 452 signal_delivered(sig, info, ka, regs,
456
457 tracehook_signal_handler(sig, info, ka, regs,
458 test_thread_flag(TIF_SINGLESTEP) || 453 test_thread_flag(TIF_SINGLESTEP) ||
459 test_thread_flag(TIF_BLOCKSTEP)); 454 test_thread_flag(TIF_BLOCKSTEP));
460 455
456 DBG(1,KERN_DEBUG "do_signal: Exit (success), regs->gr[28] = %ld\n",
457 regs->gr[28]);
458
461 return 1; 459 return 1;
462} 460}
463 461
@@ -568,28 +566,17 @@ do_signal(struct pt_regs *regs, long in_syscall)
568 siginfo_t info; 566 siginfo_t info;
569 struct k_sigaction ka; 567 struct k_sigaction ka;
570 int signr; 568 int signr;
571 sigset_t *oldset;
572 569
573 DBG(1,"\ndo_signal: oldset=0x%p, regs=0x%p, sr7 %#lx, in_syscall=%d\n", 570 DBG(1,"\ndo_signal: regs=0x%p, sr7 %#lx, in_syscall=%d\n",
574 oldset, regs, regs->sr[7], in_syscall); 571 regs, regs->sr[7], in_syscall);
575 572
576 /* Everyone else checks to see if they are in kernel mode at 573 /* Everyone else checks to see if they are in kernel mode at
577 this point and exits if that's the case. I'm not sure why 574 this point and exits if that's the case. I'm not sure why
578 we would be called in that case, but for some reason we 575 we would be called in that case, but for some reason we
579 are. */ 576 are. */
580 577
581 if (test_thread_flag(TIF_RESTORE_SIGMASK))
582 oldset = &current->saved_sigmask;
583 else
584 oldset = &current->blocked;
585
586 DBG(1,"do_signal: oldset %08lx / %08lx\n",
587 oldset->sig[0], oldset->sig[1]);
588
589
590 /* May need to force signal if handle_signal failed to deliver */ 578 /* May need to force signal if handle_signal failed to deliver */
591 while (1) { 579 while (1) {
592
593 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 580 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
594 DBG(3,"do_signal: signr = %d, regs->gr[28] = %ld\n", signr, regs->gr[28]); 581 DBG(3,"do_signal: signr = %d, regs->gr[28] = %ld\n", signr, regs->gr[28]);
595 582
@@ -603,14 +590,8 @@ do_signal(struct pt_regs *regs, long in_syscall)
603 /* Whee! Actually deliver the signal. If the 590 /* Whee! Actually deliver the signal. If the
604 delivery failed, we need to continue to iterate in 591 delivery failed, we need to continue to iterate in
605 this loop so we can deliver the SIGSEGV... */ 592 this loop so we can deliver the SIGSEGV... */
606 if (handle_signal(signr, &info, &ka, oldset, 593 if (handle_signal(signr, &info, &ka, regs, in_syscall))
607 regs, in_syscall)) {
608 DBG(1,KERN_DEBUG "do_signal: Exit (success), regs->gr[28] = %ld\n",
609 regs->gr[28]);
610 if (test_thread_flag(TIF_RESTORE_SIGMASK))
611 clear_thread_flag(TIF_RESTORE_SIGMASK);
612 return; 594 return;
613 }
614 } 595 }
615 /* end of while(1) looping forever if we can't force a signal */ 596 /* end of while(1) looping forever if we can't force a signal */
616 597
@@ -621,24 +602,16 @@ do_signal(struct pt_regs *regs, long in_syscall)
621 DBG(1,"do_signal: Exit (not delivered), regs->gr[28] = %ld\n", 602 DBG(1,"do_signal: Exit (not delivered), regs->gr[28] = %ld\n",
622 regs->gr[28]); 603 regs->gr[28]);
623 604
624 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 605 restore_saved_sigmask();
625 clear_thread_flag(TIF_RESTORE_SIGMASK);
626 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
627 }
628
629 return;
630} 606}
631 607
632void do_notify_resume(struct pt_regs *regs, long in_syscall) 608void do_notify_resume(struct pt_regs *regs, long in_syscall)
633{ 609{
634 if (test_thread_flag(TIF_SIGPENDING) || 610 if (test_thread_flag(TIF_SIGPENDING))
635 test_thread_flag(TIF_RESTORE_SIGMASK))
636 do_signal(regs, in_syscall); 611 do_signal(regs, in_syscall);
637 612
638 if (test_thread_flag(TIF_NOTIFY_RESUME)) { 613 if (test_thread_flag(TIF_NOTIFY_RESUME)) {
639 clear_thread_flag(TIF_NOTIFY_RESUME); 614 clear_thread_flag(TIF_NOTIFY_RESUME);
640 tracehook_notify_resume(regs); 615 tracehook_notify_resume(regs);
641 if (current->replacement_session_keyring)
642 key_replace_session_keyring();
643 } 616 }
644} 617}
diff --git a/arch/parisc/kernel/signal32.c b/arch/parisc/kernel/signal32.c
index e14132430762..fd49aeda9eb8 100644
--- a/arch/parisc/kernel/signal32.c
+++ b/arch/parisc/kernel/signal32.c
@@ -47,8 +47,6 @@
47#define DBG(LEVEL, ...) 47#define DBG(LEVEL, ...)
48#endif 48#endif
49 49
50#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
51
52inline void 50inline void
53sigset_32to64(sigset_t *s64, compat_sigset_t *s32) 51sigset_32to64(sigset_t *s64, compat_sigset_t *s32)
54{ 52{
diff --git a/arch/powerpc/include/asm/posix_types.h b/arch/powerpc/include/asm/posix_types.h
index f1393252bbda..2958c5b97b2d 100644
--- a/arch/powerpc/include/asm/posix_types.h
+++ b/arch/powerpc/include/asm/posix_types.h
@@ -16,9 +16,6 @@ typedef int __kernel_ssize_t;
16typedef long __kernel_ptrdiff_t; 16typedef long __kernel_ptrdiff_t;
17#define __kernel_size_t __kernel_size_t 17#define __kernel_size_t __kernel_size_t
18 18
19typedef unsigned short __kernel_nlink_t;
20#define __kernel_nlink_t __kernel_nlink_t
21
22typedef short __kernel_ipc_pid_t; 19typedef short __kernel_ipc_pid_t;
23#define __kernel_ipc_pid_t __kernel_ipc_pid_t 20#define __kernel_ipc_pid_t __kernel_ipc_pid_t
24#endif 21#endif
diff --git a/arch/powerpc/include/asm/stat.h b/arch/powerpc/include/asm/stat.h
index e4edc510b530..84880b80cc1c 100644
--- a/arch/powerpc/include/asm/stat.h
+++ b/arch/powerpc/include/asm/stat.h
@@ -30,11 +30,11 @@ struct stat {
30 unsigned long st_dev; 30 unsigned long st_dev;
31 ino_t st_ino; 31 ino_t st_ino;
32#ifdef __powerpc64__ 32#ifdef __powerpc64__
33 nlink_t st_nlink; 33 unsigned long st_nlink;
34 mode_t st_mode; 34 mode_t st_mode;
35#else 35#else
36 mode_t st_mode; 36 mode_t st_mode;
37 nlink_t st_nlink; 37 unsigned short st_nlink;
38#endif 38#endif
39 uid_t st_uid; 39 uid_t st_uid;
40 gid_t st_gid; 40 gid_t st_gid;
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index a556ccc16b58..68831e9cf82f 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -140,7 +140,23 @@ static inline void set_restore_sigmask(void)
140{ 140{
141 struct thread_info *ti = current_thread_info(); 141 struct thread_info *ti = current_thread_info();
142 ti->local_flags |= _TLF_RESTORE_SIGMASK; 142 ti->local_flags |= _TLF_RESTORE_SIGMASK;
143 set_bit(TIF_SIGPENDING, &ti->flags); 143 WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
144}
145static inline void clear_restore_sigmask(void)
146{
147 current_thread_info()->local_flags &= ~_TLF_RESTORE_SIGMASK;
148}
149static inline bool test_restore_sigmask(void)
150{
151 return current_thread_info()->local_flags & _TLF_RESTORE_SIGMASK;
152}
153static inline bool test_and_clear_restore_sigmask(void)
154{
155 struct thread_info *ti = current_thread_info();
156 if (!(ti->local_flags & _TLF_RESTORE_SIGMASK))
157 return false;
158 ti->local_flags &= ~_TLF_RESTORE_SIGMASK;
159 return true;
144} 160}
145 161
146static inline bool test_thread_local_flags(unsigned int flags) 162static inline bool test_thread_local_flags(unsigned int flags)
diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
index 651c5963662b..5c023c9cf16e 100644
--- a/arch/powerpc/kernel/signal.c
+++ b/arch/powerpc/kernel/signal.c
@@ -51,16 +51,6 @@ void __user * get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
51 return (void __user *)newsp; 51 return (void __user *)newsp;
52} 52}
53 53
54
55/*
56 * Restore the user process's signal mask
57 */
58void restore_sigmask(sigset_t *set)
59{
60 sigdelsetmask(set, ~_BLOCKABLE);
61 set_current_blocked(set);
62}
63
64static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka, 54static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka,
65 int has_handler) 55 int has_handler)
66{ 56{
@@ -114,30 +104,21 @@ static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka,
114 104
115static int do_signal(struct pt_regs *regs) 105static int do_signal(struct pt_regs *regs)
116{ 106{
117 sigset_t *oldset; 107 sigset_t *oldset = sigmask_to_save();
118 siginfo_t info; 108 siginfo_t info;
119 int signr; 109 int signr;
120 struct k_sigaction ka; 110 struct k_sigaction ka;
121 int ret; 111 int ret;
122 int is32 = is_32bit_task(); 112 int is32 = is_32bit_task();
123 113
124 if (current_thread_info()->local_flags & _TLF_RESTORE_SIGMASK)
125 oldset = &current->saved_sigmask;
126 else
127 oldset = &current->blocked;
128
129 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 114 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
130 115
131 /* Is there any syscall restart business here ? */ 116 /* Is there any syscall restart business here ? */
132 check_syscall_restart(regs, &ka, signr > 0); 117 check_syscall_restart(regs, &ka, signr > 0);
133 118
134 if (signr <= 0) { 119 if (signr <= 0) {
135 struct thread_info *ti = current_thread_info();
136 /* No signal to deliver -- put the saved sigmask back */ 120 /* No signal to deliver -- put the saved sigmask back */
137 if (ti->local_flags & _TLF_RESTORE_SIGMASK) { 121 restore_saved_sigmask();
138 ti->local_flags &= ~_TLF_RESTORE_SIGMASK;
139 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
140 }
141 regs->trap = 0; 122 regs->trap = 0;
142 return 0; /* no signals delivered */ 123 return 0; /* no signals delivered */
143 } 124 }
@@ -167,18 +148,7 @@ static int do_signal(struct pt_regs *regs)
167 148
168 regs->trap = 0; 149 regs->trap = 0;
169 if (ret) { 150 if (ret) {
170 block_sigmask(&ka, signr); 151 signal_delivered(signr, &info, &ka, regs,
171
172 /*
173 * A signal was successfully delivered; the saved sigmask is in
174 * its frame, and we can clear the TLF_RESTORE_SIGMASK flag.
175 */
176 current_thread_info()->local_flags &= ~_TLF_RESTORE_SIGMASK;
177
178 /*
179 * Let tracing know that we've done the handler setup.
180 */
181 tracehook_signal_handler(signr, &info, &ka, regs,
182 test_thread_flag(TIF_SINGLESTEP)); 152 test_thread_flag(TIF_SINGLESTEP));
183 } 153 }
184 154
@@ -193,8 +163,6 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
193 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 163 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
194 clear_thread_flag(TIF_NOTIFY_RESUME); 164 clear_thread_flag(TIF_NOTIFY_RESUME);
195 tracehook_notify_resume(regs); 165 tracehook_notify_resume(regs);
196 if (current->replacement_session_keyring)
197 key_replace_session_keyring();
198 } 166 }
199} 167}
200 168
diff --git a/arch/powerpc/kernel/signal.h b/arch/powerpc/kernel/signal.h
index 8dde973aaaf5..e00acb413934 100644
--- a/arch/powerpc/kernel/signal.h
+++ b/arch/powerpc/kernel/signal.h
@@ -10,13 +10,10 @@
10#ifndef _POWERPC_ARCH_SIGNAL_H 10#ifndef _POWERPC_ARCH_SIGNAL_H
11#define _POWERPC_ARCH_SIGNAL_H 11#define _POWERPC_ARCH_SIGNAL_H
12 12
13#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
14
15extern void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags); 13extern void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags);
16 14
17extern void __user * get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, 15extern void __user * get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
18 size_t frame_size, int is_32); 16 size_t frame_size, int is_32);
19extern void restore_sigmask(sigset_t *set);
20 17
21extern int handle_signal32(unsigned long sig, struct k_sigaction *ka, 18extern int handle_signal32(unsigned long sig, struct k_sigaction *ka,
22 siginfo_t *info, sigset_t *oldset, 19 siginfo_t *info, sigset_t *oldset,
diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index 61f6aff25edc..8b4c049aee20 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -919,7 +919,7 @@ static int do_setcontext(struct ucontext __user *ucp, struct pt_regs *regs, int
919 if (!access_ok(VERIFY_READ, mcp, sizeof(*mcp))) 919 if (!access_ok(VERIFY_READ, mcp, sizeof(*mcp)))
920 return -EFAULT; 920 return -EFAULT;
921#endif 921#endif
922 restore_sigmask(&set); 922 set_current_blocked(&set);
923 if (restore_user_regs(regs, mcp, sig)) 923 if (restore_user_regs(regs, mcp, sig))
924 return -EFAULT; 924 return -EFAULT;
925 925
@@ -1273,7 +1273,7 @@ long sys_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8,
1273 set.sig[0] = sigctx.oldmask; 1273 set.sig[0] = sigctx.oldmask;
1274 set.sig[1] = sigctx._unused[3]; 1274 set.sig[1] = sigctx._unused[3];
1275#endif 1275#endif
1276 restore_sigmask(&set); 1276 set_current_blocked(&set);
1277 1277
1278 sr = (struct mcontext __user *)from_user_ptr(sigctx.regs); 1278 sr = (struct mcontext __user *)from_user_ptr(sigctx.regs);
1279 addr = sr; 1279 addr = sr;
diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
index 2692efdb154e..d183f8719a50 100644
--- a/arch/powerpc/kernel/signal_64.c
+++ b/arch/powerpc/kernel/signal_64.c
@@ -335,7 +335,7 @@ int sys_swapcontext(struct ucontext __user *old_ctx,
335 335
336 if (__copy_from_user(&set, &new_ctx->uc_sigmask, sizeof(set))) 336 if (__copy_from_user(&set, &new_ctx->uc_sigmask, sizeof(set)))
337 do_exit(SIGSEGV); 337 do_exit(SIGSEGV);
338 restore_sigmask(&set); 338 set_current_blocked(&set);
339 if (restore_sigcontext(regs, NULL, 0, &new_ctx->uc_mcontext)) 339 if (restore_sigcontext(regs, NULL, 0, &new_ctx->uc_mcontext))
340 do_exit(SIGSEGV); 340 do_exit(SIGSEGV);
341 341
@@ -364,7 +364,7 @@ int sys_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,
364 364
365 if (__copy_from_user(&set, &uc->uc_sigmask, sizeof(set))) 365 if (__copy_from_user(&set, &uc->uc_sigmask, sizeof(set)))
366 goto badframe; 366 goto badframe;
367 restore_sigmask(&set); 367 set_current_blocked(&set);
368 if (restore_sigcontext(regs, NULL, 1, &uc->uc_mcontext)) 368 if (restore_sigcontext(regs, NULL, 1, &uc->uc_mcontext))
369 goto badframe; 369 goto badframe;
370 370
diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
index 5b63bd3da4a9..e779642c25e5 100644
--- a/arch/powerpc/mm/mmu_context_nohash.c
+++ b/arch/powerpc/mm/mmu_context_nohash.c
@@ -333,9 +333,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
333 unsigned long action, void *hcpu) 333 unsigned long action, void *hcpu)
334{ 334{
335 unsigned int cpu = (unsigned int)(long)hcpu; 335 unsigned int cpu = (unsigned int)(long)hcpu;
336#ifdef CONFIG_HOTPLUG_CPU 336
337 struct task_struct *p;
338#endif
339 /* We don't touch CPU 0 map, it's allocated at aboot and kept 337 /* We don't touch CPU 0 map, it's allocated at aboot and kept
340 * around forever 338 * around forever
341 */ 339 */
@@ -358,12 +356,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
358 stale_map[cpu] = NULL; 356 stale_map[cpu] = NULL;
359 357
360 /* We also clear the cpu_vm_mask bits of CPUs going away */ 358 /* We also clear the cpu_vm_mask bits of CPUs going away */
361 read_lock(&tasklist_lock); 359 clear_tasks_mm_cpumask(cpu);
362 for_each_process(p) {
363 if (p->mm)
364 cpumask_clear_cpu(cpu, mm_cpumask(p->mm));
365 }
366 read_unlock(&tasklist_lock);
367 break; 360 break;
368#endif /* CONFIG_HOTPLUG_CPU */ 361#endif /* CONFIG_HOTPLUG_CPU */
369 } 362 }
diff --git a/arch/s390/include/asm/posix_types.h b/arch/s390/include/asm/posix_types.h
index edf8527ff08d..7be104c0f192 100644
--- a/arch/s390/include/asm/posix_types.h
+++ b/arch/s390/include/asm/posix_types.h
@@ -24,7 +24,6 @@ typedef unsigned short __kernel_old_dev_t;
24 24
25typedef unsigned long __kernel_ino_t; 25typedef unsigned long __kernel_ino_t;
26typedef unsigned short __kernel_mode_t; 26typedef unsigned short __kernel_mode_t;
27typedef unsigned short __kernel_nlink_t;
28typedef unsigned short __kernel_ipc_pid_t; 27typedef unsigned short __kernel_ipc_pid_t;
29typedef unsigned short __kernel_uid_t; 28typedef unsigned short __kernel_uid_t;
30typedef unsigned short __kernel_gid_t; 29typedef unsigned short __kernel_gid_t;
@@ -35,7 +34,6 @@ typedef int __kernel_ptrdiff_t;
35 34
36typedef unsigned int __kernel_ino_t; 35typedef unsigned int __kernel_ino_t;
37typedef unsigned int __kernel_mode_t; 36typedef unsigned int __kernel_mode_t;
38typedef unsigned int __kernel_nlink_t;
39typedef int __kernel_ipc_pid_t; 37typedef int __kernel_ipc_pid_t;
40typedef unsigned int __kernel_uid_t; 38typedef unsigned int __kernel_uid_t;
41typedef unsigned int __kernel_gid_t; 39typedef unsigned int __kernel_gid_t;
@@ -47,7 +45,6 @@ typedef unsigned long __kernel_sigset_t; /* at least 32 bits */
47 45
48#define __kernel_ino_t __kernel_ino_t 46#define __kernel_ino_t __kernel_ino_t
49#define __kernel_mode_t __kernel_mode_t 47#define __kernel_mode_t __kernel_mode_t
50#define __kernel_nlink_t __kernel_nlink_t
51#define __kernel_ipc_pid_t __kernel_ipc_pid_t 48#define __kernel_ipc_pid_t __kernel_ipc_pid_t
52#define __kernel_uid_t __kernel_uid_t 49#define __kernel_uid_t __kernel_uid_t
53#define __kernel_gid_t __kernel_gid_t 50#define __kernel_gid_t __kernel_gid_t
diff --git a/arch/s390/kernel/compat_signal.c b/arch/s390/kernel/compat_signal.c
index 377c096ca4a7..3c0c19830c37 100644
--- a/arch/s390/kernel/compat_signal.c
+++ b/arch/s390/kernel/compat_signal.c
@@ -32,8 +32,6 @@
32#include "compat_ptrace.h" 32#include "compat_ptrace.h"
33#include "entry.h" 33#include "entry.h"
34 34
35#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
36
37typedef struct 35typedef struct
38{ 36{
39 __u8 callee_used_stack[__SIGNAL_FRAMESIZE32]; 37 __u8 callee_used_stack[__SIGNAL_FRAMESIZE32];
@@ -364,7 +362,6 @@ asmlinkage long sys32_sigreturn(void)
364 goto badframe; 362 goto badframe;
365 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE32)) 363 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE32))
366 goto badframe; 364 goto badframe;
367 sigdelsetmask(&set, ~_BLOCKABLE);
368 set_current_blocked(&set); 365 set_current_blocked(&set);
369 if (restore_sigregs32(regs, &frame->sregs)) 366 if (restore_sigregs32(regs, &frame->sregs))
370 goto badframe; 367 goto badframe;
@@ -390,7 +387,6 @@ asmlinkage long sys32_rt_sigreturn(void)
390 goto badframe; 387 goto badframe;
391 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 388 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
392 goto badframe; 389 goto badframe;
393 sigdelsetmask(&set, ~_BLOCKABLE);
394 set_current_blocked(&set); 390 set_current_blocked(&set);
395 if (restore_sigregs32(regs, &frame->uc.uc_mcontext)) 391 if (restore_sigregs32(regs, &frame->uc.uc_mcontext))
396 goto badframe; 392 goto badframe;
@@ -572,7 +568,7 @@ give_sigsegv:
572 * OK, we're invoking a handler 568 * OK, we're invoking a handler
573 */ 569 */
574 570
575int handle_signal32(unsigned long sig, struct k_sigaction *ka, 571void handle_signal32(unsigned long sig, struct k_sigaction *ka,
576 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) 572 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs)
577{ 573{
578 int ret; 574 int ret;
@@ -583,8 +579,8 @@ int handle_signal32(unsigned long sig, struct k_sigaction *ka,
583 else 579 else
584 ret = setup_frame32(sig, ka, oldset, regs); 580 ret = setup_frame32(sig, ka, oldset, regs);
585 if (ret) 581 if (ret)
586 return ret; 582 return;
587 block_sigmask(ka, sig); 583 signal_delivered(sig, info, ka, regs,
588 return 0; 584 test_thread_flag(TIF_SINGLE_STEP));
589} 585}
590 586
diff --git a/arch/s390/kernel/entry.h b/arch/s390/kernel/entry.h
index 6cdddac93a2e..f66a229ab0b3 100644
--- a/arch/s390/kernel/entry.h
+++ b/arch/s390/kernel/entry.h
@@ -31,7 +31,7 @@ void do_per_trap(struct pt_regs *regs);
31void syscall_trace(struct pt_regs *regs, int entryexit); 31void syscall_trace(struct pt_regs *regs, int entryexit);
32void kernel_stack_overflow(struct pt_regs * regs); 32void kernel_stack_overflow(struct pt_regs * regs);
33void do_signal(struct pt_regs *regs); 33void do_signal(struct pt_regs *regs);
34int handle_signal32(unsigned long sig, struct k_sigaction *ka, 34void handle_signal32(unsigned long sig, struct k_sigaction *ka,
35 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs); 35 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs);
36void do_notify_resume(struct pt_regs *regs); 36void do_notify_resume(struct pt_regs *regs);
37 37
diff --git a/arch/s390/kernel/signal.c b/arch/s390/kernel/signal.c
index f626232e216c..ac565b44aabb 100644
--- a/arch/s390/kernel/signal.c
+++ b/arch/s390/kernel/signal.c
@@ -33,9 +33,6 @@
33#include <asm/switch_to.h> 33#include <asm/switch_to.h>
34#include "entry.h" 34#include "entry.h"
35 35
36#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
37
38
39typedef struct 36typedef struct
40{ 37{
41 __u8 callee_used_stack[__SIGNAL_FRAMESIZE]; 38 __u8 callee_used_stack[__SIGNAL_FRAMESIZE];
@@ -169,7 +166,6 @@ SYSCALL_DEFINE0(sigreturn)
169 goto badframe; 166 goto badframe;
170 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE)) 167 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE))
171 goto badframe; 168 goto badframe;
172 sigdelsetmask(&set, ~_BLOCKABLE);
173 set_current_blocked(&set); 169 set_current_blocked(&set);
174 if (restore_sigregs(regs, &frame->sregs)) 170 if (restore_sigregs(regs, &frame->sregs))
175 goto badframe; 171 goto badframe;
@@ -189,7 +185,6 @@ SYSCALL_DEFINE0(rt_sigreturn)
189 goto badframe; 185 goto badframe;
190 if (__copy_from_user(&set.sig, &frame->uc.uc_sigmask, sizeof(set))) 186 if (__copy_from_user(&set.sig, &frame->uc.uc_sigmask, sizeof(set)))
191 goto badframe; 187 goto badframe;
192 sigdelsetmask(&set, ~_BLOCKABLE);
193 set_current_blocked(&set); 188 set_current_blocked(&set);
194 if (restore_sigregs(regs, &frame->uc.uc_mcontext)) 189 if (restore_sigregs(regs, &frame->uc.uc_mcontext))
195 goto badframe; 190 goto badframe;
@@ -367,7 +362,7 @@ give_sigsegv:
367 return -EFAULT; 362 return -EFAULT;
368} 363}
369 364
370static int handle_signal(unsigned long sig, struct k_sigaction *ka, 365static void handle_signal(unsigned long sig, struct k_sigaction *ka,
371 siginfo_t *info, sigset_t *oldset, 366 siginfo_t *info, sigset_t *oldset,
372 struct pt_regs *regs) 367 struct pt_regs *regs)
373{ 368{
@@ -379,9 +374,9 @@ static int handle_signal(unsigned long sig, struct k_sigaction *ka,
379 else 374 else
380 ret = setup_frame(sig, ka, oldset, regs); 375 ret = setup_frame(sig, ka, oldset, regs);
381 if (ret) 376 if (ret)
382 return ret; 377 return;
383 block_sigmask(ka, sig); 378 signal_delivered(sig, info, ka, regs,
384 return 0; 379 test_thread_flag(TIF_SINGLE_STEP));
385} 380}
386 381
387/* 382/*
@@ -398,12 +393,7 @@ void do_signal(struct pt_regs *regs)
398 siginfo_t info; 393 siginfo_t info;
399 int signr; 394 int signr;
400 struct k_sigaction ka; 395 struct k_sigaction ka;
401 sigset_t *oldset; 396 sigset_t *oldset = sigmask_to_save();
402
403 if (test_thread_flag(TIF_RESTORE_SIGMASK))
404 oldset = &current->saved_sigmask;
405 else
406 oldset = &current->blocked;
407 397
408 /* 398 /*
409 * Get signal to deliver. When running under ptrace, at this point 399 * Get signal to deliver. When running under ptrace, at this point
@@ -441,24 +431,10 @@ void do_signal(struct pt_regs *regs)
441 /* No longer in a system call */ 431 /* No longer in a system call */
442 clear_thread_flag(TIF_SYSCALL); 432 clear_thread_flag(TIF_SYSCALL);
443 433
444 if ((is_compat_task() ? 434 if (is_compat_task())
445 handle_signal32(signr, &ka, &info, oldset, regs) : 435 handle_signal32(signr, &ka, &info, oldset, regs);
446 handle_signal(signr, &ka, &info, oldset, regs)) == 0) { 436 else
447 /* 437 handle_signal(signr, &ka, &info, oldset, regs);
448 * A signal was successfully delivered; the saved
449 * sigmask will have been stored in the signal frame,
450 * and will be restored by sigreturn, so we can simply
451 * clear the TIF_RESTORE_SIGMASK flag.
452 */
453 if (test_thread_flag(TIF_RESTORE_SIGMASK))
454 clear_thread_flag(TIF_RESTORE_SIGMASK);
455
456 /*
457 * Let tracing know that we've done the handler setup.
458 */
459 tracehook_signal_handler(signr, &info, &ka, regs,
460 test_thread_flag(TIF_SINGLE_STEP));
461 }
462 return; 438 return;
463 } 439 }
464 440
@@ -484,16 +460,11 @@ void do_signal(struct pt_regs *regs)
484 /* 460 /*
485 * If there's no signal to deliver, we just put the saved sigmask back. 461 * If there's no signal to deliver, we just put the saved sigmask back.
486 */ 462 */
487 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 463 restore_saved_sigmask();
488 clear_thread_flag(TIF_RESTORE_SIGMASK);
489 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
490 }
491} 464}
492 465
493void do_notify_resume(struct pt_regs *regs) 466void do_notify_resume(struct pt_regs *regs)
494{ 467{
495 clear_thread_flag(TIF_NOTIFY_RESUME); 468 clear_thread_flag(TIF_NOTIFY_RESUME);
496 tracehook_notify_resume(regs); 469 tracehook_notify_resume(regs);
497 if (current->replacement_session_keyring)
498 key_replace_session_keyring();
499} 470}
diff --git a/arch/score/kernel/signal.c b/arch/score/kernel/signal.c
index d4a49011c48a..e382c52ca0d9 100644
--- a/arch/score/kernel/signal.c
+++ b/arch/score/kernel/signal.c
@@ -34,8 +34,6 @@
34#include <asm/syscalls.h> 34#include <asm/syscalls.h>
35#include <asm/ucontext.h> 35#include <asm/ucontext.h>
36 36
37#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
38
39struct rt_sigframe { 37struct rt_sigframe {
40 u32 rs_ass[4]; /* argument save space */ 38 u32 rs_ass[4]; /* argument save space */
41 u32 rs_code[2]; /* signal trampoline */ 39 u32 rs_code[2]; /* signal trampoline */
@@ -162,7 +160,6 @@ score_rt_sigreturn(struct pt_regs *regs)
162 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set))) 160 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
163 goto badframe; 161 goto badframe;
164 162
165 sigdelsetmask(&set, ~_BLOCKABLE);
166 set_current_blocked(&set); 163 set_current_blocked(&set);
167 164
168 sig = restore_sigcontext(regs, &frame->rs_uc.uc_mcontext); 165 sig = restore_sigcontext(regs, &frame->rs_uc.uc_mcontext);
@@ -241,11 +238,9 @@ give_sigsegv:
241 return -EFAULT; 238 return -EFAULT;
242} 239}
243 240
244static int handle_signal(unsigned long sig, siginfo_t *info, 241static void handle_signal(unsigned long sig, siginfo_t *info,
245 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs) 242 struct k_sigaction *ka, struct pt_regs *regs)
246{ 243{
247 int ret;
248
249 if (regs->is_syscall) { 244 if (regs->is_syscall) {
250 switch (regs->regs[4]) { 245 switch (regs->regs[4]) {
251 case ERESTART_RESTARTBLOCK: 246 case ERESTART_RESTARTBLOCK:
@@ -269,18 +264,15 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
269 /* 264 /*
270 * Set up the stack frame 265 * Set up the stack frame
271 */ 266 */
272 ret = setup_rt_frame(ka, regs, sig, oldset, info); 267 if (setup_rt_frame(ka, regs, sig, sigmask_to_save(), info) < 0)
273 268 return;
274 if (ret == 0)
275 block_sigmask(ka, sig);
276 269
277 return ret; 270 signal_delivered(sig, info, ka, regs, 0);
278} 271}
279 272
280static void do_signal(struct pt_regs *regs) 273static void do_signal(struct pt_regs *regs)
281{ 274{
282 struct k_sigaction ka; 275 struct k_sigaction ka;
283 sigset_t *oldset;
284 siginfo_t info; 276 siginfo_t info;
285 int signr; 277 int signr;
286 278
@@ -292,25 +284,10 @@ static void do_signal(struct pt_regs *regs)
292 if (!user_mode(regs)) 284 if (!user_mode(regs))
293 return; 285 return;
294 286
295 if (test_thread_flag(TIF_RESTORE_SIGMASK))
296 oldset = &current->saved_sigmask;
297 else
298 oldset = &current->blocked;
299
300 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 287 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
301 if (signr > 0) { 288 if (signr > 0) {
302 /* Actually deliver the signal. */ 289 /* Actually deliver the signal. */
303 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 290 handle_signal(signr, &info, &ka, regs);
304 /*
305 * A signal was successfully delivered; the saved
306 * sigmask will have been stored in the signal frame,
307 * and will be restored by sigreturn, so we can simply
308 * clear the TIF_RESTORE_SIGMASK flag.
309 */
310 if (test_thread_flag(TIF_RESTORE_SIGMASK))
311 clear_thread_flag(TIF_RESTORE_SIGMASK);
312 }
313
314 return; 291 return;
315 } 292 }
316 293
@@ -337,10 +314,7 @@ static void do_signal(struct pt_regs *regs)
337 * If there's no signal to deliver, we just put the saved sigmask 314 * If there's no signal to deliver, we just put the saved sigmask
338 * back 315 * back
339 */ 316 */
340 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 317 restore_saved_sigmask();
341 clear_thread_flag(TIF_RESTORE_SIGMASK);
342 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
343 }
344} 318}
345 319
346/* 320/*
@@ -356,7 +330,5 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
356 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 330 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
357 clear_thread_flag(TIF_NOTIFY_RESUME); 331 clear_thread_flag(TIF_NOTIFY_RESUME);
358 tracehook_notify_resume(regs); 332 tracehook_notify_resume(regs);
359 if (current->replacement_session_keyring)
360 key_replace_session_keyring();
361 } 333 }
362} 334}
diff --git a/arch/sh/boards/mach-migor/setup.c b/arch/sh/boards/mach-migor/setup.c
index 34cd0c5ff2e1..a8a1ca741c85 100644
--- a/arch/sh/boards/mach-migor/setup.c
+++ b/arch/sh/boards/mach-migor/setup.c
@@ -188,7 +188,6 @@ static struct platform_nand_data migor_nand_flash_data = {
188 .partitions = migor_nand_flash_partitions, 188 .partitions = migor_nand_flash_partitions,
189 .nr_partitions = ARRAY_SIZE(migor_nand_flash_partitions), 189 .nr_partitions = ARRAY_SIZE(migor_nand_flash_partitions),
190 .chip_delay = 20, 190 .chip_delay = 20,
191 .part_probe_types = (const char *[]) { "cmdlinepart", NULL },
192 }, 191 },
193 .ctrl = { 192 .ctrl = {
194 .dev_ready = migor_nand_flash_ready, 193 .dev_ready = migor_nand_flash_ready,
diff --git a/arch/sh/include/asm/posix_types_32.h b/arch/sh/include/asm/posix_types_32.h
index abda58467ece..ba0bdc423b07 100644
--- a/arch/sh/include/asm/posix_types_32.h
+++ b/arch/sh/include/asm/posix_types_32.h
@@ -3,8 +3,6 @@
3 3
4typedef unsigned short __kernel_mode_t; 4typedef unsigned short __kernel_mode_t;
5#define __kernel_mode_t __kernel_mode_t 5#define __kernel_mode_t __kernel_mode_t
6typedef unsigned short __kernel_nlink_t;
7#define __kernel_nlink_t __kernel_nlink_t
8typedef unsigned short __kernel_ipc_pid_t; 6typedef unsigned short __kernel_ipc_pid_t;
9#define __kernel_ipc_pid_t __kernel_ipc_pid_t 7#define __kernel_ipc_pid_t __kernel_ipc_pid_t
10typedef unsigned short __kernel_uid_t; 8typedef unsigned short __kernel_uid_t;
diff --git a/arch/sh/include/asm/posix_types_64.h b/arch/sh/include/asm/posix_types_64.h
index fcda07b4a616..244f7e950e17 100644
--- a/arch/sh/include/asm/posix_types_64.h
+++ b/arch/sh/include/asm/posix_types_64.h
@@ -3,8 +3,6 @@
3 3
4typedef unsigned short __kernel_mode_t; 4typedef unsigned short __kernel_mode_t;
5#define __kernel_mode_t __kernel_mode_t 5#define __kernel_mode_t __kernel_mode_t
6typedef unsigned short __kernel_nlink_t;
7#define __kernel_nlink_t __kernel_nlink_t
8typedef unsigned short __kernel_ipc_pid_t; 6typedef unsigned short __kernel_ipc_pid_t;
9#define __kernel_ipc_pid_t __kernel_ipc_pid_t 7#define __kernel_ipc_pid_t __kernel_ipc_pid_t
10typedef unsigned short __kernel_uid_t; 8typedef unsigned short __kernel_uid_t;
diff --git a/arch/sh/include/asm/thread_info.h b/arch/sh/include/asm/thread_info.h
index 0c04ffc4f12c..bc13b57cdc83 100644
--- a/arch/sh/include/asm/thread_info.h
+++ b/arch/sh/include/asm/thread_info.h
@@ -169,7 +169,7 @@ static inline void set_restore_sigmask(void)
169{ 169{
170 struct thread_info *ti = current_thread_info(); 170 struct thread_info *ti = current_thread_info();
171 ti->status |= TS_RESTORE_SIGMASK; 171 ti->status |= TS_RESTORE_SIGMASK;
172 set_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags); 172 WARN_ON(!test_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags));
173} 173}
174 174
175#define TI_FLAG_FAULT_CODE_SHIFT 24 175#define TI_FLAG_FAULT_CODE_SHIFT 24
@@ -189,6 +189,23 @@ static inline unsigned int get_thread_fault_code(void)
189 struct thread_info *ti = current_thread_info(); 189 struct thread_info *ti = current_thread_info();
190 return ti->flags >> TI_FLAG_FAULT_CODE_SHIFT; 190 return ti->flags >> TI_FLAG_FAULT_CODE_SHIFT;
191} 191}
192
193static inline void clear_restore_sigmask(void)
194{
195 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
196}
197static inline bool test_restore_sigmask(void)
198{
199 return current_thread_info()->status & TS_RESTORE_SIGMASK;
200}
201static inline bool test_and_clear_restore_sigmask(void)
202{
203 struct thread_info *ti = current_thread_info();
204 if (!(ti->status & TS_RESTORE_SIGMASK))
205 return false;
206 ti->status &= ~TS_RESTORE_SIGMASK;
207 return true;
208}
192#endif /* !__ASSEMBLY__ */ 209#endif /* !__ASSEMBLY__ */
193 210
194#endif /* __KERNEL__ */ 211#endif /* __KERNEL__ */
diff --git a/arch/sh/kernel/signal_32.c b/arch/sh/kernel/signal_32.c
index cb4172c8af7d..d6b7b6154f87 100644
--- a/arch/sh/kernel/signal_32.c
+++ b/arch/sh/kernel/signal_32.c
@@ -32,8 +32,6 @@
32#include <asm/syscalls.h> 32#include <asm/syscalls.h>
33#include <asm/fpu.h> 33#include <asm/fpu.h>
34 34
35#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
36
37struct fdpic_func_descriptor { 35struct fdpic_func_descriptor {
38 unsigned long text; 36 unsigned long text;
39 unsigned long GOT; 37 unsigned long GOT;
@@ -226,7 +224,6 @@ asmlinkage int sys_sigreturn(unsigned long r4, unsigned long r5,
226 sizeof(frame->extramask)))) 224 sizeof(frame->extramask))))
227 goto badframe; 225 goto badframe;
228 226
229 sigdelsetmask(&set, ~_BLOCKABLE);
230 set_current_blocked(&set); 227 set_current_blocked(&set);
231 228
232 if (restore_sigcontext(regs, &frame->sc, &r0)) 229 if (restore_sigcontext(regs, &frame->sc, &r0))
@@ -256,7 +253,6 @@ asmlinkage int sys_rt_sigreturn(unsigned long r4, unsigned long r5,
256 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 253 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
257 goto badframe; 254 goto badframe;
258 255
259 sigdelsetmask(&set, ~_BLOCKABLE);
260 set_current_blocked(&set); 256 set_current_blocked(&set);
261 257
262 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0)) 258 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0))
@@ -522,10 +518,11 @@ handle_syscall_restart(unsigned long save_r0, struct pt_regs *regs,
522/* 518/*
523 * OK, we're invoking a handler 519 * OK, we're invoking a handler
524 */ 520 */
525static int 521static void
526handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info, 522handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
527 sigset_t *oldset, struct pt_regs *regs, unsigned int save_r0) 523 struct pt_regs *regs, unsigned int save_r0)
528{ 524{
525 sigset_t *oldset = sigmask_to_save();
529 int ret; 526 int ret;
530 527
531 /* Set up the stack frame */ 528 /* Set up the stack frame */
@@ -534,10 +531,10 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
534 else 531 else
535 ret = setup_frame(sig, ka, oldset, regs); 532 ret = setup_frame(sig, ka, oldset, regs);
536 533
537 if (ret == 0) 534 if (ret)
538 block_sigmask(ka, sig); 535 return;
539 536 signal_delivered(sig, info, ka, regs,
540 return ret; 537 test_thread_flag(TIF_SINGLESTEP));
541} 538}
542 539
543/* 540/*
@@ -554,7 +551,6 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
554 siginfo_t info; 551 siginfo_t info;
555 int signr; 552 int signr;
556 struct k_sigaction ka; 553 struct k_sigaction ka;
557 sigset_t *oldset;
558 554
559 /* 555 /*
560 * We want the common case to go fast, which 556 * We want the common case to go fast, which
@@ -565,30 +561,12 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
565 if (!user_mode(regs)) 561 if (!user_mode(regs))
566 return; 562 return;
567 563
568 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
569 oldset = &current->saved_sigmask;
570 else
571 oldset = &current->blocked;
572
573 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 564 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
574 if (signr > 0) { 565 if (signr > 0) {
575 handle_syscall_restart(save_r0, regs, &ka.sa); 566 handle_syscall_restart(save_r0, regs, &ka.sa);
576 567
577 /* Whee! Actually deliver the signal. */ 568 /* Whee! Actually deliver the signal. */
578 if (handle_signal(signr, &ka, &info, oldset, 569 handle_signal(signr, &ka, &info, regs, save_r0);
579 regs, save_r0) == 0) {
580 /*
581 * A signal was successfully delivered; the saved
582 * sigmask will have been stored in the signal frame,
583 * and will be restored by sigreturn, so we can simply
584 * clear the TS_RESTORE_SIGMASK flag
585 */
586 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
587
588 tracehook_signal_handler(signr, &info, &ka, regs,
589 test_thread_flag(TIF_SINGLESTEP));
590 }
591
592 return; 570 return;
593 } 571 }
594 572
@@ -610,10 +588,7 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
610 * If there's no signal to deliver, we just put the saved sigmask 588 * If there's no signal to deliver, we just put the saved sigmask
611 * back. 589 * back.
612 */ 590 */
613 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 591 restore_saved_sigmask();
614 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
615 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
616 }
617} 592}
618 593
619asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned int save_r0, 594asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned int save_r0,
@@ -626,7 +601,5 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned int save_r0,
626 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 601 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
627 clear_thread_flag(TIF_NOTIFY_RESUME); 602 clear_thread_flag(TIF_NOTIFY_RESUME);
628 tracehook_notify_resume(regs); 603 tracehook_notify_resume(regs);
629 if (current->replacement_session_keyring)
630 key_replace_session_keyring();
631 } 604 }
632} 605}
diff --git a/arch/sh/kernel/signal_64.c b/arch/sh/kernel/signal_64.c
index b589a354c069..6b5b3dfe886b 100644
--- a/arch/sh/kernel/signal_64.c
+++ b/arch/sh/kernel/signal_64.c
@@ -41,11 +41,9 @@
41 41
42#define DEBUG_SIG 0 42#define DEBUG_SIG 0
43 43
44#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) 44static void
45
46static int
47handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, 45handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
48 sigset_t *oldset, struct pt_regs * regs); 46 struct pt_regs * regs);
49 47
50static inline void 48static inline void
51handle_syscall_restart(struct pt_regs *regs, struct sigaction *sa) 49handle_syscall_restart(struct pt_regs *regs, struct sigaction *sa)
@@ -88,7 +86,6 @@ static void do_signal(struct pt_regs *regs)
88 siginfo_t info; 86 siginfo_t info;
89 int signr; 87 int signr;
90 struct k_sigaction ka; 88 struct k_sigaction ka;
91 sigset_t *oldset;
92 89
93 /* 90 /*
94 * We want the common case to go fast, which 91 * We want the common case to go fast, which
@@ -99,28 +96,13 @@ static void do_signal(struct pt_regs *regs)
99 if (!user_mode(regs)) 96 if (!user_mode(regs))
100 return; 97 return;
101 98
102 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
103 oldset = &current->saved_sigmask;
104 else
105 oldset = &current->blocked;
106
107 signr = get_signal_to_deliver(&info, &ka, regs, 0); 99 signr = get_signal_to_deliver(&info, &ka, regs, 0);
108 if (signr > 0) { 100 if (signr > 0) {
109 handle_syscall_restart(regs, &ka.sa); 101 handle_syscall_restart(regs, &ka.sa);
110 102
111 /* Whee! Actually deliver the signal. */ 103 /* Whee! Actually deliver the signal. */
112 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 104 handle_signal(signr, &info, &ka, regs);
113 /* 105 return;
114 * If a signal was successfully delivered, the
115 * saved sigmask is in its frame, and we can
116 * clear the TS_RESTORE_SIGMASK flag.
117 */
118 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
119
120 tracehook_signal_handler(signr, &info, &ka, regs,
121 test_thread_flag(TIF_SINGLESTEP));
122 return;
123 }
124 } 106 }
125 107
126 /* Did we come from a system call? */ 108 /* Did we come from a system call? */
@@ -143,12 +125,7 @@ static void do_signal(struct pt_regs *regs)
143 } 125 }
144 126
145 /* No signal to deliver -- put the saved sigmask back */ 127 /* No signal to deliver -- put the saved sigmask back */
146 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 128 restore_saved_sigmask();
147 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
148 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
149 }
150
151 return;
152} 129}
153 130
154/* 131/*
@@ -351,7 +328,6 @@ asmlinkage int sys_sigreturn(unsigned long r2, unsigned long r3,
351 sizeof(frame->extramask)))) 328 sizeof(frame->extramask))))
352 goto badframe; 329 goto badframe;
353 330
354 sigdelsetmask(&set, ~_BLOCKABLE);
355 set_current_blocked(&set); 331 set_current_blocked(&set);
356 332
357 if (restore_sigcontext(regs, &frame->sc, &ret)) 333 if (restore_sigcontext(regs, &frame->sc, &ret))
@@ -384,7 +360,6 @@ asmlinkage int sys_rt_sigreturn(unsigned long r2, unsigned long r3,
384 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 360 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
385 goto badframe; 361 goto badframe;
386 362
387 sigdelsetmask(&set, ~_BLOCKABLE);
388 set_current_blocked(&set); 363 set_current_blocked(&set);
389 364
390 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ret)) 365 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ret))
@@ -659,10 +634,11 @@ give_sigsegv:
659/* 634/*
660 * OK, we're invoking a handler 635 * OK, we're invoking a handler
661 */ 636 */
662static int 637static void
663handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, 638handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
664 sigset_t *oldset, struct pt_regs * regs) 639 struct pt_regs * regs)
665{ 640{
641 sigset_t *oldset = sigmask_to_save();
666 int ret; 642 int ret;
667 643
668 /* Set up the stack frame */ 644 /* Set up the stack frame */
@@ -671,10 +647,11 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
671 else 647 else
672 ret = setup_frame(sig, ka, oldset, regs); 648 ret = setup_frame(sig, ka, oldset, regs);
673 649
674 if (ret == 0) 650 if (ret)
675 block_sigmask(ka, sig); 651 return;
676 652
677 return ret; 653 signal_delivered(sig, info, ka, regs,
654 test_thread_flag(TIF_SINGLESTEP));
678} 655}
679 656
680asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags) 657asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
@@ -685,7 +662,5 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned long thread_info
685 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 662 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
686 clear_thread_flag(TIF_NOTIFY_RESUME); 663 clear_thread_flag(TIF_NOTIFY_RESUME);
687 tracehook_notify_resume(regs); 664 tracehook_notify_resume(regs);
688 if (current->replacement_session_keyring)
689 key_replace_session_keyring();
690 } 665 }
691} 666}
diff --git a/arch/sh/kernel/smp.c b/arch/sh/kernel/smp.c
index b86e9ca79455..2062aa88af41 100644
--- a/arch/sh/kernel/smp.c
+++ b/arch/sh/kernel/smp.c
@@ -123,7 +123,6 @@ void native_play_dead(void)
123int __cpu_disable(void) 123int __cpu_disable(void)
124{ 124{
125 unsigned int cpu = smp_processor_id(); 125 unsigned int cpu = smp_processor_id();
126 struct task_struct *p;
127 int ret; 126 int ret;
128 127
129 ret = mp_ops->cpu_disable(cpu); 128 ret = mp_ops->cpu_disable(cpu);
@@ -153,11 +152,7 @@ int __cpu_disable(void)
153 flush_cache_all(); 152 flush_cache_all();
154 local_flush_tlb_all(); 153 local_flush_tlb_all();
155 154
156 read_lock(&tasklist_lock); 155 clear_tasks_mm_cpumask(cpu);
157 for_each_process(p)
158 if (p->mm)
159 cpumask_clear_cpu(cpu, mm_cpumask(p->mm));
160 read_unlock(&tasklist_lock);
161 156
162 return 0; 157 return 0;
163} 158}
diff --git a/arch/sparc/include/asm/posix_types.h b/arch/sparc/include/asm/posix_types.h
index 3070f25ae90a..156220ed99eb 100644
--- a/arch/sparc/include/asm/posix_types.h
+++ b/arch/sparc/include/asm/posix_types.h
@@ -9,8 +9,6 @@
9 9
10#if defined(__sparc__) && defined(__arch64__) 10#if defined(__sparc__) && defined(__arch64__)
11/* sparc 64 bit */ 11/* sparc 64 bit */
12typedef unsigned int __kernel_nlink_t;
13#define __kernel_nlink_t __kernel_nlink_t
14 12
15typedef unsigned short __kernel_old_uid_t; 13typedef unsigned short __kernel_old_uid_t;
16typedef unsigned short __kernel_old_gid_t; 14typedef unsigned short __kernel_old_gid_t;
@@ -38,9 +36,6 @@ typedef unsigned short __kernel_gid_t;
38typedef unsigned short __kernel_mode_t; 36typedef unsigned short __kernel_mode_t;
39#define __kernel_mode_t __kernel_mode_t 37#define __kernel_mode_t __kernel_mode_t
40 38
41typedef short __kernel_nlink_t;
42#define __kernel_nlink_t __kernel_nlink_t
43
44typedef long __kernel_daddr_t; 39typedef long __kernel_daddr_t;
45#define __kernel_daddr_t __kernel_daddr_t 40#define __kernel_daddr_t __kernel_daddr_t
46 41
diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
index 5af664932452..e6cd224506a9 100644
--- a/arch/sparc/include/asm/thread_info_32.h
+++ b/arch/sparc/include/asm/thread_info_32.h
@@ -131,8 +131,7 @@ register struct thread_info *current_thread_info_reg asm("g6");
131#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG) 131#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
132 132
133#define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | \ 133#define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | \
134 _TIF_SIGPENDING | \ 134 _TIF_SIGPENDING)
135 _TIF_RESTORE_SIGMASK)
136 135
137#endif /* __KERNEL__ */ 136#endif /* __KERNEL__ */
138 137
diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
index 7f0981b09451..cfa8c38fb9c8 100644
--- a/arch/sparc/include/asm/thread_info_64.h
+++ b/arch/sparc/include/asm/thread_info_64.h
@@ -238,7 +238,23 @@ static inline void set_restore_sigmask(void)
238{ 238{
239 struct thread_info *ti = current_thread_info(); 239 struct thread_info *ti = current_thread_info();
240 ti->status |= TS_RESTORE_SIGMASK; 240 ti->status |= TS_RESTORE_SIGMASK;
241 set_bit(TIF_SIGPENDING, &ti->flags); 241 WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
242}
243static inline void clear_restore_sigmask(void)
244{
245 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
246}
247static inline bool test_restore_sigmask(void)
248{
249 return current_thread_info()->status & TS_RESTORE_SIGMASK;
250}
251static inline bool test_and_clear_restore_sigmask(void)
252{
253 struct thread_info *ti = current_thread_info();
254 if (!(ti->status & TS_RESTORE_SIGMASK))
255 return false;
256 ti->status &= ~TS_RESTORE_SIGMASK;
257 return true;
242} 258}
243#endif /* !__ASSEMBLY__ */ 259#endif /* !__ASSEMBLY__ */
244 260
diff --git a/arch/sparc/kernel/signal32.c b/arch/sparc/kernel/signal32.c
index bb1513e45f1a..a53e0a5fd3a3 100644
--- a/arch/sparc/kernel/signal32.c
+++ b/arch/sparc/kernel/signal32.c
@@ -32,8 +32,6 @@
32 32
33#include "sigutil.h" 33#include "sigutil.h"
34 34
35#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
36
37/* This magic should be in g_upper[0] for all upper parts 35/* This magic should be in g_upper[0] for all upper parts
38 * to be valid. 36 * to be valid.
39 */ 37 */
@@ -274,7 +272,6 @@ void do_sigreturn32(struct pt_regs *regs)
274 case 2: set.sig[1] = seta[2] + (((long)seta[3]) << 32); 272 case 2: set.sig[1] = seta[2] + (((long)seta[3]) << 32);
275 case 1: set.sig[0] = seta[0] + (((long)seta[1]) << 32); 273 case 1: set.sig[0] = seta[0] + (((long)seta[1]) << 32);
276 } 274 }
277 sigdelsetmask(&set, ~_BLOCKABLE);
278 set_current_blocked(&set); 275 set_current_blocked(&set);
279 return; 276 return;
280 277
@@ -376,7 +373,6 @@ asmlinkage void do_rt_sigreturn32(struct pt_regs *regs)
376 case 2: set.sig[1] = seta.sig[2] + (((long)seta.sig[3]) << 32); 373 case 2: set.sig[1] = seta.sig[2] + (((long)seta.sig[3]) << 32);
377 case 1: set.sig[0] = seta.sig[0] + (((long)seta.sig[1]) << 32); 374 case 1: set.sig[0] = seta.sig[0] + (((long)seta.sig[1]) << 32);
378 } 375 }
379 sigdelsetmask(&set, ~_BLOCKABLE);
380 set_current_blocked(&set); 376 set_current_blocked(&set);
381 return; 377 return;
382segv: 378segv:
@@ -775,7 +771,7 @@ sigsegv:
775 return -EFAULT; 771 return -EFAULT;
776} 772}
777 773
778static inline int handle_signal32(unsigned long signr, struct k_sigaction *ka, 774static inline void handle_signal32(unsigned long signr, struct k_sigaction *ka,
779 siginfo_t *info, 775 siginfo_t *info,
780 sigset_t *oldset, struct pt_regs *regs) 776 sigset_t *oldset, struct pt_regs *regs)
781{ 777{
@@ -787,12 +783,9 @@ static inline int handle_signal32(unsigned long signr, struct k_sigaction *ka,
787 err = setup_frame32(ka, regs, signr, oldset); 783 err = setup_frame32(ka, regs, signr, oldset);
788 784
789 if (err) 785 if (err)
790 return err; 786 return;
791
792 block_sigmask(ka, signr);
793 tracehook_signal_handler(signr, info, ka, regs, 0);
794 787
795 return 0; 788 signal_delivered(signr, info, ka, regs, 0);
796} 789}
797 790
798static inline void syscall_restart32(unsigned long orig_i0, struct pt_regs *regs, 791static inline void syscall_restart32(unsigned long orig_i0, struct pt_regs *regs,
@@ -841,14 +834,7 @@ void do_signal32(sigset_t *oldset, struct pt_regs * regs)
841 if (signr > 0) { 834 if (signr > 0) {
842 if (restart_syscall) 835 if (restart_syscall)
843 syscall_restart32(orig_i0, regs, &ka.sa); 836 syscall_restart32(orig_i0, regs, &ka.sa);
844 if (handle_signal32(signr, &ka, &info, oldset, regs) == 0) { 837 handle_signal32(signr, &ka, &info, oldset, regs);
845 /* A signal was successfully delivered; the saved
846 * sigmask will have been stored in the signal frame,
847 * and will be restored by sigreturn, so we can simply
848 * clear the TS_RESTORE_SIGMASK flag.
849 */
850 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
851 }
852 return; 838 return;
853 } 839 }
854 if (restart_syscall && 840 if (restart_syscall &&
@@ -872,10 +858,7 @@ void do_signal32(sigset_t *oldset, struct pt_regs * regs)
872 /* If there's no signal to deliver, we just put the saved sigmask 858 /* If there's no signal to deliver, we just put the saved sigmask
873 * back 859 * back
874 */ 860 */
875 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 861 restore_saved_sigmask();
876 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
877 set_current_blocked(&current->saved_sigmask);
878 }
879} 862}
880 863
881struct sigstack32 { 864struct sigstack32 {
diff --git a/arch/sparc/kernel/signal_32.c b/arch/sparc/kernel/signal_32.c
index 2b7e849f7c65..68f9c8650af4 100644
--- a/arch/sparc/kernel/signal_32.c
+++ b/arch/sparc/kernel/signal_32.c
@@ -29,8 +29,6 @@
29 29
30#include "sigutil.h" 30#include "sigutil.h"
31 31
32#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
33
34extern void fpsave(unsigned long *fpregs, unsigned long *fsr, 32extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
35 void *fpqueue, unsigned long *fpqdepth); 33 void *fpqueue, unsigned long *fpqdepth);
36extern void fpload(unsigned long *fpregs, unsigned long *fsr); 34extern void fpload(unsigned long *fpregs, unsigned long *fsr);
@@ -130,7 +128,6 @@ asmlinkage void do_sigreturn(struct pt_regs *regs)
130 if (err) 128 if (err)
131 goto segv_and_exit; 129 goto segv_and_exit;
132 130
133 sigdelsetmask(&set, ~_BLOCKABLE);
134 set_current_blocked(&set); 131 set_current_blocked(&set);
135 return; 132 return;
136 133
@@ -197,7 +194,6 @@ asmlinkage void do_rt_sigreturn(struct pt_regs *regs)
197 goto segv; 194 goto segv;
198 } 195 }
199 196
200 sigdelsetmask(&set, ~_BLOCKABLE);
201 set_current_blocked(&set); 197 set_current_blocked(&set);
202 return; 198 return;
203segv: 199segv:
@@ -449,10 +445,11 @@ sigsegv:
449 return -EFAULT; 445 return -EFAULT;
450} 446}
451 447
452static inline int 448static inline void
453handle_signal(unsigned long signr, struct k_sigaction *ka, 449handle_signal(unsigned long signr, struct k_sigaction *ka,
454 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) 450 siginfo_t *info, struct pt_regs *regs)
455{ 451{
452 sigset_t *oldset = sigmask_to_save();
456 int err; 453 int err;
457 454
458 if (ka->sa.sa_flags & SA_SIGINFO) 455 if (ka->sa.sa_flags & SA_SIGINFO)
@@ -461,12 +458,9 @@ handle_signal(unsigned long signr, struct k_sigaction *ka,
461 err = setup_frame(ka, regs, signr, oldset); 458 err = setup_frame(ka, regs, signr, oldset);
462 459
463 if (err) 460 if (err)
464 return err; 461 return;
465
466 block_sigmask(ka, signr);
467 tracehook_signal_handler(signr, info, ka, regs, 0);
468 462
469 return 0; 463 signal_delivered(signr, info, ka, regs, 0);
470} 464}
471 465
472static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs, 466static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
@@ -498,7 +492,6 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
498{ 492{
499 struct k_sigaction ka; 493 struct k_sigaction ka;
500 int restart_syscall; 494 int restart_syscall;
501 sigset_t *oldset;
502 siginfo_t info; 495 siginfo_t info;
503 int signr; 496 int signr;
504 497
@@ -523,11 +516,6 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
523 if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C)) 516 if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C))
524 regs->u_regs[UREG_G6] = orig_i0; 517 regs->u_regs[UREG_G6] = orig_i0;
525 518
526 if (test_thread_flag(TIF_RESTORE_SIGMASK))
527 oldset = &current->saved_sigmask;
528 else
529 oldset = &current->blocked;
530
531 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 519 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
532 520
533 /* If the debugger messes with the program counter, it clears 521 /* If the debugger messes with the program counter, it clears
@@ -544,15 +532,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
544 if (signr > 0) { 532 if (signr > 0) {
545 if (restart_syscall) 533 if (restart_syscall)
546 syscall_restart(orig_i0, regs, &ka.sa); 534 syscall_restart(orig_i0, regs, &ka.sa);
547 if (handle_signal(signr, &ka, &info, oldset, regs) == 0) { 535 handle_signal(signr, &ka, &info, regs);
548 /* a signal was successfully delivered; the saved
549 * sigmask will have been stored in the signal frame,
550 * and will be restored by sigreturn, so we can simply
551 * clear the TIF_RESTORE_SIGMASK flag.
552 */
553 if (test_thread_flag(TIF_RESTORE_SIGMASK))
554 clear_thread_flag(TIF_RESTORE_SIGMASK);
555 }
556 return; 536 return;
557 } 537 }
558 if (restart_syscall && 538 if (restart_syscall &&
@@ -576,22 +556,17 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
576 /* if there's no signal to deliver, we just put the saved sigmask 556 /* if there's no signal to deliver, we just put the saved sigmask
577 * back 557 * back
578 */ 558 */
579 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 559 restore_saved_sigmask();
580 clear_thread_flag(TIF_RESTORE_SIGMASK);
581 set_current_blocked(&current->saved_sigmask);
582 }
583} 560}
584 561
585void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, 562void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0,
586 unsigned long thread_info_flags) 563 unsigned long thread_info_flags)
587{ 564{
588 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 565 if (thread_info_flags & _TIF_SIGPENDING)
589 do_signal(regs, orig_i0); 566 do_signal(regs, orig_i0);
590 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 567 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
591 clear_thread_flag(TIF_NOTIFY_RESUME); 568 clear_thread_flag(TIF_NOTIFY_RESUME);
592 tracehook_notify_resume(regs); 569 tracehook_notify_resume(regs);
593 if (current->replacement_session_keyring)
594 key_replace_session_keyring();
595 } 570 }
596} 571}
597 572
diff --git a/arch/sparc/kernel/signal_64.c b/arch/sparc/kernel/signal_64.c
index eafaab486b2d..867de2f8189c 100644
--- a/arch/sparc/kernel/signal_64.c
+++ b/arch/sparc/kernel/signal_64.c
@@ -38,8 +38,6 @@
38#include "systbls.h" 38#include "systbls.h"
39#include "sigutil.h" 39#include "sigutil.h"
40 40
41#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
42
43/* {set, get}context() needed for 64-bit SparcLinux userland. */ 41/* {set, get}context() needed for 64-bit SparcLinux userland. */
44asmlinkage void sparc64_set_context(struct pt_regs *regs) 42asmlinkage void sparc64_set_context(struct pt_regs *regs)
45{ 43{
@@ -71,7 +69,6 @@ asmlinkage void sparc64_set_context(struct pt_regs *regs)
71 if (__copy_from_user(&set, &ucp->uc_sigmask, sizeof(sigset_t))) 69 if (__copy_from_user(&set, &ucp->uc_sigmask, sizeof(sigset_t)))
72 goto do_sigsegv; 70 goto do_sigsegv;
73 } 71 }
74 sigdelsetmask(&set, ~_BLOCKABLE);
75 set_current_blocked(&set); 72 set_current_blocked(&set);
76 } 73 }
77 if (test_thread_flag(TIF_32BIT)) { 74 if (test_thread_flag(TIF_32BIT)) {
@@ -315,7 +312,6 @@ void do_rt_sigreturn(struct pt_regs *regs)
315 /* Prevent syscall restart. */ 312 /* Prevent syscall restart. */
316 pt_regs_clear_syscall(regs); 313 pt_regs_clear_syscall(regs);
317 314
318 sigdelsetmask(&set, ~_BLOCKABLE);
319 set_current_blocked(&set); 315 set_current_blocked(&set);
320 return; 316 return;
321segv: 317segv:
@@ -466,7 +462,7 @@ sigsegv:
466 return -EFAULT; 462 return -EFAULT;
467} 463}
468 464
469static inline int handle_signal(unsigned long signr, struct k_sigaction *ka, 465static inline void handle_signal(unsigned long signr, struct k_sigaction *ka,
470 siginfo_t *info, 466 siginfo_t *info,
471 sigset_t *oldset, struct pt_regs *regs) 467 sigset_t *oldset, struct pt_regs *regs)
472{ 468{
@@ -475,12 +471,9 @@ static inline int handle_signal(unsigned long signr, struct k_sigaction *ka,
475 err = setup_rt_frame(ka, regs, signr, oldset, 471 err = setup_rt_frame(ka, regs, signr, oldset,
476 (ka->sa.sa_flags & SA_SIGINFO) ? info : NULL); 472 (ka->sa.sa_flags & SA_SIGINFO) ? info : NULL);
477 if (err) 473 if (err)
478 return err; 474 return;
479
480 block_sigmask(ka, signr);
481 tracehook_signal_handler(signr, info, ka, regs, 0);
482 475
483 return 0; 476 signal_delivered(signr, info, ka, regs, 0);
484} 477}
485 478
486static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs, 479static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
@@ -512,7 +505,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
512{ 505{
513 struct k_sigaction ka; 506 struct k_sigaction ka;
514 int restart_syscall; 507 int restart_syscall;
515 sigset_t *oldset; 508 sigset_t *oldset = sigmask_to_save();
516 siginfo_t info; 509 siginfo_t info;
517 int signr; 510 int signr;
518 511
@@ -538,11 +531,6 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
538 (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY))) 531 (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY)))
539 regs->u_regs[UREG_G6] = orig_i0; 532 regs->u_regs[UREG_G6] = orig_i0;
540 533
541 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
542 oldset = &current->saved_sigmask;
543 else
544 oldset = &current->blocked;
545
546#ifdef CONFIG_COMPAT 534#ifdef CONFIG_COMPAT
547 if (test_thread_flag(TIF_32BIT)) { 535 if (test_thread_flag(TIF_32BIT)) {
548 extern void do_signal32(sigset_t *, struct pt_regs *); 536 extern void do_signal32(sigset_t *, struct pt_regs *);
@@ -563,14 +551,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
563 if (signr > 0) { 551 if (signr > 0) {
564 if (restart_syscall) 552 if (restart_syscall)
565 syscall_restart(orig_i0, regs, &ka.sa); 553 syscall_restart(orig_i0, regs, &ka.sa);
566 if (handle_signal(signr, &ka, &info, oldset, regs) == 0) { 554 handle_signal(signr, &ka, &info, oldset, regs);
567 /* A signal was successfully delivered; the saved
568 * sigmask will have been stored in the signal frame,
569 * and will be restored by sigreturn, so we can simply
570 * clear the TS_RESTORE_SIGMASK flag.
571 */
572 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
573 }
574 return; 555 return;
575 } 556 }
576 if (restart_syscall && 557 if (restart_syscall &&
@@ -594,10 +575,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
594 /* If there's no signal to deliver, we just put the saved sigmask 575 /* If there's no signal to deliver, we just put the saved sigmask
595 * back 576 * back
596 */ 577 */
597 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 578 restore_saved_sigmask();
598 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
599 set_current_blocked(&current->saved_sigmask);
600 }
601} 579}
602 580
603void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags) 581void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags)
@@ -607,8 +585,6 @@ void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long
607 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 585 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
608 clear_thread_flag(TIF_NOTIFY_RESUME); 586 clear_thread_flag(TIF_NOTIFY_RESUME);
609 tracehook_notify_resume(regs); 587 tracehook_notify_resume(regs);
610 if (current->replacement_session_keyring)
611 key_replace_session_keyring();
612 } 588 }
613} 589}
614 590
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 3ee51f189a55..275f74fd6f6a 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -580,16 +580,9 @@ SYSCALL_DEFINE5(64_mremap, unsigned long, addr, unsigned long, old_len,
580 unsigned long, new_len, unsigned long, flags, 580 unsigned long, new_len, unsigned long, flags,
581 unsigned long, new_addr) 581 unsigned long, new_addr)
582{ 582{
583 unsigned long ret = -EINVAL;
584
585 if (test_thread_flag(TIF_32BIT)) 583 if (test_thread_flag(TIF_32BIT))
586 goto out; 584 return -EINVAL;
587 585 return sys_mremap(addr, old_len, new_len, flags, new_addr);
588 down_write(&current->mm->mmap_sem);
589 ret = do_mremap(addr, old_len, new_len, flags, new_addr);
590 up_write(&current->mm->mmap_sem);
591out:
592 return ret;
593} 586}
594 587
595/* we come to here via sys_nis_syscall so it can setup the regs argument */ 588/* we come to here via sys_nis_syscall so it can setup the regs argument */
diff --git a/arch/tile/include/asm/compat.h b/arch/tile/include/asm/compat.h
index 69adc08d36a5..6e74450ff0a1 100644
--- a/arch/tile/include/asm/compat.h
+++ b/arch/tile/include/asm/compat.h
@@ -44,7 +44,6 @@ typedef __kernel_uid32_t __compat_gid32_t;
44typedef __kernel_mode_t compat_mode_t; 44typedef __kernel_mode_t compat_mode_t;
45typedef __kernel_dev_t compat_dev_t; 45typedef __kernel_dev_t compat_dev_t;
46typedef __kernel_loff_t compat_loff_t; 46typedef __kernel_loff_t compat_loff_t;
47typedef __kernel_nlink_t compat_nlink_t;
48typedef __kernel_ipc_pid_t compat_ipc_pid_t; 47typedef __kernel_ipc_pid_t compat_ipc_pid_t;
49typedef __kernel_daddr_t compat_daddr_t; 48typedef __kernel_daddr_t compat_daddr_t;
50typedef __kernel_fsid_t compat_fsid_t; 49typedef __kernel_fsid_t compat_fsid_t;
diff --git a/arch/tile/include/asm/thread_info.h b/arch/tile/include/asm/thread_info.h
index 656c486e64fa..7e1fef36bde6 100644
--- a/arch/tile/include/asm/thread_info.h
+++ b/arch/tile/include/asm/thread_info.h
@@ -166,7 +166,23 @@ static inline void set_restore_sigmask(void)
166{ 166{
167 struct thread_info *ti = current_thread_info(); 167 struct thread_info *ti = current_thread_info();
168 ti->status |= TS_RESTORE_SIGMASK; 168 ti->status |= TS_RESTORE_SIGMASK;
169 set_bit(TIF_SIGPENDING, &ti->flags); 169 WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
170}
171static inline void clear_restore_sigmask(void)
172{
173 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
174}
175static inline bool test_restore_sigmask(void)
176{
177 return current_thread_info()->status & TS_RESTORE_SIGMASK;
178}
179static inline bool test_and_clear_restore_sigmask(void)
180{
181 struct thread_info *ti = current_thread_info();
182 if (!(ti->status & TS_RESTORE_SIGMASK))
183 return false;
184 ti->status &= ~TS_RESTORE_SIGMASK;
185 return true;
170} 186}
171#endif /* !__ASSEMBLY__ */ 187#endif /* !__ASSEMBLY__ */
172 188
diff --git a/arch/tile/kernel/compat_signal.c b/arch/tile/kernel/compat_signal.c
index cdef6e5ec022..474571b84085 100644
--- a/arch/tile/kernel/compat_signal.c
+++ b/arch/tile/kernel/compat_signal.c
@@ -118,8 +118,6 @@ struct compat_rt_sigframe {
118 struct compat_ucontext uc; 118 struct compat_ucontext uc;
119}; 119};
120 120
121#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
122
123long compat_sys_rt_sigaction(int sig, struct compat_sigaction __user *act, 121long compat_sys_rt_sigaction(int sig, struct compat_sigaction __user *act,
124 struct compat_sigaction __user *oact, 122 struct compat_sigaction __user *oact,
125 size_t sigsetsize) 123 size_t sigsetsize)
@@ -302,7 +300,6 @@ long compat_sys_rt_sigreturn(struct pt_regs *regs)
302 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 300 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
303 goto badframe; 301 goto badframe;
304 302
305 sigdelsetmask(&set, ~_BLOCKABLE);
306 set_current_blocked(&set); 303 set_current_blocked(&set);
307 304
308 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 305 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c
index ba1023d8a021..6be799150501 100644
--- a/arch/tile/kernel/process.c
+++ b/arch/tile/kernel/process.c
@@ -565,8 +565,6 @@ int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
565 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 565 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
566 clear_thread_flag(TIF_NOTIFY_RESUME); 566 clear_thread_flag(TIF_NOTIFY_RESUME);
567 tracehook_notify_resume(regs); 567 tracehook_notify_resume(regs);
568 if (current->replacement_session_keyring)
569 key_replace_session_keyring();
570 return 1; 568 return 1;
571 } 569 }
572 if (thread_info_flags & _TIF_SINGLESTEP) { 570 if (thread_info_flags & _TIF_SINGLESTEP) {
diff --git a/arch/tile/kernel/signal.c b/arch/tile/kernel/signal.c
index f79d4b88c747..e29b0553211d 100644
--- a/arch/tile/kernel/signal.c
+++ b/arch/tile/kernel/signal.c
@@ -37,8 +37,6 @@
37 37
38#define DEBUG_SIG 0 38#define DEBUG_SIG 0
39 39
40#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
41
42SYSCALL_DEFINE3(sigaltstack, const stack_t __user *, uss, 40SYSCALL_DEFINE3(sigaltstack, const stack_t __user *, uss,
43 stack_t __user *, uoss, struct pt_regs *, regs) 41 stack_t __user *, uoss, struct pt_regs *, regs)
44{ 42{
@@ -96,7 +94,6 @@ SYSCALL_DEFINE1(rt_sigreturn, struct pt_regs *, regs)
96 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 94 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
97 goto badframe; 95 goto badframe;
98 96
99 sigdelsetmask(&set, ~_BLOCKABLE);
100 set_current_blocked(&set); 97 set_current_blocked(&set);
101 98
102 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 99 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -242,10 +239,11 @@ give_sigsegv:
242 * OK, we're invoking a handler 239 * OK, we're invoking a handler
243 */ 240 */
244 241
245static int handle_signal(unsigned long sig, siginfo_t *info, 242static void handle_signal(unsigned long sig, siginfo_t *info,
246 struct k_sigaction *ka, sigset_t *oldset, 243 struct k_sigaction *ka,
247 struct pt_regs *regs) 244 struct pt_regs *regs)
248{ 245{
246 sigset_t *oldset = sigmask_to_save();
249 int ret; 247 int ret;
250 248
251 /* Are we from a system call? */ 249 /* Are we from a system call? */
@@ -278,15 +276,9 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
278 else 276 else
279#endif 277#endif
280 ret = setup_rt_frame(sig, ka, info, oldset, regs); 278 ret = setup_rt_frame(sig, ka, info, oldset, regs);
281 if (ret == 0) { 279 if (ret)
282 /* This code is only called from system calls or from 280 return;
283 * the work_pending path in the return-to-user code, and 281 signal_delivered(sig, info, ka, regs, 0);
284 * either way we can re-enable interrupts unconditionally.
285 */
286 block_sigmask(ka, sig);
287 }
288
289 return ret;
290} 282}
291 283
292/* 284/*
@@ -299,7 +291,6 @@ void do_signal(struct pt_regs *regs)
299 siginfo_t info; 291 siginfo_t info;
300 int signr; 292 int signr;
301 struct k_sigaction ka; 293 struct k_sigaction ka;
302 sigset_t *oldset;
303 294
304 /* 295 /*
305 * i386 will check if we're coming from kernel mode and bail out 296 * i386 will check if we're coming from kernel mode and bail out
@@ -308,24 +299,10 @@ void do_signal(struct pt_regs *regs)
308 * helpful, we can reinstate the check on "!user_mode(regs)". 299 * helpful, we can reinstate the check on "!user_mode(regs)".
309 */ 300 */
310 301
311 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
312 oldset = &current->saved_sigmask;
313 else
314 oldset = &current->blocked;
315
316 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 302 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
317 if (signr > 0) { 303 if (signr > 0) {
318 /* Whee! Actually deliver the signal. */ 304 /* Whee! Actually deliver the signal. */
319 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 305 handle_signal(signr, &info, &ka, regs);
320 /*
321 * A signal was successfully delivered; the saved
322 * sigmask will have been stored in the signal frame,
323 * and will be restored by sigreturn, so we can simply
324 * clear the TS_RESTORE_SIGMASK flag.
325 */
326 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
327 }
328
329 goto done; 306 goto done;
330 } 307 }
331 308
@@ -350,10 +327,7 @@ void do_signal(struct pt_regs *regs)
350 } 327 }
351 328
352 /* If there's no signal to deliver, just put the saved sigmask back. */ 329 /* If there's no signal to deliver, just put the saved sigmask back. */
353 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 330 restore_saved_sigmask();
354 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
355 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
356 }
357 331
358done: 332done:
359 /* Avoid double syscall restart if there are nested signals. */ 333 /* Avoid double syscall restart if there are nested signals. */
diff --git a/arch/um/include/shared/frame_kern.h b/arch/um/include/shared/frame_kern.h
index 76078490c258..e584e40ee832 100644
--- a/arch/um/include/shared/frame_kern.h
+++ b/arch/um/include/shared/frame_kern.h
@@ -6,9 +6,6 @@
6#ifndef __FRAME_KERN_H_ 6#ifndef __FRAME_KERN_H_
7#define __FRAME_KERN_H_ 7#define __FRAME_KERN_H_
8 8
9#define _S(nr) (1<<((nr)-1))
10#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
11
12extern int setup_signal_stack_sc(unsigned long stack_top, int sig, 9extern int setup_signal_stack_sc(unsigned long stack_top, int sig,
13 struct k_sigaction *ka, 10 struct k_sigaction *ka,
14 struct pt_regs *regs, 11 struct pt_regs *regs,
diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
index 3a2235e0abc3..ccb9a9d283f1 100644
--- a/arch/um/kernel/process.c
+++ b/arch/um/kernel/process.c
@@ -117,11 +117,8 @@ void interrupt_end(void)
117 schedule(); 117 schedule();
118 if (test_thread_flag(TIF_SIGPENDING)) 118 if (test_thread_flag(TIF_SIGPENDING))
119 do_signal(); 119 do_signal();
120 if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME)) { 120 if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
121 tracehook_notify_resume(&current->thread.regs); 121 tracehook_notify_resume(&current->thread.regs);
122 if (current->replacement_session_keyring)
123 key_replace_session_keyring();
124 }
125} 122}
126 123
127void exit_thread(void) 124void exit_thread(void)
diff --git a/arch/um/kernel/reboot.c b/arch/um/kernel/reboot.c
index 4d93dff6b371..3d15243ce692 100644
--- a/arch/um/kernel/reboot.c
+++ b/arch/um/kernel/reboot.c
@@ -4,7 +4,9 @@
4 */ 4 */
5 5
6#include "linux/sched.h" 6#include "linux/sched.h"
7#include "linux/spinlock.h"
7#include "linux/slab.h" 8#include "linux/slab.h"
9#include "linux/oom.h"
8#include "kern_util.h" 10#include "kern_util.h"
9#include "os.h" 11#include "os.h"
10#include "skas.h" 12#include "skas.h"
@@ -22,13 +24,18 @@ static void kill_off_processes(void)
22 struct task_struct *p; 24 struct task_struct *p;
23 int pid; 25 int pid;
24 26
27 read_lock(&tasklist_lock);
25 for_each_process(p) { 28 for_each_process(p) {
26 if (p->mm == NULL) 29 struct task_struct *t;
27 continue;
28 30
29 pid = p->mm->context.id.u.pid; 31 t = find_lock_task_mm(p);
32 if (!t)
33 continue;
34 pid = t->mm->context.id.u.pid;
35 task_unlock(t);
30 os_kill_ptraced_process(pid, 1); 36 os_kill_ptraced_process(pid, 1);
31 } 37 }
38 read_unlock(&tasklist_lock);
32 } 39 }
33} 40}
34 41
diff --git a/arch/um/kernel/signal.c b/arch/um/kernel/signal.c
index 292e706016c5..7362d58efc29 100644
--- a/arch/um/kernel/signal.c
+++ b/arch/um/kernel/signal.c
@@ -15,17 +15,13 @@
15EXPORT_SYMBOL(block_signals); 15EXPORT_SYMBOL(block_signals);
16EXPORT_SYMBOL(unblock_signals); 16EXPORT_SYMBOL(unblock_signals);
17 17
18#define _S(nr) (1<<((nr)-1))
19
20#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
21
22/* 18/*
23 * OK, we're invoking a handler 19 * OK, we're invoking a handler
24 */ 20 */
25static int handle_signal(struct pt_regs *regs, unsigned long signr, 21static void handle_signal(struct pt_regs *regs, unsigned long signr,
26 struct k_sigaction *ka, siginfo_t *info, 22 struct k_sigaction *ka, siginfo_t *info)
27 sigset_t *oldset)
28{ 23{
24 sigset_t *oldset = sigmask_to_save();
29 unsigned long sp; 25 unsigned long sp;
30 int err; 26 int err;
31 27
@@ -65,9 +61,7 @@ static int handle_signal(struct pt_regs *regs, unsigned long signr,
65 if (err) 61 if (err)
66 force_sigsegv(signr, current); 62 force_sigsegv(signr, current);
67 else 63 else
68 block_sigmask(ka, signr); 64 signal_delivered(signr, info, ka, regs, 0);
69
70 return err;
71} 65}
72 66
73static int kern_do_signal(struct pt_regs *regs) 67static int kern_do_signal(struct pt_regs *regs)
@@ -77,24 +71,9 @@ static int kern_do_signal(struct pt_regs *regs)
77 int sig, handled_sig = 0; 71 int sig, handled_sig = 0;
78 72
79 while ((sig = get_signal_to_deliver(&info, &ka_copy, regs, NULL)) > 0) { 73 while ((sig = get_signal_to_deliver(&info, &ka_copy, regs, NULL)) > 0) {
80 sigset_t *oldset;
81 if (test_thread_flag(TIF_RESTORE_SIGMASK))
82 oldset = &current->saved_sigmask;
83 else
84 oldset = &current->blocked;
85 handled_sig = 1; 74 handled_sig = 1;
86 /* Whee! Actually deliver the signal. */ 75 /* Whee! Actually deliver the signal. */
87 if (!handle_signal(regs, sig, &ka_copy, &info, oldset)) { 76 handle_signal(regs, sig, &ka_copy, &info);
88 /*
89 * a signal was successfully delivered; the saved
90 * sigmask will have been stored in the signal frame,
91 * and will be restored by sigreturn, so we can simply
92 * clear the TIF_RESTORE_SIGMASK flag
93 */
94 if (test_thread_flag(TIF_RESTORE_SIGMASK))
95 clear_thread_flag(TIF_RESTORE_SIGMASK);
96 break;
97 }
98 } 77 }
99 78
100 /* Did we come from a system call? */ 79 /* Did we come from a system call? */
@@ -130,10 +109,8 @@ static int kern_do_signal(struct pt_regs *regs)
130 * if there's no signal to deliver, we just put the saved sigmask 109 * if there's no signal to deliver, we just put the saved sigmask
131 * back 110 * back
132 */ 111 */
133 if (!handled_sig && test_thread_flag(TIF_RESTORE_SIGMASK)) { 112 if (!handled_sig)
134 clear_thread_flag(TIF_RESTORE_SIGMASK); 113 restore_saved_sigmask();
135 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
136 }
137 return handled_sig; 114 return handled_sig;
138} 115}
139 116
diff --git a/arch/um/kernel/trap.c b/arch/um/kernel/trap.c
index dafc94715950..3be60765c0e2 100644
--- a/arch/um/kernel/trap.c
+++ b/arch/um/kernel/trap.c
@@ -30,6 +30,8 @@ int handle_page_fault(unsigned long address, unsigned long ip,
30 pmd_t *pmd; 30 pmd_t *pmd;
31 pte_t *pte; 31 pte_t *pte;
32 int err = -EFAULT; 32 int err = -EFAULT;
33 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
34 (is_write ? FAULT_FLAG_WRITE : 0);
33 35
34 *code_out = SEGV_MAPERR; 36 *code_out = SEGV_MAPERR;
35 37
@@ -40,6 +42,7 @@ int handle_page_fault(unsigned long address, unsigned long ip,
40 if (in_atomic()) 42 if (in_atomic())
41 goto out_nosemaphore; 43 goto out_nosemaphore;
42 44
45retry:
43 down_read(&mm->mmap_sem); 46 down_read(&mm->mmap_sem);
44 vma = find_vma(mm, address); 47 vma = find_vma(mm, address);
45 if (!vma) 48 if (!vma)
@@ -65,7 +68,11 @@ good_area:
65 do { 68 do {
66 int fault; 69 int fault;
67 70
68 fault = handle_mm_fault(mm, vma, address, is_write ? FAULT_FLAG_WRITE : 0); 71 fault = handle_mm_fault(mm, vma, address, flags);
72
73 if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
74 goto out_nosemaphore;
75
69 if (unlikely(fault & VM_FAULT_ERROR)) { 76 if (unlikely(fault & VM_FAULT_ERROR)) {
70 if (fault & VM_FAULT_OOM) { 77 if (fault & VM_FAULT_OOM) {
71 goto out_of_memory; 78 goto out_of_memory;
@@ -75,10 +82,17 @@ good_area:
75 } 82 }
76 BUG(); 83 BUG();
77 } 84 }
78 if (fault & VM_FAULT_MAJOR) 85 if (flags & FAULT_FLAG_ALLOW_RETRY) {
79 current->maj_flt++; 86 if (fault & VM_FAULT_MAJOR)
80 else 87 current->maj_flt++;
81 current->min_flt++; 88 else
89 current->min_flt++;
90 if (fault & VM_FAULT_RETRY) {
91 flags &= ~FAULT_FLAG_ALLOW_RETRY;
92
93 goto retry;
94 }
95 }
82 96
83 pgd = pgd_offset(mm, address); 97 pgd = pgd_offset(mm, address);
84 pud = pud_offset(pgd, address); 98 pud = pud_offset(pgd, address);
diff --git a/arch/unicore32/kernel/signal.c b/arch/unicore32/kernel/signal.c
index 7754df6ef7d4..8adedb37720a 100644
--- a/arch/unicore32/kernel/signal.c
+++ b/arch/unicore32/kernel/signal.c
@@ -21,8 +21,6 @@
21#include <asm/cacheflush.h> 21#include <asm/cacheflush.h>
22#include <asm/ucontext.h> 22#include <asm/ucontext.h>
23 23
24#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
25
26/* 24/*
27 * For UniCore syscalls, we encode the syscall number into the instruction. 25 * For UniCore syscalls, we encode the syscall number into the instruction.
28 */ 26 */
@@ -61,10 +59,8 @@ static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
61 int err; 59 int err;
62 60
63 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set)); 61 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
64 if (err == 0) { 62 if (err == 0)
65 sigdelsetmask(&set, ~_BLOCKABLE);
66 set_current_blocked(&set); 63 set_current_blocked(&set);
67 }
68 64
69 err |= __get_user(regs->UCreg_00, &sf->uc.uc_mcontext.regs.UCreg_00); 65 err |= __get_user(regs->UCreg_00, &sf->uc.uc_mcontext.regs.UCreg_00);
70 err |= __get_user(regs->UCreg_01, &sf->uc.uc_mcontext.regs.UCreg_01); 66 err |= __get_user(regs->UCreg_01, &sf->uc.uc_mcontext.regs.UCreg_01);
@@ -312,13 +308,12 @@ static inline void setup_syscall_restart(struct pt_regs *regs)
312/* 308/*
313 * OK, we're invoking a handler 309 * OK, we're invoking a handler
314 */ 310 */
315static int handle_signal(unsigned long sig, struct k_sigaction *ka, 311static void handle_signal(unsigned long sig, struct k_sigaction *ka,
316 siginfo_t *info, sigset_t *oldset, 312 siginfo_t *info, struct pt_regs *regs, int syscall)
317 struct pt_regs *regs, int syscall)
318{ 313{
319 struct thread_info *thread = current_thread_info(); 314 struct thread_info *thread = current_thread_info();
320 struct task_struct *tsk = current; 315 struct task_struct *tsk = current;
321 sigset_t blocked; 316 sigset_t *oldset = sigmask_to_save();
322 int usig = sig; 317 int usig = sig;
323 int ret; 318 int ret;
324 319
@@ -364,15 +359,10 @@ static int handle_signal(unsigned long sig, struct k_sigaction *ka,
364 359
365 if (ret != 0) { 360 if (ret != 0) {
366 force_sigsegv(sig, tsk); 361 force_sigsegv(sig, tsk);
367 return ret; 362 return;
368 } 363 }
369 364
370 /* 365 signal_delivered(sig, info, ka, regs, 0);
371 * Block the signal if we were successful.
372 */
373 block_sigmask(ka, sig);
374
375 return 0;
376} 366}
377 367
378/* 368/*
@@ -399,32 +389,12 @@ static void do_signal(struct pt_regs *regs, int syscall)
399 if (!user_mode(regs)) 389 if (!user_mode(regs))
400 return; 390 return;
401 391
402 if (try_to_freeze())
403 goto no_signal;
404
405 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 392 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
406 if (signr > 0) { 393 if (signr > 0) {
407 sigset_t *oldset; 394 handle_signal(signr, &ka, &info, regs, syscall);
408
409 if (test_thread_flag(TIF_RESTORE_SIGMASK))
410 oldset = &current->saved_sigmask;
411 else
412 oldset = &current->blocked;
413 if (handle_signal(signr, &ka, &info, oldset, regs, syscall)
414 == 0) {
415 /*
416 * A signal was successfully delivered; the saved
417 * sigmask will have been stored in the signal frame,
418 * and will be restored by sigreturn, so we can simply
419 * clear the TIF_RESTORE_SIGMASK flag.
420 */
421 if (test_thread_flag(TIF_RESTORE_SIGMASK))
422 clear_thread_flag(TIF_RESTORE_SIGMASK);
423 }
424 return; 395 return;
425 } 396 }
426 397
427 no_signal:
428 /* 398 /*
429 * No signal to deliver to the process - restart the syscall. 399 * No signal to deliver to the process - restart the syscall.
430 */ 400 */
@@ -451,8 +421,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
451 /* If there's no signal to deliver, we just put the saved 421 /* If there's no signal to deliver, we just put the saved
452 * sigmask back. 422 * sigmask back.
453 */ 423 */
454 if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK)) 424 restore_saved_sigmask();
455 set_current_blocked(&current->saved_sigmask);
456} 425}
457 426
458asmlinkage void do_notify_resume(struct pt_regs *regs, 427asmlinkage void do_notify_resume(struct pt_regs *regs,
@@ -464,8 +433,6 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,
464 if (thread_flags & _TIF_NOTIFY_RESUME) { 433 if (thread_flags & _TIF_NOTIFY_RESUME) {
465 clear_thread_flag(TIF_NOTIFY_RESUME); 434 clear_thread_flag(TIF_NOTIFY_RESUME);
466 tracehook_notify_resume(regs); 435 tracehook_notify_resume(regs);
467 if (current->replacement_session_keyring)
468 key_replace_session_keyring();
469 } 436 }
470} 437}
471 438
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index d700811785ea..c70684f859e1 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1506,6 +1506,8 @@ config EFI_STUB
1506 This kernel feature allows a bzImage to be loaded directly 1506 This kernel feature allows a bzImage to be loaded directly
1507 by EFI firmware without the use of a bootloader. 1507 by EFI firmware without the use of a bootloader.
1508 1508
1509 See Documentation/x86/efi-stub.txt for more information.
1510
1509config SECCOMP 1511config SECCOMP
1510 def_bool y 1512 def_bool y
1511 prompt "Enable seccomp to safely compute untrusted bytecode" 1513 prompt "Enable seccomp to safely compute untrusted bytecode"
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index 2c14e76bb4c7..4e85f5f85837 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -16,6 +16,26 @@
16 16
17static efi_system_table_t *sys_table; 17static efi_system_table_t *sys_table;
18 18
19static void efi_printk(char *str)
20{
21 char *s8;
22
23 for (s8 = str; *s8; s8++) {
24 struct efi_simple_text_output_protocol *out;
25 efi_char16_t ch[2] = { 0 };
26
27 ch[0] = *s8;
28 out = (struct efi_simple_text_output_protocol *)sys_table->con_out;
29
30 if (*s8 == '\n') {
31 efi_char16_t nl[2] = { '\r', 0 };
32 efi_call_phys2(out->output_string, out, nl);
33 }
34
35 efi_call_phys2(out->output_string, out, ch);
36 }
37}
38
19static efi_status_t __get_map(efi_memory_desc_t **map, unsigned long *map_size, 39static efi_status_t __get_map(efi_memory_desc_t **map, unsigned long *map_size,
20 unsigned long *desc_size) 40 unsigned long *desc_size)
21{ 41{
@@ -531,8 +551,10 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
531 EFI_LOADER_DATA, 551 EFI_LOADER_DATA,
532 nr_initrds * sizeof(*initrds), 552 nr_initrds * sizeof(*initrds),
533 &initrds); 553 &initrds);
534 if (status != EFI_SUCCESS) 554 if (status != EFI_SUCCESS) {
555 efi_printk("Failed to alloc mem for initrds\n");
535 goto fail; 556 goto fail;
557 }
536 558
537 str = (char *)(unsigned long)hdr->cmd_line_ptr; 559 str = (char *)(unsigned long)hdr->cmd_line_ptr;
538 for (i = 0; i < nr_initrds; i++) { 560 for (i = 0; i < nr_initrds; i++) {
@@ -575,32 +597,42 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
575 597
576 status = efi_call_phys3(boottime->handle_protocol, 598 status = efi_call_phys3(boottime->handle_protocol,
577 image->device_handle, &fs_proto, &io); 599 image->device_handle, &fs_proto, &io);
578 if (status != EFI_SUCCESS) 600 if (status != EFI_SUCCESS) {
601 efi_printk("Failed to handle fs_proto\n");
579 goto free_initrds; 602 goto free_initrds;
603 }
580 604
581 status = efi_call_phys2(io->open_volume, io, &fh); 605 status = efi_call_phys2(io->open_volume, io, &fh);
582 if (status != EFI_SUCCESS) 606 if (status != EFI_SUCCESS) {
607 efi_printk("Failed to open volume\n");
583 goto free_initrds; 608 goto free_initrds;
609 }
584 } 610 }
585 611
586 status = efi_call_phys5(fh->open, fh, &h, filename_16, 612 status = efi_call_phys5(fh->open, fh, &h, filename_16,
587 EFI_FILE_MODE_READ, (u64)0); 613 EFI_FILE_MODE_READ, (u64)0);
588 if (status != EFI_SUCCESS) 614 if (status != EFI_SUCCESS) {
615 efi_printk("Failed to open initrd file\n");
589 goto close_handles; 616 goto close_handles;
617 }
590 618
591 initrd->handle = h; 619 initrd->handle = h;
592 620
593 info_sz = 0; 621 info_sz = 0;
594 status = efi_call_phys4(h->get_info, h, &info_guid, 622 status = efi_call_phys4(h->get_info, h, &info_guid,
595 &info_sz, NULL); 623 &info_sz, NULL);
596 if (status != EFI_BUFFER_TOO_SMALL) 624 if (status != EFI_BUFFER_TOO_SMALL) {
625 efi_printk("Failed to get initrd info size\n");
597 goto close_handles; 626 goto close_handles;
627 }
598 628
599grow: 629grow:
600 status = efi_call_phys3(sys_table->boottime->allocate_pool, 630 status = efi_call_phys3(sys_table->boottime->allocate_pool,
601 EFI_LOADER_DATA, info_sz, &info); 631 EFI_LOADER_DATA, info_sz, &info);
602 if (status != EFI_SUCCESS) 632 if (status != EFI_SUCCESS) {
633 efi_printk("Failed to alloc mem for initrd info\n");
603 goto close_handles; 634 goto close_handles;
635 }
604 636
605 status = efi_call_phys4(h->get_info, h, &info_guid, 637 status = efi_call_phys4(h->get_info, h, &info_guid,
606 &info_sz, info); 638 &info_sz, info);
@@ -612,8 +644,10 @@ grow:
612 file_sz = info->file_size; 644 file_sz = info->file_size;
613 efi_call_phys1(sys_table->boottime->free_pool, info); 645 efi_call_phys1(sys_table->boottime->free_pool, info);
614 646
615 if (status != EFI_SUCCESS) 647 if (status != EFI_SUCCESS) {
648 efi_printk("Failed to get initrd info\n");
616 goto close_handles; 649 goto close_handles;
650 }
617 651
618 initrd->size = file_sz; 652 initrd->size = file_sz;
619 initrd_total += file_sz; 653 initrd_total += file_sz;
@@ -629,11 +663,14 @@ grow:
629 */ 663 */
630 status = high_alloc(initrd_total, 0x1000, 664 status = high_alloc(initrd_total, 0x1000,
631 &initrd_addr, hdr->initrd_addr_max); 665 &initrd_addr, hdr->initrd_addr_max);
632 if (status != EFI_SUCCESS) 666 if (status != EFI_SUCCESS) {
667 efi_printk("Failed to alloc highmem for initrds\n");
633 goto close_handles; 668 goto close_handles;
669 }
634 670
635 /* We've run out of free low memory. */ 671 /* We've run out of free low memory. */
636 if (initrd_addr > hdr->initrd_addr_max) { 672 if (initrd_addr > hdr->initrd_addr_max) {
673 efi_printk("We've run out of free low memory\n");
637 status = EFI_INVALID_PARAMETER; 674 status = EFI_INVALID_PARAMETER;
638 goto free_initrd_total; 675 goto free_initrd_total;
639 } 676 }
@@ -652,8 +689,10 @@ grow:
652 status = efi_call_phys3(fh->read, 689 status = efi_call_phys3(fh->read,
653 initrds[j].handle, 690 initrds[j].handle,
654 &chunksize, addr); 691 &chunksize, addr);
655 if (status != EFI_SUCCESS) 692 if (status != EFI_SUCCESS) {
693 efi_printk("Failed to read initrd\n");
656 goto free_initrd_total; 694 goto free_initrd_total;
695 }
657 addr += chunksize; 696 addr += chunksize;
658 size -= chunksize; 697 size -= chunksize;
659 } 698 }
@@ -674,7 +713,7 @@ free_initrd_total:
674 low_free(initrd_total, initrd_addr); 713 low_free(initrd_total, initrd_addr);
675 714
676close_handles: 715close_handles:
677 for (k = j; k < nr_initrds; k++) 716 for (k = j; k < i; k++)
678 efi_call_phys1(fh->close, initrds[k].handle); 717 efi_call_phys1(fh->close, initrds[k].handle);
679free_initrds: 718free_initrds:
680 efi_call_phys1(sys_table->boottime->free_pool, initrds); 719 efi_call_phys1(sys_table->boottime->free_pool, initrds);
@@ -732,8 +771,10 @@ static efi_status_t make_boot_params(struct boot_params *boot_params,
732 options_size++; /* NUL termination */ 771 options_size++; /* NUL termination */
733 772
734 status = low_alloc(options_size, 1, &cmdline); 773 status = low_alloc(options_size, 1, &cmdline);
735 if (status != EFI_SUCCESS) 774 if (status != EFI_SUCCESS) {
775 efi_printk("Failed to alloc mem for cmdline\n");
736 goto fail; 776 goto fail;
777 }
737 778
738 s1 = (u8 *)(unsigned long)cmdline; 779 s1 = (u8 *)(unsigned long)cmdline;
739 s2 = (u16 *)options; 780 s2 = (u16 *)options;
@@ -895,12 +936,16 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
895 936
896 status = efi_call_phys3(sys_table->boottime->handle_protocol, 937 status = efi_call_phys3(sys_table->boottime->handle_protocol,
897 handle, &proto, (void *)&image); 938 handle, &proto, (void *)&image);
898 if (status != EFI_SUCCESS) 939 if (status != EFI_SUCCESS) {
940 efi_printk("Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
899 goto fail; 941 goto fail;
942 }
900 943
901 status = low_alloc(0x4000, 1, (unsigned long *)&boot_params); 944 status = low_alloc(0x4000, 1, (unsigned long *)&boot_params);
902 if (status != EFI_SUCCESS) 945 if (status != EFI_SUCCESS) {
946 efi_printk("Failed to alloc lowmem for boot params\n");
903 goto fail; 947 goto fail;
948 }
904 949
905 memset(boot_params, 0x0, 0x4000); 950 memset(boot_params, 0x0, 0x4000);
906 951
@@ -933,8 +978,10 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
933 if (status != EFI_SUCCESS) { 978 if (status != EFI_SUCCESS) {
934 status = low_alloc(hdr->init_size, hdr->kernel_alignment, 979 status = low_alloc(hdr->init_size, hdr->kernel_alignment,
935 &start); 980 &start);
936 if (status != EFI_SUCCESS) 981 if (status != EFI_SUCCESS) {
982 efi_printk("Failed to alloc mem for kernel\n");
937 goto fail; 983 goto fail;
984 }
938 } 985 }
939 986
940 hdr->code32_start = (__u32)start; 987 hdr->code32_start = (__u32)start;
@@ -945,19 +992,25 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
945 status = efi_call_phys3(sys_table->boottime->allocate_pool, 992 status = efi_call_phys3(sys_table->boottime->allocate_pool,
946 EFI_LOADER_DATA, sizeof(*gdt), 993 EFI_LOADER_DATA, sizeof(*gdt),
947 (void **)&gdt); 994 (void **)&gdt);
948 if (status != EFI_SUCCESS) 995 if (status != EFI_SUCCESS) {
996 efi_printk("Failed to alloc mem for gdt structure\n");
949 goto fail; 997 goto fail;
998 }
950 999
951 gdt->size = 0x800; 1000 gdt->size = 0x800;
952 status = low_alloc(gdt->size, 8, (unsigned long *)&gdt->address); 1001 status = low_alloc(gdt->size, 8, (unsigned long *)&gdt->address);
953 if (status != EFI_SUCCESS) 1002 if (status != EFI_SUCCESS) {
1003 efi_printk("Failed to alloc mem for gdt\n");
954 goto fail; 1004 goto fail;
1005 }
955 1006
956 status = efi_call_phys3(sys_table->boottime->allocate_pool, 1007 status = efi_call_phys3(sys_table->boottime->allocate_pool,
957 EFI_LOADER_DATA, sizeof(*idt), 1008 EFI_LOADER_DATA, sizeof(*idt),
958 (void **)&idt); 1009 (void **)&idt);
959 if (status != EFI_SUCCESS) 1010 if (status != EFI_SUCCESS) {
1011 efi_printk("Failed to alloc mem for idt structure\n");
960 goto fail; 1012 goto fail;
1013 }
961 1014
962 idt->size = 0; 1015 idt->size = 0;
963 idt->address = 0; 1016 idt->address = 0;
diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h
index 39251663e65b..3b6e15627c55 100644
--- a/arch/x86/boot/compressed/eboot.h
+++ b/arch/x86/boot/compressed/eboot.h
@@ -58,4 +58,10 @@ struct efi_uga_draw_protocol {
58 void *blt; 58 void *blt;
59}; 59};
60 60
61struct efi_simple_text_output_protocol {
62 void *reset;
63 void *output_string;
64 void *test_string;
65};
66
61#endif /* BOOT_COMPRESSED_EBOOT_H */ 67#endif /* BOOT_COMPRESSED_EBOOT_H */
diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
index 98bd70faccc5..daeca56211e3 100644
--- a/arch/x86/ia32/ia32_signal.c
+++ b/arch/x86/ia32/ia32_signal.c
@@ -273,7 +273,6 @@ asmlinkage long sys32_sigreturn(struct pt_regs *regs)
273 sizeof(frame->extramask)))) 273 sizeof(frame->extramask))))
274 goto badframe; 274 goto badframe;
275 275
276 sigdelsetmask(&set, ~_BLOCKABLE);
277 set_current_blocked(&set); 276 set_current_blocked(&set);
278 277
279 if (ia32_restore_sigcontext(regs, &frame->sc, &ax)) 278 if (ia32_restore_sigcontext(regs, &frame->sc, &ax))
@@ -299,7 +298,6 @@ asmlinkage long sys32_rt_sigreturn(struct pt_regs *regs)
299 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 298 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
300 goto badframe; 299 goto badframe;
301 300
302 sigdelsetmask(&set, ~_BLOCKABLE);
303 set_current_blocked(&set); 301 set_current_blocked(&set);
304 302
305 if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) 303 if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
diff --git a/arch/x86/include/asm/ftrace.h b/arch/x86/include/asm/ftrace.h
index 18d9005d9e4f..b0767bc08740 100644
--- a/arch/x86/include/asm/ftrace.h
+++ b/arch/x86/include/asm/ftrace.h
@@ -34,7 +34,7 @@
34 34
35#ifndef __ASSEMBLY__ 35#ifndef __ASSEMBLY__
36extern void mcount(void); 36extern void mcount(void);
37extern int modifying_ftrace_code; 37extern atomic_t modifying_ftrace_code;
38 38
39static inline unsigned long ftrace_call_adjust(unsigned long addr) 39static inline unsigned long ftrace_call_adjust(unsigned long addr)
40{ 40{
diff --git a/arch/x86/include/asm/posix_types_32.h b/arch/x86/include/asm/posix_types_32.h
index 99f262e04b91..8e525059e7d8 100644
--- a/arch/x86/include/asm/posix_types_32.h
+++ b/arch/x86/include/asm/posix_types_32.h
@@ -10,9 +10,6 @@
10typedef unsigned short __kernel_mode_t; 10typedef unsigned short __kernel_mode_t;
11#define __kernel_mode_t __kernel_mode_t 11#define __kernel_mode_t __kernel_mode_t
12 12
13typedef unsigned short __kernel_nlink_t;
14#define __kernel_nlink_t __kernel_nlink_t
15
16typedef unsigned short __kernel_ipc_pid_t; 13typedef unsigned short __kernel_ipc_pid_t;
17#define __kernel_ipc_pid_t __kernel_ipc_pid_t 14#define __kernel_ipc_pid_t __kernel_ipc_pid_t
18 15
diff --git a/arch/x86/include/asm/sighandling.h b/arch/x86/include/asm/sighandling.h
index ada93b3b8c66..beff97f7df37 100644
--- a/arch/x86/include/asm/sighandling.h
+++ b/arch/x86/include/asm/sighandling.h
@@ -7,8 +7,6 @@
7 7
8#include <asm/processor-flags.h> 8#include <asm/processor-flags.h>
9 9
10#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
11
12#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \ 10#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
13 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \ 11 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
14 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \ 12 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 5c25de07cba8..89f794f007ec 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -248,7 +248,23 @@ static inline void set_restore_sigmask(void)
248{ 248{
249 struct thread_info *ti = current_thread_info(); 249 struct thread_info *ti = current_thread_info();
250 ti->status |= TS_RESTORE_SIGMASK; 250 ti->status |= TS_RESTORE_SIGMASK;
251 set_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags); 251 WARN_ON(!test_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags));
252}
253static inline void clear_restore_sigmask(void)
254{
255 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
256}
257static inline bool test_restore_sigmask(void)
258{
259 return current_thread_info()->status & TS_RESTORE_SIGMASK;
260}
261static inline bool test_and_clear_restore_sigmask(void)
262{
263 struct thread_info *ti = current_thread_info();
264 if (!(ti->status & TS_RESTORE_SIGMASK))
265 return false;
266 ti->status &= ~TS_RESTORE_SIGMASK;
267 return true;
252} 268}
253 269
254static inline bool is_ia32_task(void) 270static inline bool is_ia32_task(void)
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 82f29e70d058..6b9333b429ba 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1101,14 +1101,20 @@ int is_debug_stack(unsigned long addr)
1101 addr > (__get_cpu_var(debug_stack_addr) - DEBUG_STKSZ)); 1101 addr > (__get_cpu_var(debug_stack_addr) - DEBUG_STKSZ));
1102} 1102}
1103 1103
1104static DEFINE_PER_CPU(u32, debug_stack_use_ctr);
1105
1104void debug_stack_set_zero(void) 1106void debug_stack_set_zero(void)
1105{ 1107{
1108 this_cpu_inc(debug_stack_use_ctr);
1106 load_idt((const struct desc_ptr *)&nmi_idt_descr); 1109 load_idt((const struct desc_ptr *)&nmi_idt_descr);
1107} 1110}
1108 1111
1109void debug_stack_reset(void) 1112void debug_stack_reset(void)
1110{ 1113{
1111 load_idt((const struct desc_ptr *)&idt_descr); 1114 if (WARN_ON(!this_cpu_read(debug_stack_use_ctr)))
1115 return;
1116 if (this_cpu_dec_return(debug_stack_use_ctr) == 0)
1117 load_idt((const struct desc_ptr *)&idt_descr);
1112} 1118}
1113 1119
1114#else /* CONFIG_X86_64 */ 1120#else /* CONFIG_X86_64 */
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
index 01ccf9b71473..623f28837476 100644
--- a/arch/x86/kernel/entry_32.S
+++ b/arch/x86/kernel/entry_32.S
@@ -316,7 +316,6 @@ ret_from_exception:
316 preempt_stop(CLBR_ANY) 316 preempt_stop(CLBR_ANY)
317ret_from_intr: 317ret_from_intr:
318 GET_THREAD_INFO(%ebp) 318 GET_THREAD_INFO(%ebp)
319resume_userspace_sig:
320#ifdef CONFIG_VM86 319#ifdef CONFIG_VM86
321 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS 320 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
322 movb PT_CS(%esp), %al 321 movb PT_CS(%esp), %al
@@ -615,9 +614,13 @@ work_notifysig: # deal with pending signals and
615 # vm86-space 614 # vm86-space
616 TRACE_IRQS_ON 615 TRACE_IRQS_ON
617 ENABLE_INTERRUPTS(CLBR_NONE) 616 ENABLE_INTERRUPTS(CLBR_NONE)
617 movb PT_CS(%esp), %bl
618 andb $SEGMENT_RPL_MASK, %bl
619 cmpb $USER_RPL, %bl
620 jb resume_kernel
618 xorl %edx, %edx 621 xorl %edx, %edx
619 call do_notify_resume 622 call do_notify_resume
620 jmp resume_userspace_sig 623 jmp resume_userspace
621 624
622 ALIGN 625 ALIGN
623work_notifysig_v86: 626work_notifysig_v86:
@@ -630,9 +633,13 @@ work_notifysig_v86:
630#endif 633#endif
631 TRACE_IRQS_ON 634 TRACE_IRQS_ON
632 ENABLE_INTERRUPTS(CLBR_NONE) 635 ENABLE_INTERRUPTS(CLBR_NONE)
636 movb PT_CS(%esp), %bl
637 andb $SEGMENT_RPL_MASK, %bl
638 cmpb $USER_RPL, %bl
639 jb resume_kernel
633 xorl %edx, %edx 640 xorl %edx, %edx
634 call do_notify_resume 641 call do_notify_resume
635 jmp resume_userspace_sig 642 jmp resume_userspace
636END(work_pending) 643END(work_pending)
637 644
638 # perform syscall exit tracing 645 # perform syscall exit tracing
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 320852d02026..7d65133b51be 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -191,6 +191,44 @@ ENDPROC(native_usergs_sysret64)
191.endm 191.endm
192 192
193/* 193/*
194 * When dynamic function tracer is enabled it will add a breakpoint
195 * to all locations that it is about to modify, sync CPUs, update
196 * all the code, sync CPUs, then remove the breakpoints. In this time
197 * if lockdep is enabled, it might jump back into the debug handler
198 * outside the updating of the IST protection. (TRACE_IRQS_ON/OFF).
199 *
200 * We need to change the IDT table before calling TRACE_IRQS_ON/OFF to
201 * make sure the stack pointer does not get reset back to the top
202 * of the debug stack, and instead just reuses the current stack.
203 */
204#if defined(CONFIG_DYNAMIC_FTRACE) && defined(CONFIG_TRACE_IRQFLAGS)
205
206.macro TRACE_IRQS_OFF_DEBUG
207 call debug_stack_set_zero
208 TRACE_IRQS_OFF
209 call debug_stack_reset
210.endm
211
212.macro TRACE_IRQS_ON_DEBUG
213 call debug_stack_set_zero
214 TRACE_IRQS_ON
215 call debug_stack_reset
216.endm
217
218.macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
219 bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
220 jnc 1f
221 TRACE_IRQS_ON_DEBUG
2221:
223.endm
224
225#else
226# define TRACE_IRQS_OFF_DEBUG TRACE_IRQS_OFF
227# define TRACE_IRQS_ON_DEBUG TRACE_IRQS_ON
228# define TRACE_IRQS_IRETQ_DEBUG TRACE_IRQS_IRETQ
229#endif
230
231/*
194 * C code is not supposed to know about undefined top of stack. Every time 232 * C code is not supposed to know about undefined top of stack. Every time
195 * a C function with an pt_regs argument is called from the SYSCALL based 233 * a C function with an pt_regs argument is called from the SYSCALL based
196 * fast path FIXUP_TOP_OF_STACK is needed. 234 * fast path FIXUP_TOP_OF_STACK is needed.
@@ -1098,7 +1136,7 @@ ENTRY(\sym)
1098 subq $ORIG_RAX-R15, %rsp 1136 subq $ORIG_RAX-R15, %rsp
1099 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15 1137 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
1100 call save_paranoid 1138 call save_paranoid
1101 TRACE_IRQS_OFF 1139 TRACE_IRQS_OFF_DEBUG
1102 movq %rsp,%rdi /* pt_regs pointer */ 1140 movq %rsp,%rdi /* pt_regs pointer */
1103 xorl %esi,%esi /* no error code */ 1141 xorl %esi,%esi /* no error code */
1104 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist) 1142 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
@@ -1393,7 +1431,7 @@ paranoidzeroentry machine_check *machine_check_vector(%rip)
1393ENTRY(paranoid_exit) 1431ENTRY(paranoid_exit)
1394 DEFAULT_FRAME 1432 DEFAULT_FRAME
1395 DISABLE_INTERRUPTS(CLBR_NONE) 1433 DISABLE_INTERRUPTS(CLBR_NONE)
1396 TRACE_IRQS_OFF 1434 TRACE_IRQS_OFF_DEBUG
1397 testl %ebx,%ebx /* swapgs needed? */ 1435 testl %ebx,%ebx /* swapgs needed? */
1398 jnz paranoid_restore 1436 jnz paranoid_restore
1399 testl $3,CS(%rsp) 1437 testl $3,CS(%rsp)
@@ -1404,7 +1442,7 @@ paranoid_swapgs:
1404 RESTORE_ALL 8 1442 RESTORE_ALL 8
1405 jmp irq_return 1443 jmp irq_return
1406paranoid_restore: 1444paranoid_restore:
1407 TRACE_IRQS_IRETQ 0 1445 TRACE_IRQS_IRETQ_DEBUG 0
1408 RESTORE_ALL 8 1446 RESTORE_ALL 8
1409 jmp irq_return 1447 jmp irq_return
1410paranoid_userspace: 1448paranoid_userspace:
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 32ff36596ab1..c3a7cb4bf6e6 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -100,7 +100,7 @@ static const unsigned char *ftrace_nop_replace(void)
100} 100}
101 101
102static int 102static int
103ftrace_modify_code(unsigned long ip, unsigned const char *old_code, 103ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
104 unsigned const char *new_code) 104 unsigned const char *new_code)
105{ 105{
106 unsigned char replaced[MCOUNT_INSN_SIZE]; 106 unsigned char replaced[MCOUNT_INSN_SIZE];
@@ -141,7 +141,20 @@ int ftrace_make_nop(struct module *mod,
141 old = ftrace_call_replace(ip, addr); 141 old = ftrace_call_replace(ip, addr);
142 new = ftrace_nop_replace(); 142 new = ftrace_nop_replace();
143 143
144 return ftrace_modify_code(rec->ip, old, new); 144 /*
145 * On boot up, and when modules are loaded, the MCOUNT_ADDR
146 * is converted to a nop, and will never become MCOUNT_ADDR
147 * again. This code is either running before SMP (on boot up)
148 * or before the code will ever be executed (module load).
149 * We do not want to use the breakpoint version in this case,
150 * just modify the code directly.
151 */
152 if (addr == MCOUNT_ADDR)
153 return ftrace_modify_code_direct(rec->ip, old, new);
154
155 /* Normal cases use add_brk_on_nop */
156 WARN_ONCE(1, "invalid use of ftrace_make_nop");
157 return -EINVAL;
145} 158}
146 159
147int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) 160int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
@@ -152,9 +165,47 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
152 old = ftrace_nop_replace(); 165 old = ftrace_nop_replace();
153 new = ftrace_call_replace(ip, addr); 166 new = ftrace_call_replace(ip, addr);
154 167
155 return ftrace_modify_code(rec->ip, old, new); 168 /* Should only be called when module is loaded */
169 return ftrace_modify_code_direct(rec->ip, old, new);
156} 170}
157 171
172/*
173 * The modifying_ftrace_code is used to tell the breakpoint
174 * handler to call ftrace_int3_handler(). If it fails to
175 * call this handler for a breakpoint added by ftrace, then
176 * the kernel may crash.
177 *
178 * As atomic_writes on x86 do not need a barrier, we do not
179 * need to add smp_mb()s for this to work. It is also considered
180 * that we can not read the modifying_ftrace_code before
181 * executing the breakpoint. That would be quite remarkable if
182 * it could do that. Here's the flow that is required:
183 *
184 * CPU-0 CPU-1
185 *
186 * atomic_inc(mfc);
187 * write int3s
188 * <trap-int3> // implicit (r)mb
189 * if (atomic_read(mfc))
190 * call ftrace_int3_handler()
191 *
192 * Then when we are finished:
193 *
194 * atomic_dec(mfc);
195 *
196 * If we hit a breakpoint that was not set by ftrace, it does not
197 * matter if ftrace_int3_handler() is called or not. It will
198 * simply be ignored. But it is crucial that a ftrace nop/caller
199 * breakpoint is handled. No other user should ever place a
200 * breakpoint on an ftrace nop/caller location. It must only
201 * be done by this code.
202 */
203atomic_t modifying_ftrace_code __read_mostly;
204
205static int
206ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
207 unsigned const char *new_code);
208
158int ftrace_update_ftrace_func(ftrace_func_t func) 209int ftrace_update_ftrace_func(ftrace_func_t func)
159{ 210{
160 unsigned long ip = (unsigned long)(&ftrace_call); 211 unsigned long ip = (unsigned long)(&ftrace_call);
@@ -163,13 +214,17 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
163 214
164 memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE); 215 memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
165 new = ftrace_call_replace(ip, (unsigned long)func); 216 new = ftrace_call_replace(ip, (unsigned long)func);
217
218 /* See comment above by declaration of modifying_ftrace_code */
219 atomic_inc(&modifying_ftrace_code);
220
166 ret = ftrace_modify_code(ip, old, new); 221 ret = ftrace_modify_code(ip, old, new);
167 222
223 atomic_dec(&modifying_ftrace_code);
224
168 return ret; 225 return ret;
169} 226}
170 227
171int modifying_ftrace_code __read_mostly;
172
173/* 228/*
174 * A breakpoint was added to the code address we are about to 229 * A breakpoint was added to the code address we are about to
175 * modify, and this is the handle that will just skip over it. 230 * modify, and this is the handle that will just skip over it.
@@ -489,13 +544,46 @@ void ftrace_replace_code(int enable)
489 } 544 }
490} 545}
491 546
547static int
548ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
549 unsigned const char *new_code)
550{
551 int ret;
552
553 ret = add_break(ip, old_code);
554 if (ret)
555 goto out;
556
557 run_sync();
558
559 ret = add_update_code(ip, new_code);
560 if (ret)
561 goto fail_update;
562
563 run_sync();
564
565 ret = ftrace_write(ip, new_code, 1);
566 if (ret) {
567 ret = -EPERM;
568 goto out;
569 }
570 run_sync();
571 out:
572 return ret;
573
574 fail_update:
575 probe_kernel_write((void *)ip, &old_code[0], 1);
576 goto out;
577}
578
492void arch_ftrace_update_code(int command) 579void arch_ftrace_update_code(int command)
493{ 580{
494 modifying_ftrace_code++; 581 /* See comment above by declaration of modifying_ftrace_code */
582 atomic_inc(&modifying_ftrace_code);
495 583
496 ftrace_modify_all_code(command); 584 ftrace_modify_all_code(command);
497 585
498 modifying_ftrace_code--; 586 atomic_dec(&modifying_ftrace_code);
499} 587}
500 588
501int __init ftrace_dyn_arch_init(void *data) 589int __init ftrace_dyn_arch_init(void *data)
diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
index 90875279ef3d..a0b2f84457be 100644
--- a/arch/x86/kernel/nmi.c
+++ b/arch/x86/kernel/nmi.c
@@ -444,14 +444,16 @@ static inline void nmi_nesting_preprocess(struct pt_regs *regs)
444 */ 444 */
445 if (unlikely(is_debug_stack(regs->sp))) { 445 if (unlikely(is_debug_stack(regs->sp))) {
446 debug_stack_set_zero(); 446 debug_stack_set_zero();
447 __get_cpu_var(update_debug_stack) = 1; 447 this_cpu_write(update_debug_stack, 1);
448 } 448 }
449} 449}
450 450
451static inline void nmi_nesting_postprocess(void) 451static inline void nmi_nesting_postprocess(void)
452{ 452{
453 if (unlikely(__get_cpu_var(update_debug_stack))) 453 if (unlikely(this_cpu_read(update_debug_stack))) {
454 debug_stack_reset(); 454 debug_stack_reset();
455 this_cpu_write(update_debug_stack, 0);
456 }
455} 457}
456#endif 458#endif
457 459
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index 13b1990c7c58..c4c6a5c2bf0f 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -1211,12 +1211,6 @@ static long x32_arch_ptrace(struct task_struct *child,
1211 0, sizeof(struct user_i387_struct), 1211 0, sizeof(struct user_i387_struct),
1212 datap); 1212 datap);
1213 1213
1214 /* normal 64bit interface to access TLS data.
1215 Works just like arch_prctl, except that the arguments
1216 are reversed. */
1217 case PTRACE_ARCH_PRCTL:
1218 return do_arch_prctl(child, data, addr);
1219
1220 default: 1214 default:
1221 return compat_ptrace_request(child, request, addr, data); 1215 return compat_ptrace_request(child, request, addr, data);
1222 } 1216 }
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 965dfda0fd5e..21af737053aa 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -555,7 +555,6 @@ unsigned long sys_sigreturn(struct pt_regs *regs)
555 sizeof(frame->extramask)))) 555 sizeof(frame->extramask))))
556 goto badframe; 556 goto badframe;
557 557
558 sigdelsetmask(&set, ~_BLOCKABLE);
559 set_current_blocked(&set); 558 set_current_blocked(&set);
560 559
561 if (restore_sigcontext(regs, &frame->sc, &ax)) 560 if (restore_sigcontext(regs, &frame->sc, &ax))
@@ -581,7 +580,6 @@ long sys_rt_sigreturn(struct pt_regs *regs)
581 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 580 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
582 goto badframe; 581 goto badframe;
583 582
584 sigdelsetmask(&set, ~_BLOCKABLE);
585 set_current_blocked(&set); 583 set_current_blocked(&set);
586 584
587 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) 585 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
@@ -647,42 +645,28 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
647 struct pt_regs *regs) 645 struct pt_regs *regs)
648{ 646{
649 int usig = signr_convert(sig); 647 int usig = signr_convert(sig);
650 sigset_t *set = &current->blocked; 648 sigset_t *set = sigmask_to_save();
651 int ret;
652
653 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
654 set = &current->saved_sigmask;
655 649
656 /* Set up the stack frame */ 650 /* Set up the stack frame */
657 if (is_ia32) { 651 if (is_ia32) {
658 if (ka->sa.sa_flags & SA_SIGINFO) 652 if (ka->sa.sa_flags & SA_SIGINFO)
659 ret = ia32_setup_rt_frame(usig, ka, info, set, regs); 653 return ia32_setup_rt_frame(usig, ka, info, set, regs);
660 else 654 else
661 ret = ia32_setup_frame(usig, ka, set, regs); 655 return ia32_setup_frame(usig, ka, set, regs);
662#ifdef CONFIG_X86_X32_ABI 656#ifdef CONFIG_X86_X32_ABI
663 } else if (is_x32) { 657 } else if (is_x32) {
664 ret = x32_setup_rt_frame(usig, ka, info, 658 return x32_setup_rt_frame(usig, ka, info,
665 (compat_sigset_t *)set, regs); 659 (compat_sigset_t *)set, regs);
666#endif 660#endif
667 } else { 661 } else {
668 ret = __setup_rt_frame(sig, ka, info, set, regs); 662 return __setup_rt_frame(sig, ka, info, set, regs);
669 }
670
671 if (ret) {
672 force_sigsegv(sig, current);
673 return -EFAULT;
674 } 663 }
675
676 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
677 return ret;
678} 664}
679 665
680static int 666static void
681handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, 667handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
682 struct pt_regs *regs) 668 struct pt_regs *regs)
683{ 669{
684 int ret;
685
686 /* Are we from a system call? */ 670 /* Are we from a system call? */
687 if (syscall_get_nr(current, regs) >= 0) { 671 if (syscall_get_nr(current, regs) >= 0) {
688 /* If so, check system call restarting.. */ 672 /* If so, check system call restarting.. */
@@ -713,10 +697,10 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
713 likely(test_and_clear_thread_flag(TIF_FORCED_TF))) 697 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
714 regs->flags &= ~X86_EFLAGS_TF; 698 regs->flags &= ~X86_EFLAGS_TF;
715 699
716 ret = setup_rt_frame(sig, ka, info, regs); 700 if (setup_rt_frame(sig, ka, info, regs) < 0) {
717 701 force_sigsegv(sig, current);
718 if (ret) 702 return;
719 return ret; 703 }
720 704
721 /* 705 /*
722 * Clear the direction flag as per the ABI for function entry. 706 * Clear the direction flag as per the ABI for function entry.
@@ -731,12 +715,8 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
731 */ 715 */
732 regs->flags &= ~X86_EFLAGS_TF; 716 regs->flags &= ~X86_EFLAGS_TF;
733 717
734 block_sigmask(ka, sig); 718 signal_delivered(sig, info, ka, regs,
735 719 test_thread_flag(TIF_SINGLESTEP));
736 tracehook_signal_handler(sig, info, ka, regs,
737 test_thread_flag(TIF_SINGLESTEP));
738
739 return 0;
740} 720}
741 721
742#ifdef CONFIG_X86_32 722#ifdef CONFIG_X86_32
@@ -757,16 +737,6 @@ static void do_signal(struct pt_regs *regs)
757 siginfo_t info; 737 siginfo_t info;
758 int signr; 738 int signr;
759 739
760 /*
761 * We want the common case to go fast, which is why we may in certain
762 * cases get here from kernel mode. Just return without doing anything
763 * if so.
764 * X86_32: vm86 regs switched out by assembly code before reaching
765 * here, so testing against kernel CS suffices.
766 */
767 if (!user_mode(regs))
768 return;
769
770 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 740 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
771 if (signr > 0) { 741 if (signr > 0) {
772 /* Whee! Actually deliver the signal. */ 742 /* Whee! Actually deliver the signal. */
@@ -796,10 +766,7 @@ static void do_signal(struct pt_regs *regs)
796 * If there's no signal to deliver, we just put the saved sigmask 766 * If there's no signal to deliver, we just put the saved sigmask
797 * back. 767 * back.
798 */ 768 */
799 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 769 restore_saved_sigmask();
800 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
801 set_current_blocked(&current->saved_sigmask);
802 }
803} 770}
804 771
805/* 772/*
@@ -827,8 +794,6 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
827 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 794 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
828 clear_thread_flag(TIF_NOTIFY_RESUME); 795 clear_thread_flag(TIF_NOTIFY_RESUME);
829 tracehook_notify_resume(regs); 796 tracehook_notify_resume(regs);
830 if (current->replacement_session_keyring)
831 key_replace_session_keyring();
832 } 797 }
833 if (thread_info_flags & _TIF_USER_RETURN_NOTIFY) 798 if (thread_info_flags & _TIF_USER_RETURN_NOTIFY)
834 fire_user_return_notifiers(); 799 fire_user_return_notifiers();
@@ -936,7 +901,6 @@ asmlinkage long sys32_x32_rt_sigreturn(struct pt_regs *regs)
936 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 901 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
937 goto badframe; 902 goto badframe;
938 903
939 sigdelsetmask(&set, ~_BLOCKABLE);
940 set_current_blocked(&set); 904 set_current_blocked(&set);
941 905
942 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) 906 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index ff08457a025d..05b31d92f69c 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -303,8 +303,12 @@ gp_in_kernel:
303dotraplinkage void __kprobes notrace do_int3(struct pt_regs *regs, long error_code) 303dotraplinkage void __kprobes notrace do_int3(struct pt_regs *regs, long error_code)
304{ 304{
305#ifdef CONFIG_DYNAMIC_FTRACE 305#ifdef CONFIG_DYNAMIC_FTRACE
306 /* ftrace must be first, everything else may cause a recursive crash */ 306 /*
307 if (unlikely(modifying_ftrace_code) && ftrace_int3_handler(regs)) 307 * ftrace must be first, everything else may cause a recursive crash.
308 * See note by declaration of modifying_ftrace_code in ftrace.c
309 */
310 if (unlikely(atomic_read(&modifying_ftrace_code)) &&
311 ftrace_int3_handler(regs))
308 return; 312 return;
309#endif 313#endif
310#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP 314#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
diff --git a/arch/x86/syscalls/syscall_32.tbl b/arch/x86/syscalls/syscall_32.tbl
index 29f9f0554f7d..7a35a6e71d44 100644
--- a/arch/x86/syscalls/syscall_32.tbl
+++ b/arch/x86/syscalls/syscall_32.tbl
@@ -355,3 +355,4 @@
355346 i386 setns sys_setns 355346 i386 setns sys_setns
356347 i386 process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv 356347 i386 process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv
357348 i386 process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev 357348 i386 process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev
358349 i386 kcmp sys_kcmp
diff --git a/arch/x86/syscalls/syscall_64.tbl b/arch/x86/syscalls/syscall_64.tbl
index dd29a9ea27c5..51171aeff0dc 100644
--- a/arch/x86/syscalls/syscall_64.tbl
+++ b/arch/x86/syscalls/syscall_64.tbl
@@ -318,6 +318,8 @@
318309 common getcpu sys_getcpu 318309 common getcpu sys_getcpu
319310 64 process_vm_readv sys_process_vm_readv 319310 64 process_vm_readv sys_process_vm_readv
320311 64 process_vm_writev sys_process_vm_writev 320311 64 process_vm_writev sys_process_vm_writev
321312 64 kcmp sys_kcmp
322
321# 323#
322# x32-specific system call numbers start at 512 to avoid cache impact 324# x32-specific system call numbers start at 512 to avoid cache impact
323# for native 64-bit operation. 325# for native 64-bit operation.
diff --git a/arch/x86/um/signal.c b/arch/x86/um/signal.c
index bb0fb03b9f85..a508cea13503 100644
--- a/arch/x86/um/signal.c
+++ b/arch/x86/um/signal.c
@@ -486,7 +486,6 @@ long sys_sigreturn(struct pt_regs *regs)
486 copy_from_user(&set.sig[1], extramask, sig_size)) 486 copy_from_user(&set.sig[1], extramask, sig_size))
487 goto segfault; 487 goto segfault;
488 488
489 sigdelsetmask(&set, ~_BLOCKABLE);
490 set_current_blocked(&set); 489 set_current_blocked(&set);
491 490
492 if (copy_sc_from_user(&current->thread.regs, sc)) 491 if (copy_sc_from_user(&current->thread.regs, sc))
@@ -600,7 +599,6 @@ long sys_rt_sigreturn(struct pt_regs *regs)
600 if (copy_from_user(&set, &uc->uc_sigmask, sizeof(set))) 599 if (copy_from_user(&set, &uc->uc_sigmask, sizeof(set)))
601 goto segfault; 600 goto segfault;
602 601
603 sigdelsetmask(&set, ~_BLOCKABLE);
604 set_current_blocked(&set); 602 set_current_blocked(&set);
605 603
606 if (copy_sc_from_user(&current->thread.regs, &uc->uc_mcontext)) 604 if (copy_sc_from_user(&current->thread.regs, &uc->uc_mcontext))
diff --git a/arch/xtensa/kernel/signal.c b/arch/xtensa/kernel/signal.c
index c5e4ec0598d2..b9f8e5850d3a 100644
--- a/arch/xtensa/kernel/signal.c
+++ b/arch/xtensa/kernel/signal.c
@@ -30,8 +30,6 @@
30 30
31#define DEBUG_SIG 0 31#define DEBUG_SIG 0
32 32
33#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
34
35extern struct task_struct *coproc_owners[]; 33extern struct task_struct *coproc_owners[];
36 34
37struct rt_sigframe 35struct rt_sigframe
@@ -261,7 +259,6 @@ asmlinkage long xtensa_rt_sigreturn(long a0, long a1, long a2, long a3,
261 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 259 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
262 goto badframe; 260 goto badframe;
263 261
264 sigdelsetmask(&set, ~_BLOCKABLE);
265 set_current_blocked(&set); 262 set_current_blocked(&set);
266 263
267 if (restore_sigcontext(regs, frame)) 264 if (restore_sigcontext(regs, frame))
@@ -452,15 +449,6 @@ static void do_signal(struct pt_regs *regs)
452 siginfo_t info; 449 siginfo_t info;
453 int signr; 450 int signr;
454 struct k_sigaction ka; 451 struct k_sigaction ka;
455 sigset_t oldset;
456
457 if (try_to_freeze())
458 goto no_signal;
459
460 if (test_thread_flag(TIF_RESTORE_SIGMASK))
461 oldset = &current->saved_sigmask;
462 else
463 oldset = &current->blocked;
464 452
465 task_pt_regs(current)->icountlevel = 0; 453 task_pt_regs(current)->icountlevel = 0;
466 454
@@ -501,19 +489,17 @@ static void do_signal(struct pt_regs *regs)
501 489
502 /* Whee! Actually deliver the signal. */ 490 /* Whee! Actually deliver the signal. */
503 /* Set up the stack frame */ 491 /* Set up the stack frame */
504 ret = setup_frame(signr, &ka, &info, oldset, regs); 492 ret = setup_frame(signr, &ka, &info, sigmask_to_save(), regs);
505 if (ret) 493 if (ret)
506 return; 494 return;
507 495
508 clear_thread_flag(TIF_RESTORE_SIGMASK); 496 signal_delivered(signr, info, ka, regs, 0);
509 block_sigmask(&ka, signr);
510 if (current->ptrace & PT_SINGLESTEP) 497 if (current->ptrace & PT_SINGLESTEP)
511 task_pt_regs(current)->icountlevel = 1; 498 task_pt_regs(current)->icountlevel = 1;
512 499
513 return; 500 return;
514 } 501 }
515 502
516no_signal:
517 /* Did we come from a system call? */ 503 /* Did we come from a system call? */
518 if ((signed) regs->syscall >= 0) { 504 if ((signed) regs->syscall >= 0) {
519 /* Restart the system call - no handlers present */ 505 /* Restart the system call - no handlers present */
@@ -532,8 +518,7 @@ no_signal:
532 } 518 }
533 519
534 /* If there's no signal to deliver, we just restore the saved mask. */ 520 /* If there's no signal to deliver, we just restore the saved mask. */
535 if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK)) 521 restore_saved_sigmask();
536 set_current_blocked(&current->saved_sigmask);
537 522
538 if (current->ptrace & PT_SINGLESTEP) 523 if (current->ptrace & PT_SINGLESTEP)
539 task_pt_regs(current)->icountlevel = 1; 524 task_pt_regs(current)->icountlevel = 1;
@@ -548,9 +533,6 @@ void do_notify_resume(struct pt_regs *regs)
548 if (test_thread_flag(TIF_SIGPENDING)) 533 if (test_thread_flag(TIF_SIGPENDING))
549 do_signal(regs); 534 do_signal(regs);
550 535
551 if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME)) { 536 if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
552 tracehook_notify_resume(regs); 537 tracehook_notify_resume(regs);
553 if (current->replacement_session_keyring)
554 key_replace_session_keyring();
555 }
556} 538}
diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index ba29b2e73d48..72b5e7280d14 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -42,7 +42,7 @@ struct device *soc_device_to_device(struct soc_device *soc_dev)
42 return &soc_dev->dev; 42 return &soc_dev->dev;
43} 43}
44 44
45static mode_t soc_attribute_mode(struct kobject *kobj, 45static umode_t soc_attribute_mode(struct kobject *kobj,
46 struct attribute *attr, 46 struct attribute *attr,
47 int index) 47 int index)
48{ 48{
diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.c b/drivers/gpu/drm/cirrus/cirrus_drv.c
index d7038230b71e..7053140c6596 100644
--- a/drivers/gpu/drm/cirrus/cirrus_drv.c
+++ b/drivers/gpu/drm/cirrus/cirrus_drv.c
@@ -35,9 +35,28 @@ static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
35 {0,} 35 {0,}
36}; 36};
37 37
38
39static void cirrus_kick_out_firmware_fb(struct pci_dev *pdev)
40{
41 struct apertures_struct *ap;
42 bool primary = false;
43
44 ap = alloc_apertures(1);
45 ap->ranges[0].base = pci_resource_start(pdev, 0);
46 ap->ranges[0].size = pci_resource_len(pdev, 0);
47
48#ifdef CONFIG_X86
49 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
50#endif
51 remove_conflicting_framebuffers(ap, "cirrusdrmfb", primary);
52 kfree(ap);
53}
54
38static int __devinit 55static int __devinit
39cirrus_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 56cirrus_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40{ 57{
58 cirrus_kick_out_firmware_fb(pdev);
59
41 return drm_get_pci_dev(pdev, ent, &driver); 60 return drm_get_pci_dev(pdev, ent, &driver);
42} 61}
43 62
diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.h b/drivers/gpu/drm/cirrus/cirrus_drv.h
index 21bdfa8836f7..64ea597cb6d3 100644
--- a/drivers/gpu/drm/cirrus/cirrus_drv.h
+++ b/drivers/gpu/drm/cirrus/cirrus_drv.h
@@ -145,7 +145,7 @@ struct cirrus_device {
145 struct ttm_bo_device bdev; 145 struct ttm_bo_device bdev;
146 atomic_t validate_sequence; 146 atomic_t validate_sequence;
147 } ttm; 147 } ttm;
148 148 bool mm_inited;
149}; 149};
150 150
151 151
diff --git a/drivers/gpu/drm/cirrus/cirrus_ttm.c b/drivers/gpu/drm/cirrus/cirrus_ttm.c
index 2ebcd11a5023..50e170f879de 100644
--- a/drivers/gpu/drm/cirrus/cirrus_ttm.c
+++ b/drivers/gpu/drm/cirrus/cirrus_ttm.c
@@ -275,12 +275,17 @@ int cirrus_mm_init(struct cirrus_device *cirrus)
275 pci_resource_len(dev->pdev, 0), 275 pci_resource_len(dev->pdev, 0),
276 DRM_MTRR_WC); 276 DRM_MTRR_WC);
277 277
278 cirrus->mm_inited = true;
278 return 0; 279 return 0;
279} 280}
280 281
281void cirrus_mm_fini(struct cirrus_device *cirrus) 282void cirrus_mm_fini(struct cirrus_device *cirrus)
282{ 283{
283 struct drm_device *dev = cirrus->dev; 284 struct drm_device *dev = cirrus->dev;
285
286 if (!cirrus->mm_inited)
287 return;
288
284 ttm_bo_device_release(&cirrus->ttm.bdev); 289 ttm_bo_device_release(&cirrus->ttm.bdev);
285 290
286 cirrus_ttm_global_release(cirrus); 291 cirrus_ttm_global_release(cirrus);
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index c3b5139eba7f..eb92fe257a39 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -30,7 +30,7 @@
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/export.h> 33#include <linux/module.h>
34#include "drmP.h" 34#include "drmP.h"
35#include "drm_edid.h" 35#include "drm_edid.h"
36#include "drm_edid_modes.h" 36#include "drm_edid_modes.h"
@@ -149,6 +149,10 @@ int drm_edid_header_is_valid(const u8 *raw_edid)
149} 149}
150EXPORT_SYMBOL(drm_edid_header_is_valid); 150EXPORT_SYMBOL(drm_edid_header_is_valid);
151 151
152static int edid_fixup __read_mostly = 6;
153module_param_named(edid_fixup, edid_fixup, int, 0400);
154MODULE_PARM_DESC(edid_fixup,
155 "Minimum number of valid EDID header bytes (0-8, default 6)");
152 156
153/* 157/*
154 * Sanity check the EDID block (base or extension). Return 0 if the block 158 * Sanity check the EDID block (base or extension). Return 0 if the block
@@ -160,10 +164,13 @@ bool drm_edid_block_valid(u8 *raw_edid, int block)
160 u8 csum = 0; 164 u8 csum = 0;
161 struct edid *edid = (struct edid *)raw_edid; 165 struct edid *edid = (struct edid *)raw_edid;
162 166
167 if (edid_fixup > 8 || edid_fixup < 0)
168 edid_fixup = 6;
169
163 if (block == 0) { 170 if (block == 0) {
164 int score = drm_edid_header_is_valid(raw_edid); 171 int score = drm_edid_header_is_valid(raw_edid);
165 if (score == 8) ; 172 if (score == 8) ;
166 else if (score >= 6) { 173 else if (score >= edid_fixup) {
167 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n"); 174 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
168 memcpy(raw_edid, edid_header, sizeof(edid_header)); 175 memcpy(raw_edid, edid_header, sizeof(edid_header));
169 } else { 176 } else {
diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
index f920fb5e42b6..fa9439159ebd 100644
--- a/drivers/gpu/drm/i810/i810_dma.c
+++ b/drivers/gpu/drm/i810/i810_dma.c
@@ -130,11 +130,10 @@ static int i810_map_buffer(struct drm_buf *buf, struct drm_file *file_priv)
130 return -EINVAL; 130 return -EINVAL;
131 131
132 /* This is all entirely broken */ 132 /* This is all entirely broken */
133 down_write(&current->mm->mmap_sem);
134 old_fops = file_priv->filp->f_op; 133 old_fops = file_priv->filp->f_op;
135 file_priv->filp->f_op = &i810_buffer_fops; 134 file_priv->filp->f_op = &i810_buffer_fops;
136 dev_priv->mmap_buffer = buf; 135 dev_priv->mmap_buffer = buf;
137 buf_priv->virtual = (void *)do_mmap(file_priv->filp, 0, buf->total, 136 buf_priv->virtual = (void *)vm_mmap(file_priv->filp, 0, buf->total,
138 PROT_READ | PROT_WRITE, 137 PROT_READ | PROT_WRITE,
139 MAP_SHARED, buf->bus_address); 138 MAP_SHARED, buf->bus_address);
140 dev_priv->mmap_buffer = NULL; 139 dev_priv->mmap_buffer = NULL;
@@ -145,7 +144,6 @@ static int i810_map_buffer(struct drm_buf *buf, struct drm_file *file_priv)
145 retcode = PTR_ERR(buf_priv->virtual); 144 retcode = PTR_ERR(buf_priv->virtual);
146 buf_priv->virtual = NULL; 145 buf_priv->virtual = NULL;
147 } 146 }
148 up_write(&current->mm->mmap_sem);
149 147
150 return retcode; 148 return retcode;
151} 149}
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 377c21f531e4..c9cfc67c2cf5 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -942,6 +942,9 @@ struct drm_i915_gem_object {
942 942
943 /* prime dma-buf support */ 943 /* prime dma-buf support */
944 struct sg_table *sg_table; 944 struct sg_table *sg_table;
945 void *dma_buf_vmapping;
946 int vmapping_count;
947
945 /** 948 /**
946 * Used for performing relocations during execbuffer insertion. 949 * Used for performing relocations during execbuffer insertion.
947 */ 950 */
diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
index 8e269178d6a5..aa308e1337db 100644
--- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
@@ -74,6 +74,59 @@ static void i915_gem_dmabuf_release(struct dma_buf *dma_buf)
74 } 74 }
75} 75}
76 76
77static void *i915_gem_dmabuf_vmap(struct dma_buf *dma_buf)
78{
79 struct drm_i915_gem_object *obj = dma_buf->priv;
80 struct drm_device *dev = obj->base.dev;
81 int ret;
82
83 ret = i915_mutex_lock_interruptible(dev);
84 if (ret)
85 return ERR_PTR(ret);
86
87 if (obj->dma_buf_vmapping) {
88 obj->vmapping_count++;
89 goto out_unlock;
90 }
91
92 if (!obj->pages) {
93 ret = i915_gem_object_get_pages_gtt(obj, __GFP_NORETRY | __GFP_NOWARN);
94 if (ret) {
95 mutex_unlock(&dev->struct_mutex);
96 return ERR_PTR(ret);
97 }
98 }
99
100 obj->dma_buf_vmapping = vmap(obj->pages, obj->base.size / PAGE_SIZE, 0, PAGE_KERNEL);
101 if (!obj->dma_buf_vmapping) {
102 DRM_ERROR("failed to vmap object\n");
103 goto out_unlock;
104 }
105
106 obj->vmapping_count = 1;
107out_unlock:
108 mutex_unlock(&dev->struct_mutex);
109 return obj->dma_buf_vmapping;
110}
111
112static void i915_gem_dmabuf_vunmap(struct dma_buf *dma_buf, void *vaddr)
113{
114 struct drm_i915_gem_object *obj = dma_buf->priv;
115 struct drm_device *dev = obj->base.dev;
116 int ret;
117
118 ret = i915_mutex_lock_interruptible(dev);
119 if (ret)
120 return;
121
122 --obj->vmapping_count;
123 if (obj->vmapping_count == 0) {
124 vunmap(obj->dma_buf_vmapping);
125 obj->dma_buf_vmapping = NULL;
126 }
127 mutex_unlock(&dev->struct_mutex);
128}
129
77static void *i915_gem_dmabuf_kmap_atomic(struct dma_buf *dma_buf, unsigned long page_num) 130static void *i915_gem_dmabuf_kmap_atomic(struct dma_buf *dma_buf, unsigned long page_num)
78{ 131{
79 return NULL; 132 return NULL;
@@ -93,6 +146,11 @@ static void i915_gem_dmabuf_kunmap(struct dma_buf *dma_buf, unsigned long page_n
93 146
94} 147}
95 148
149static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
150{
151 return -EINVAL;
152}
153
96static const struct dma_buf_ops i915_dmabuf_ops = { 154static const struct dma_buf_ops i915_dmabuf_ops = {
97 .map_dma_buf = i915_gem_map_dma_buf, 155 .map_dma_buf = i915_gem_map_dma_buf,
98 .unmap_dma_buf = i915_gem_unmap_dma_buf, 156 .unmap_dma_buf = i915_gem_unmap_dma_buf,
@@ -101,6 +159,9 @@ static const struct dma_buf_ops i915_dmabuf_ops = {
101 .kmap_atomic = i915_gem_dmabuf_kmap_atomic, 159 .kmap_atomic = i915_gem_dmabuf_kmap_atomic,
102 .kunmap = i915_gem_dmabuf_kunmap, 160 .kunmap = i915_gem_dmabuf_kunmap,
103 .kunmap_atomic = i915_gem_dmabuf_kunmap_atomic, 161 .kunmap_atomic = i915_gem_dmabuf_kunmap_atomic,
162 .mmap = i915_gem_dmabuf_mmap,
163 .vmap = i915_gem_dmabuf_vmap,
164 .vunmap = i915_gem_dmabuf_vunmap,
104}; 165};
105 166
106struct dma_buf *i915_gem_prime_export(struct drm_device *dev, 167struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.c b/drivers/gpu/drm/mgag200/mgag200_drv.c
index 3c8e04f54713..93e832d6c328 100644
--- a/drivers/gpu/drm/mgag200/mgag200_drv.c
+++ b/drivers/gpu/drm/mgag200/mgag200_drv.c
@@ -41,9 +41,28 @@ static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
41 41
42MODULE_DEVICE_TABLE(pci, pciidlist); 42MODULE_DEVICE_TABLE(pci, pciidlist);
43 43
44static void mgag200_kick_out_firmware_fb(struct pci_dev *pdev)
45{
46 struct apertures_struct *ap;
47 bool primary = false;
48
49 ap = alloc_apertures(1);
50 ap->ranges[0].base = pci_resource_start(pdev, 0);
51 ap->ranges[0].size = pci_resource_len(pdev, 0);
52
53#ifdef CONFIG_X86
54 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
55#endif
56 remove_conflicting_framebuffers(ap, "mgag200drmfb", primary);
57 kfree(ap);
58}
59
60
44static int __devinit 61static int __devinit
45mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 62mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46{ 63{
64 mgag200_kick_out_firmware_fb(pdev);
65
47 return drm_get_pci_dev(pdev, ent, &driver); 66 return drm_get_pci_dev(pdev, ent, &driver);
48} 67}
49 68
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
index 634d222c93de..8613cb23808c 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
@@ -123,6 +123,9 @@ struct nouveau_bo {
123 123
124 struct drm_gem_object *gem; 124 struct drm_gem_object *gem;
125 int pin_refcnt; 125 int pin_refcnt;
126
127 struct ttm_bo_kmap_obj dma_buf_vmap;
128 int vmapping_count;
126}; 129};
127 130
128#define nouveau_bo_tile_layout(nvbo) \ 131#define nouveau_bo_tile_layout(nvbo) \
diff --git a/drivers/gpu/drm/nouveau/nouveau_prime.c b/drivers/gpu/drm/nouveau/nouveau_prime.c
index c58aab7370c5..a89240e5fb29 100644
--- a/drivers/gpu/drm/nouveau/nouveau_prime.c
+++ b/drivers/gpu/drm/nouveau/nouveau_prime.c
@@ -61,6 +61,48 @@ static void nouveau_gem_kunmap(struct dma_buf *dma_buf, unsigned long page_num,
61 61
62} 62}
63 63
64static int nouveau_gem_prime_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
65{
66 return -EINVAL;
67}
68
69static void *nouveau_gem_prime_vmap(struct dma_buf *dma_buf)
70{
71 struct nouveau_bo *nvbo = dma_buf->priv;
72 struct drm_device *dev = nvbo->gem->dev;
73 int ret;
74
75 mutex_lock(&dev->struct_mutex);
76 if (nvbo->vmapping_count) {
77 nvbo->vmapping_count++;
78 goto out_unlock;
79 }
80
81 ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.num_pages,
82 &nvbo->dma_buf_vmap);
83 if (ret) {
84 mutex_unlock(&dev->struct_mutex);
85 return ERR_PTR(ret);
86 }
87 nvbo->vmapping_count = 1;
88out_unlock:
89 mutex_unlock(&dev->struct_mutex);
90 return nvbo->dma_buf_vmap.virtual;
91}
92
93static void nouveau_gem_prime_vunmap(struct dma_buf *dma_buf, void *vaddr)
94{
95 struct nouveau_bo *nvbo = dma_buf->priv;
96 struct drm_device *dev = nvbo->gem->dev;
97
98 mutex_lock(&dev->struct_mutex);
99 nvbo->vmapping_count--;
100 if (nvbo->vmapping_count == 0) {
101 ttm_bo_kunmap(&nvbo->dma_buf_vmap);
102 }
103 mutex_unlock(&dev->struct_mutex);
104}
105
64static const struct dma_buf_ops nouveau_dmabuf_ops = { 106static const struct dma_buf_ops nouveau_dmabuf_ops = {
65 .map_dma_buf = nouveau_gem_map_dma_buf, 107 .map_dma_buf = nouveau_gem_map_dma_buf,
66 .unmap_dma_buf = nouveau_gem_unmap_dma_buf, 108 .unmap_dma_buf = nouveau_gem_unmap_dma_buf,
@@ -69,6 +111,9 @@ static const struct dma_buf_ops nouveau_dmabuf_ops = {
69 .kmap_atomic = nouveau_gem_kmap_atomic, 111 .kmap_atomic = nouveau_gem_kmap_atomic,
70 .kunmap = nouveau_gem_kunmap, 112 .kunmap = nouveau_gem_kunmap,
71 .kunmap_atomic = nouveau_gem_kunmap_atomic, 113 .kunmap_atomic = nouveau_gem_kunmap_atomic,
114 .mmap = nouveau_gem_prime_mmap,
115 .vmap = nouveau_gem_prime_vmap,
116 .vunmap = nouveau_gem_prime_vunmap,
72}; 117};
73 118
74static int 119static int
diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c
index 58991af90502..01550d05e273 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -1029,6 +1029,11 @@ int evergreen_pcie_gart_enable(struct radeon_device *rdev)
1029 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp); 1029 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
1030 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp); 1030 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
1031 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp); 1031 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
1032 if ((rdev->family == CHIP_JUNIPER) ||
1033 (rdev->family == CHIP_CYPRESS) ||
1034 (rdev->family == CHIP_HEMLOCK) ||
1035 (rdev->family == CHIP_BARTS))
1036 WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp);
1032 } 1037 }
1033 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp); 1038 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
1034 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); 1039 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
@@ -1553,163 +1558,10 @@ int evergreen_cp_resume(struct radeon_device *rdev)
1553/* 1558/*
1554 * Core functions 1559 * Core functions
1555 */ 1560 */
1556static u32 evergreen_get_tile_pipe_to_backend_map(struct radeon_device *rdev,
1557 u32 num_tile_pipes,
1558 u32 num_backends,
1559 u32 backend_disable_mask)
1560{
1561 u32 backend_map = 0;
1562 u32 enabled_backends_mask = 0;
1563 u32 enabled_backends_count = 0;
1564 u32 cur_pipe;
1565 u32 swizzle_pipe[EVERGREEN_MAX_PIPES];
1566 u32 cur_backend = 0;
1567 u32 i;
1568 bool force_no_swizzle;
1569
1570 if (num_tile_pipes > EVERGREEN_MAX_PIPES)
1571 num_tile_pipes = EVERGREEN_MAX_PIPES;
1572 if (num_tile_pipes < 1)
1573 num_tile_pipes = 1;
1574 if (num_backends > EVERGREEN_MAX_BACKENDS)
1575 num_backends = EVERGREEN_MAX_BACKENDS;
1576 if (num_backends < 1)
1577 num_backends = 1;
1578
1579 for (i = 0; i < EVERGREEN_MAX_BACKENDS; ++i) {
1580 if (((backend_disable_mask >> i) & 1) == 0) {
1581 enabled_backends_mask |= (1 << i);
1582 ++enabled_backends_count;
1583 }
1584 if (enabled_backends_count == num_backends)
1585 break;
1586 }
1587
1588 if (enabled_backends_count == 0) {
1589 enabled_backends_mask = 1;
1590 enabled_backends_count = 1;
1591 }
1592
1593 if (enabled_backends_count != num_backends)
1594 num_backends = enabled_backends_count;
1595
1596 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * EVERGREEN_MAX_PIPES);
1597 switch (rdev->family) {
1598 case CHIP_CEDAR:
1599 case CHIP_REDWOOD:
1600 case CHIP_PALM:
1601 case CHIP_SUMO:
1602 case CHIP_SUMO2:
1603 case CHIP_TURKS:
1604 case CHIP_CAICOS:
1605 force_no_swizzle = false;
1606 break;
1607 case CHIP_CYPRESS:
1608 case CHIP_HEMLOCK:
1609 case CHIP_JUNIPER:
1610 case CHIP_BARTS:
1611 default:
1612 force_no_swizzle = true;
1613 break;
1614 }
1615 if (force_no_swizzle) {
1616 bool last_backend_enabled = false;
1617
1618 force_no_swizzle = false;
1619 for (i = 0; i < EVERGREEN_MAX_BACKENDS; ++i) {
1620 if (((enabled_backends_mask >> i) & 1) == 1) {
1621 if (last_backend_enabled)
1622 force_no_swizzle = true;
1623 last_backend_enabled = true;
1624 } else
1625 last_backend_enabled = false;
1626 }
1627 }
1628
1629 switch (num_tile_pipes) {
1630 case 1:
1631 case 3:
1632 case 5:
1633 case 7:
1634 DRM_ERROR("odd number of pipes!\n");
1635 break;
1636 case 2:
1637 swizzle_pipe[0] = 0;
1638 swizzle_pipe[1] = 1;
1639 break;
1640 case 4:
1641 if (force_no_swizzle) {
1642 swizzle_pipe[0] = 0;
1643 swizzle_pipe[1] = 1;
1644 swizzle_pipe[2] = 2;
1645 swizzle_pipe[3] = 3;
1646 } else {
1647 swizzle_pipe[0] = 0;
1648 swizzle_pipe[1] = 2;
1649 swizzle_pipe[2] = 1;
1650 swizzle_pipe[3] = 3;
1651 }
1652 break;
1653 case 6:
1654 if (force_no_swizzle) {
1655 swizzle_pipe[0] = 0;
1656 swizzle_pipe[1] = 1;
1657 swizzle_pipe[2] = 2;
1658 swizzle_pipe[3] = 3;
1659 swizzle_pipe[4] = 4;
1660 swizzle_pipe[5] = 5;
1661 } else {
1662 swizzle_pipe[0] = 0;
1663 swizzle_pipe[1] = 2;
1664 swizzle_pipe[2] = 4;
1665 swizzle_pipe[3] = 1;
1666 swizzle_pipe[4] = 3;
1667 swizzle_pipe[5] = 5;
1668 }
1669 break;
1670 case 8:
1671 if (force_no_swizzle) {
1672 swizzle_pipe[0] = 0;
1673 swizzle_pipe[1] = 1;
1674 swizzle_pipe[2] = 2;
1675 swizzle_pipe[3] = 3;
1676 swizzle_pipe[4] = 4;
1677 swizzle_pipe[5] = 5;
1678 swizzle_pipe[6] = 6;
1679 swizzle_pipe[7] = 7;
1680 } else {
1681 swizzle_pipe[0] = 0;
1682 swizzle_pipe[1] = 2;
1683 swizzle_pipe[2] = 4;
1684 swizzle_pipe[3] = 6;
1685 swizzle_pipe[4] = 1;
1686 swizzle_pipe[5] = 3;
1687 swizzle_pipe[6] = 5;
1688 swizzle_pipe[7] = 7;
1689 }
1690 break;
1691 }
1692
1693 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
1694 while (((1 << cur_backend) & enabled_backends_mask) == 0)
1695 cur_backend = (cur_backend + 1) % EVERGREEN_MAX_BACKENDS;
1696
1697 backend_map |= (((cur_backend & 0xf) << (swizzle_pipe[cur_pipe] * 4)));
1698
1699 cur_backend = (cur_backend + 1) % EVERGREEN_MAX_BACKENDS;
1700 }
1701
1702 return backend_map;
1703}
1704
1705static void evergreen_gpu_init(struct radeon_device *rdev) 1561static void evergreen_gpu_init(struct radeon_device *rdev)
1706{ 1562{
1707 u32 cc_rb_backend_disable = 0; 1563 u32 gb_addr_config;
1708 u32 cc_gc_shader_pipe_config;
1709 u32 gb_addr_config = 0;
1710 u32 mc_shared_chmap, mc_arb_ramcfg; 1564 u32 mc_shared_chmap, mc_arb_ramcfg;
1711 u32 gb_backend_map;
1712 u32 grbm_gfx_index;
1713 u32 sx_debug_1; 1565 u32 sx_debug_1;
1714 u32 smx_dc_ctl0; 1566 u32 smx_dc_ctl0;
1715 u32 sq_config; 1567 u32 sq_config;
@@ -1724,6 +1576,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1724 u32 sq_stack_resource_mgmt_3; 1576 u32 sq_stack_resource_mgmt_3;
1725 u32 vgt_cache_invalidation; 1577 u32 vgt_cache_invalidation;
1726 u32 hdp_host_path_cntl, tmp; 1578 u32 hdp_host_path_cntl, tmp;
1579 u32 disabled_rb_mask;
1727 int i, j, num_shader_engines, ps_thread_count; 1580 int i, j, num_shader_engines, ps_thread_count;
1728 1581
1729 switch (rdev->family) { 1582 switch (rdev->family) {
@@ -1748,6 +1601,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1748 rdev->config.evergreen.sc_prim_fifo_size = 0x100; 1601 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
1749 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; 1602 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1750 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; 1603 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
1604 gb_addr_config = CYPRESS_GB_ADDR_CONFIG_GOLDEN;
1751 break; 1605 break;
1752 case CHIP_JUNIPER: 1606 case CHIP_JUNIPER:
1753 rdev->config.evergreen.num_ses = 1; 1607 rdev->config.evergreen.num_ses = 1;
@@ -1769,6 +1623,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1769 rdev->config.evergreen.sc_prim_fifo_size = 0x100; 1623 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
1770 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; 1624 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1771 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; 1625 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
1626 gb_addr_config = JUNIPER_GB_ADDR_CONFIG_GOLDEN;
1772 break; 1627 break;
1773 case CHIP_REDWOOD: 1628 case CHIP_REDWOOD:
1774 rdev->config.evergreen.num_ses = 1; 1629 rdev->config.evergreen.num_ses = 1;
@@ -1790,6 +1645,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1790 rdev->config.evergreen.sc_prim_fifo_size = 0x100; 1645 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
1791 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; 1646 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1792 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; 1647 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
1648 gb_addr_config = REDWOOD_GB_ADDR_CONFIG_GOLDEN;
1793 break; 1649 break;
1794 case CHIP_CEDAR: 1650 case CHIP_CEDAR:
1795 default: 1651 default:
@@ -1812,6 +1668,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1812 rdev->config.evergreen.sc_prim_fifo_size = 0x40; 1668 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
1813 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; 1669 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1814 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; 1670 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
1671 gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
1815 break; 1672 break;
1816 case CHIP_PALM: 1673 case CHIP_PALM:
1817 rdev->config.evergreen.num_ses = 1; 1674 rdev->config.evergreen.num_ses = 1;
@@ -1833,6 +1690,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1833 rdev->config.evergreen.sc_prim_fifo_size = 0x40; 1690 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
1834 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; 1691 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1835 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; 1692 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
1693 gb_addr_config = CEDAR_GB_ADDR_CONFIG_GOLDEN;
1836 break; 1694 break;
1837 case CHIP_SUMO: 1695 case CHIP_SUMO:
1838 rdev->config.evergreen.num_ses = 1; 1696 rdev->config.evergreen.num_ses = 1;
@@ -1860,6 +1718,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1860 rdev->config.evergreen.sc_prim_fifo_size = 0x40; 1718 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
1861 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; 1719 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1862 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; 1720 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
1721 gb_addr_config = REDWOOD_GB_ADDR_CONFIG_GOLDEN;
1863 break; 1722 break;
1864 case CHIP_SUMO2: 1723 case CHIP_SUMO2:
1865 rdev->config.evergreen.num_ses = 1; 1724 rdev->config.evergreen.num_ses = 1;
@@ -1881,6 +1740,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1881 rdev->config.evergreen.sc_prim_fifo_size = 0x40; 1740 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
1882 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; 1741 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1883 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; 1742 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
1743 gb_addr_config = REDWOOD_GB_ADDR_CONFIG_GOLDEN;
1884 break; 1744 break;
1885 case CHIP_BARTS: 1745 case CHIP_BARTS:
1886 rdev->config.evergreen.num_ses = 2; 1746 rdev->config.evergreen.num_ses = 2;
@@ -1902,6 +1762,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1902 rdev->config.evergreen.sc_prim_fifo_size = 0x100; 1762 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
1903 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; 1763 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1904 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; 1764 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
1765 gb_addr_config = BARTS_GB_ADDR_CONFIG_GOLDEN;
1905 break; 1766 break;
1906 case CHIP_TURKS: 1767 case CHIP_TURKS:
1907 rdev->config.evergreen.num_ses = 1; 1768 rdev->config.evergreen.num_ses = 1;
@@ -1923,6 +1784,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1923 rdev->config.evergreen.sc_prim_fifo_size = 0x100; 1784 rdev->config.evergreen.sc_prim_fifo_size = 0x100;
1924 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; 1785 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1925 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; 1786 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
1787 gb_addr_config = TURKS_GB_ADDR_CONFIG_GOLDEN;
1926 break; 1788 break;
1927 case CHIP_CAICOS: 1789 case CHIP_CAICOS:
1928 rdev->config.evergreen.num_ses = 1; 1790 rdev->config.evergreen.num_ses = 1;
@@ -1944,6 +1806,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1944 rdev->config.evergreen.sc_prim_fifo_size = 0x40; 1806 rdev->config.evergreen.sc_prim_fifo_size = 0x40;
1945 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30; 1807 rdev->config.evergreen.sc_hiz_tile_fifo_size = 0x30;
1946 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130; 1808 rdev->config.evergreen.sc_earlyz_tile_fifo_size = 0x130;
1809 gb_addr_config = CAICOS_GB_ADDR_CONFIG_GOLDEN;
1947 break; 1810 break;
1948 } 1811 }
1949 1812
@@ -1960,20 +1823,6 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1960 1823
1961 evergreen_fix_pci_max_read_req_size(rdev); 1824 evergreen_fix_pci_max_read_req_size(rdev);
1962 1825
1963 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & ~2;
1964
1965 cc_gc_shader_pipe_config |=
1966 INACTIVE_QD_PIPES((EVERGREEN_MAX_PIPES_MASK << rdev->config.evergreen.max_pipes)
1967 & EVERGREEN_MAX_PIPES_MASK);
1968 cc_gc_shader_pipe_config |=
1969 INACTIVE_SIMDS((EVERGREEN_MAX_SIMDS_MASK << rdev->config.evergreen.max_simds)
1970 & EVERGREEN_MAX_SIMDS_MASK);
1971
1972 cc_rb_backend_disable =
1973 BACKEND_DISABLE((EVERGREEN_MAX_BACKENDS_MASK << rdev->config.evergreen.max_backends)
1974 & EVERGREEN_MAX_BACKENDS_MASK);
1975
1976
1977 mc_shared_chmap = RREG32(MC_SHARED_CHMAP); 1826 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
1978 if ((rdev->family == CHIP_PALM) || 1827 if ((rdev->family == CHIP_PALM) ||
1979 (rdev->family == CHIP_SUMO) || 1828 (rdev->family == CHIP_SUMO) ||
@@ -1982,134 +1831,6 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1982 else 1831 else
1983 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG); 1832 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
1984 1833
1985 switch (rdev->config.evergreen.max_tile_pipes) {
1986 case 1:
1987 default:
1988 gb_addr_config |= NUM_PIPES(0);
1989 break;
1990 case 2:
1991 gb_addr_config |= NUM_PIPES(1);
1992 break;
1993 case 4:
1994 gb_addr_config |= NUM_PIPES(2);
1995 break;
1996 case 8:
1997 gb_addr_config |= NUM_PIPES(3);
1998 break;
1999 }
2000
2001 gb_addr_config |= PIPE_INTERLEAVE_SIZE((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
2002 gb_addr_config |= BANK_INTERLEAVE_SIZE(0);
2003 gb_addr_config |= NUM_SHADER_ENGINES(rdev->config.evergreen.num_ses - 1);
2004 gb_addr_config |= SHADER_ENGINE_TILE_SIZE(1);
2005 gb_addr_config |= NUM_GPUS(0); /* Hemlock? */
2006 gb_addr_config |= MULTI_GPU_TILE_SIZE(2);
2007
2008 if (((mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT) > 2)
2009 gb_addr_config |= ROW_SIZE(2);
2010 else
2011 gb_addr_config |= ROW_SIZE((mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT);
2012
2013 if (rdev->ddev->pdev->device == 0x689e) {
2014 u32 efuse_straps_4;
2015 u32 efuse_straps_3;
2016 u8 efuse_box_bit_131_124;
2017
2018 WREG32(RCU_IND_INDEX, 0x204);
2019 efuse_straps_4 = RREG32(RCU_IND_DATA);
2020 WREG32(RCU_IND_INDEX, 0x203);
2021 efuse_straps_3 = RREG32(RCU_IND_DATA);
2022 efuse_box_bit_131_124 = (u8)(((efuse_straps_4 & 0xf) << 4) | ((efuse_straps_3 & 0xf0000000) >> 28));
2023
2024 switch(efuse_box_bit_131_124) {
2025 case 0x00:
2026 gb_backend_map = 0x76543210;
2027 break;
2028 case 0x55:
2029 gb_backend_map = 0x77553311;
2030 break;
2031 case 0x56:
2032 gb_backend_map = 0x77553300;
2033 break;
2034 case 0x59:
2035 gb_backend_map = 0x77552211;
2036 break;
2037 case 0x66:
2038 gb_backend_map = 0x77443300;
2039 break;
2040 case 0x99:
2041 gb_backend_map = 0x66552211;
2042 break;
2043 case 0x5a:
2044 gb_backend_map = 0x77552200;
2045 break;
2046 case 0xaa:
2047 gb_backend_map = 0x66442200;
2048 break;
2049 case 0x95:
2050 gb_backend_map = 0x66553311;
2051 break;
2052 default:
2053 DRM_ERROR("bad backend map, using default\n");
2054 gb_backend_map =
2055 evergreen_get_tile_pipe_to_backend_map(rdev,
2056 rdev->config.evergreen.max_tile_pipes,
2057 rdev->config.evergreen.max_backends,
2058 ((EVERGREEN_MAX_BACKENDS_MASK <<
2059 rdev->config.evergreen.max_backends) &
2060 EVERGREEN_MAX_BACKENDS_MASK));
2061 break;
2062 }
2063 } else if (rdev->ddev->pdev->device == 0x68b9) {
2064 u32 efuse_straps_3;
2065 u8 efuse_box_bit_127_124;
2066
2067 WREG32(RCU_IND_INDEX, 0x203);
2068 efuse_straps_3 = RREG32(RCU_IND_DATA);
2069 efuse_box_bit_127_124 = (u8)((efuse_straps_3 & 0xF0000000) >> 28);
2070
2071 switch(efuse_box_bit_127_124) {
2072 case 0x0:
2073 gb_backend_map = 0x00003210;
2074 break;
2075 case 0x5:
2076 case 0x6:
2077 case 0x9:
2078 case 0xa:
2079 gb_backend_map = 0x00003311;
2080 break;
2081 default:
2082 DRM_ERROR("bad backend map, using default\n");
2083 gb_backend_map =
2084 evergreen_get_tile_pipe_to_backend_map(rdev,
2085 rdev->config.evergreen.max_tile_pipes,
2086 rdev->config.evergreen.max_backends,
2087 ((EVERGREEN_MAX_BACKENDS_MASK <<
2088 rdev->config.evergreen.max_backends) &
2089 EVERGREEN_MAX_BACKENDS_MASK));
2090 break;
2091 }
2092 } else {
2093 switch (rdev->family) {
2094 case CHIP_CYPRESS:
2095 case CHIP_HEMLOCK:
2096 case CHIP_BARTS:
2097 gb_backend_map = 0x66442200;
2098 break;
2099 case CHIP_JUNIPER:
2100 gb_backend_map = 0x00002200;
2101 break;
2102 default:
2103 gb_backend_map =
2104 evergreen_get_tile_pipe_to_backend_map(rdev,
2105 rdev->config.evergreen.max_tile_pipes,
2106 rdev->config.evergreen.max_backends,
2107 ((EVERGREEN_MAX_BACKENDS_MASK <<
2108 rdev->config.evergreen.max_backends) &
2109 EVERGREEN_MAX_BACKENDS_MASK));
2110 }
2111 }
2112
2113 /* setup tiling info dword. gb_addr_config is not adequate since it does 1834 /* setup tiling info dword. gb_addr_config is not adequate since it does
2114 * not have bank info, so create a custom tiling dword. 1835 * not have bank info, so create a custom tiling dword.
2115 * bits 3:0 num_pipes 1836 * bits 3:0 num_pipes
@@ -2136,45 +1857,54 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
2136 /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */ 1857 /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
2137 if (rdev->flags & RADEON_IS_IGP) 1858 if (rdev->flags & RADEON_IS_IGP)
2138 rdev->config.evergreen.tile_config |= 1 << 4; 1859 rdev->config.evergreen.tile_config |= 1 << 4;
2139 else 1860 else {
2140 rdev->config.evergreen.tile_config |= 1861 if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT)
2141 ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) << 4; 1862 rdev->config.evergreen.tile_config |= 1 << 4;
2142 rdev->config.evergreen.tile_config |= 1863 else
2143 ((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT) << 8; 1864 rdev->config.evergreen.tile_config |= 0 << 4;
1865 }
1866 rdev->config.evergreen.tile_config |= 0 << 8;
2144 rdev->config.evergreen.tile_config |= 1867 rdev->config.evergreen.tile_config |=
2145 ((gb_addr_config & 0x30000000) >> 28) << 12; 1868 ((gb_addr_config & 0x30000000) >> 28) << 12;
2146 1869
2147 rdev->config.evergreen.backend_map = gb_backend_map; 1870 num_shader_engines = (gb_addr_config & NUM_SHADER_ENGINES(3) >> 12) + 1;
2148 WREG32(GB_BACKEND_MAP, gb_backend_map);
2149 WREG32(GB_ADDR_CONFIG, gb_addr_config);
2150 WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
2151 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
2152
2153 num_shader_engines = ((RREG32(GB_ADDR_CONFIG) & NUM_SHADER_ENGINES(3)) >> 12) + 1;
2154 grbm_gfx_index = INSTANCE_BROADCAST_WRITES;
2155 1871
2156 for (i = 0; i < rdev->config.evergreen.num_ses; i++) { 1872 if ((rdev->family >= CHIP_CEDAR) && (rdev->family <= CHIP_HEMLOCK)) {
2157 u32 rb = cc_rb_backend_disable | (0xf0 << 16); 1873 u32 efuse_straps_4;
2158 u32 sp = cc_gc_shader_pipe_config; 1874 u32 efuse_straps_3;
2159 u32 gfx = grbm_gfx_index | SE_INDEX(i);
2160 1875
2161 if (i == num_shader_engines) { 1876 WREG32(RCU_IND_INDEX, 0x204);
2162 rb |= BACKEND_DISABLE(EVERGREEN_MAX_BACKENDS_MASK); 1877 efuse_straps_4 = RREG32(RCU_IND_DATA);
2163 sp |= INACTIVE_SIMDS(EVERGREEN_MAX_SIMDS_MASK); 1878 WREG32(RCU_IND_INDEX, 0x203);
1879 efuse_straps_3 = RREG32(RCU_IND_DATA);
1880 tmp = (((efuse_straps_4 & 0xf) << 4) |
1881 ((efuse_straps_3 & 0xf0000000) >> 28));
1882 } else {
1883 tmp = 0;
1884 for (i = (rdev->config.evergreen.num_ses - 1); i >= 0; i--) {
1885 u32 rb_disable_bitmap;
1886
1887 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
1888 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
1889 rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
1890 tmp <<= 4;
1891 tmp |= rb_disable_bitmap;
2164 } 1892 }
1893 }
1894 /* enabled rb are just the one not disabled :) */
1895 disabled_rb_mask = tmp;
2165 1896
2166 WREG32(GRBM_GFX_INDEX, gfx); 1897 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
2167 WREG32(RLC_GFX_INDEX, gfx); 1898 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
2168 1899
2169 WREG32(CC_RB_BACKEND_DISABLE, rb); 1900 WREG32(GB_ADDR_CONFIG, gb_addr_config);
2170 WREG32(CC_SYS_RB_BACKEND_DISABLE, rb); 1901 WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
2171 WREG32(GC_USER_RB_BACKEND_DISABLE, rb); 1902 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
2172 WREG32(CC_GC_SHADER_PIPE_CONFIG, sp);
2173 }
2174 1903
2175 grbm_gfx_index |= SE_BROADCAST_WRITES; 1904 tmp = gb_addr_config & NUM_PIPES_MASK;
2176 WREG32(GRBM_GFX_INDEX, grbm_gfx_index); 1905 tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.evergreen.max_backends,
2177 WREG32(RLC_GFX_INDEX, grbm_gfx_index); 1906 EVERGREEN_MAX_BACKENDS, disabled_rb_mask);
1907 WREG32(GB_BACKEND_MAP, tmp);
2178 1908
2179 WREG32(CGTS_SYS_TCC_DISABLE, 0); 1909 WREG32(CGTS_SYS_TCC_DISABLE, 0);
2180 WREG32(CGTS_TCC_DISABLE, 0); 1910 WREG32(CGTS_TCC_DISABLE, 0);
diff --git a/drivers/gpu/drm/radeon/evergreend.h b/drivers/gpu/drm/radeon/evergreend.h
index 79130bfd1d6f..2773039b4902 100644
--- a/drivers/gpu/drm/radeon/evergreend.h
+++ b/drivers/gpu/drm/radeon/evergreend.h
@@ -37,6 +37,15 @@
37#define EVERGREEN_MAX_PIPES_MASK 0xFF 37#define EVERGREEN_MAX_PIPES_MASK 0xFF
38#define EVERGREEN_MAX_LDS_NUM 0xFFFF 38#define EVERGREEN_MAX_LDS_NUM 0xFFFF
39 39
40#define CYPRESS_GB_ADDR_CONFIG_GOLDEN 0x02011003
41#define BARTS_GB_ADDR_CONFIG_GOLDEN 0x02011003
42#define CAYMAN_GB_ADDR_CONFIG_GOLDEN 0x02011003
43#define JUNIPER_GB_ADDR_CONFIG_GOLDEN 0x02010002
44#define REDWOOD_GB_ADDR_CONFIG_GOLDEN 0x02010002
45#define TURKS_GB_ADDR_CONFIG_GOLDEN 0x02010002
46#define CEDAR_GB_ADDR_CONFIG_GOLDEN 0x02010001
47#define CAICOS_GB_ADDR_CONFIG_GOLDEN 0x02010001
48
40/* Registers */ 49/* Registers */
41 50
42#define RCU_IND_INDEX 0x100 51#define RCU_IND_INDEX 0x100
@@ -54,6 +63,7 @@
54#define BACKEND_DISABLE(x) ((x) << 16) 63#define BACKEND_DISABLE(x) ((x) << 16)
55#define GB_ADDR_CONFIG 0x98F8 64#define GB_ADDR_CONFIG 0x98F8
56#define NUM_PIPES(x) ((x) << 0) 65#define NUM_PIPES(x) ((x) << 0)
66#define NUM_PIPES_MASK 0x0000000f
57#define PIPE_INTERLEAVE_SIZE(x) ((x) << 4) 67#define PIPE_INTERLEAVE_SIZE(x) ((x) << 4)
58#define BANK_INTERLEAVE_SIZE(x) ((x) << 8) 68#define BANK_INTERLEAVE_SIZE(x) ((x) << 8)
59#define NUM_SHADER_ENGINES(x) ((x) << 12) 69#define NUM_SHADER_ENGINES(x) ((x) << 12)
@@ -452,6 +462,7 @@
452#define MC_VM_MD_L1_TLB0_CNTL 0x2654 462#define MC_VM_MD_L1_TLB0_CNTL 0x2654
453#define MC_VM_MD_L1_TLB1_CNTL 0x2658 463#define MC_VM_MD_L1_TLB1_CNTL 0x2658
454#define MC_VM_MD_L1_TLB2_CNTL 0x265C 464#define MC_VM_MD_L1_TLB2_CNTL 0x265C
465#define MC_VM_MD_L1_TLB3_CNTL 0x2698
455 466
456#define FUS_MC_VM_MD_L1_TLB0_CNTL 0x265C 467#define FUS_MC_VM_MD_L1_TLB0_CNTL 0x265C
457#define FUS_MC_VM_MD_L1_TLB1_CNTL 0x2660 468#define FUS_MC_VM_MD_L1_TLB1_CNTL 0x2660
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index ce4e7cc6c905..3df4efa11942 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -417,215 +417,17 @@ out:
417/* 417/*
418 * Core functions 418 * Core functions
419 */ 419 */
420static u32 cayman_get_tile_pipe_to_backend_map(struct radeon_device *rdev,
421 u32 num_tile_pipes,
422 u32 num_backends_per_asic,
423 u32 *backend_disable_mask_per_asic,
424 u32 num_shader_engines)
425{
426 u32 backend_map = 0;
427 u32 enabled_backends_mask = 0;
428 u32 enabled_backends_count = 0;
429 u32 num_backends_per_se;
430 u32 cur_pipe;
431 u32 swizzle_pipe[CAYMAN_MAX_PIPES];
432 u32 cur_backend = 0;
433 u32 i;
434 bool force_no_swizzle;
435
436 /* force legal values */
437 if (num_tile_pipes < 1)
438 num_tile_pipes = 1;
439 if (num_tile_pipes > rdev->config.cayman.max_tile_pipes)
440 num_tile_pipes = rdev->config.cayman.max_tile_pipes;
441 if (num_shader_engines < 1)
442 num_shader_engines = 1;
443 if (num_shader_engines > rdev->config.cayman.max_shader_engines)
444 num_shader_engines = rdev->config.cayman.max_shader_engines;
445 if (num_backends_per_asic < num_shader_engines)
446 num_backends_per_asic = num_shader_engines;
447 if (num_backends_per_asic > (rdev->config.cayman.max_backends_per_se * num_shader_engines))
448 num_backends_per_asic = rdev->config.cayman.max_backends_per_se * num_shader_engines;
449
450 /* make sure we have the same number of backends per se */
451 num_backends_per_asic = ALIGN(num_backends_per_asic, num_shader_engines);
452 /* set up the number of backends per se */
453 num_backends_per_se = num_backends_per_asic / num_shader_engines;
454 if (num_backends_per_se > rdev->config.cayman.max_backends_per_se) {
455 num_backends_per_se = rdev->config.cayman.max_backends_per_se;
456 num_backends_per_asic = num_backends_per_se * num_shader_engines;
457 }
458
459 /* create enable mask and count for enabled backends */
460 for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) {
461 if (((*backend_disable_mask_per_asic >> i) & 1) == 0) {
462 enabled_backends_mask |= (1 << i);
463 ++enabled_backends_count;
464 }
465 if (enabled_backends_count == num_backends_per_asic)
466 break;
467 }
468
469 /* force the backends mask to match the current number of backends */
470 if (enabled_backends_count != num_backends_per_asic) {
471 u32 this_backend_enabled;
472 u32 shader_engine;
473 u32 backend_per_se;
474
475 enabled_backends_mask = 0;
476 enabled_backends_count = 0;
477 *backend_disable_mask_per_asic = CAYMAN_MAX_BACKENDS_MASK;
478 for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) {
479 /* calc the current se */
480 shader_engine = i / rdev->config.cayman.max_backends_per_se;
481 /* calc the backend per se */
482 backend_per_se = i % rdev->config.cayman.max_backends_per_se;
483 /* default to not enabled */
484 this_backend_enabled = 0;
485 if ((shader_engine < num_shader_engines) &&
486 (backend_per_se < num_backends_per_se))
487 this_backend_enabled = 1;
488 if (this_backend_enabled) {
489 enabled_backends_mask |= (1 << i);
490 *backend_disable_mask_per_asic &= ~(1 << i);
491 ++enabled_backends_count;
492 }
493 }
494 }
495
496
497 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * CAYMAN_MAX_PIPES);
498 switch (rdev->family) {
499 case CHIP_CAYMAN:
500 case CHIP_ARUBA:
501 force_no_swizzle = true;
502 break;
503 default:
504 force_no_swizzle = false;
505 break;
506 }
507 if (force_no_swizzle) {
508 bool last_backend_enabled = false;
509
510 force_no_swizzle = false;
511 for (i = 0; i < CAYMAN_MAX_BACKENDS; ++i) {
512 if (((enabled_backends_mask >> i) & 1) == 1) {
513 if (last_backend_enabled)
514 force_no_swizzle = true;
515 last_backend_enabled = true;
516 } else
517 last_backend_enabled = false;
518 }
519 }
520
521 switch (num_tile_pipes) {
522 case 1:
523 case 3:
524 case 5:
525 case 7:
526 DRM_ERROR("odd number of pipes!\n");
527 break;
528 case 2:
529 swizzle_pipe[0] = 0;
530 swizzle_pipe[1] = 1;
531 break;
532 case 4:
533 if (force_no_swizzle) {
534 swizzle_pipe[0] = 0;
535 swizzle_pipe[1] = 1;
536 swizzle_pipe[2] = 2;
537 swizzle_pipe[3] = 3;
538 } else {
539 swizzle_pipe[0] = 0;
540 swizzle_pipe[1] = 2;
541 swizzle_pipe[2] = 1;
542 swizzle_pipe[3] = 3;
543 }
544 break;
545 case 6:
546 if (force_no_swizzle) {
547 swizzle_pipe[0] = 0;
548 swizzle_pipe[1] = 1;
549 swizzle_pipe[2] = 2;
550 swizzle_pipe[3] = 3;
551 swizzle_pipe[4] = 4;
552 swizzle_pipe[5] = 5;
553 } else {
554 swizzle_pipe[0] = 0;
555 swizzle_pipe[1] = 2;
556 swizzle_pipe[2] = 4;
557 swizzle_pipe[3] = 1;
558 swizzle_pipe[4] = 3;
559 swizzle_pipe[5] = 5;
560 }
561 break;
562 case 8:
563 if (force_no_swizzle) {
564 swizzle_pipe[0] = 0;
565 swizzle_pipe[1] = 1;
566 swizzle_pipe[2] = 2;
567 swizzle_pipe[3] = 3;
568 swizzle_pipe[4] = 4;
569 swizzle_pipe[5] = 5;
570 swizzle_pipe[6] = 6;
571 swizzle_pipe[7] = 7;
572 } else {
573 swizzle_pipe[0] = 0;
574 swizzle_pipe[1] = 2;
575 swizzle_pipe[2] = 4;
576 swizzle_pipe[3] = 6;
577 swizzle_pipe[4] = 1;
578 swizzle_pipe[5] = 3;
579 swizzle_pipe[6] = 5;
580 swizzle_pipe[7] = 7;
581 }
582 break;
583 }
584
585 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
586 while (((1 << cur_backend) & enabled_backends_mask) == 0)
587 cur_backend = (cur_backend + 1) % CAYMAN_MAX_BACKENDS;
588
589 backend_map |= (((cur_backend & 0xf) << (swizzle_pipe[cur_pipe] * 4)));
590
591 cur_backend = (cur_backend + 1) % CAYMAN_MAX_BACKENDS;
592 }
593
594 return backend_map;
595}
596
597static u32 cayman_get_disable_mask_per_asic(struct radeon_device *rdev,
598 u32 disable_mask_per_se,
599 u32 max_disable_mask_per_se,
600 u32 num_shader_engines)
601{
602 u32 disable_field_width_per_se = r600_count_pipe_bits(disable_mask_per_se);
603 u32 disable_mask_per_asic = disable_mask_per_se & max_disable_mask_per_se;
604
605 if (num_shader_engines == 1)
606 return disable_mask_per_asic;
607 else if (num_shader_engines == 2)
608 return disable_mask_per_asic | (disable_mask_per_asic << disable_field_width_per_se);
609 else
610 return 0xffffffff;
611}
612
613static void cayman_gpu_init(struct radeon_device *rdev) 420static void cayman_gpu_init(struct radeon_device *rdev)
614{ 421{
615 u32 cc_rb_backend_disable = 0;
616 u32 cc_gc_shader_pipe_config;
617 u32 gb_addr_config = 0; 422 u32 gb_addr_config = 0;
618 u32 mc_shared_chmap, mc_arb_ramcfg; 423 u32 mc_shared_chmap, mc_arb_ramcfg;
619 u32 gb_backend_map;
620 u32 cgts_tcc_disable; 424 u32 cgts_tcc_disable;
621 u32 sx_debug_1; 425 u32 sx_debug_1;
622 u32 smx_dc_ctl0; 426 u32 smx_dc_ctl0;
623 u32 gc_user_shader_pipe_config;
624 u32 gc_user_rb_backend_disable;
625 u32 cgts_user_tcc_disable;
626 u32 cgts_sm_ctrl_reg; 427 u32 cgts_sm_ctrl_reg;
627 u32 hdp_host_path_cntl; 428 u32 hdp_host_path_cntl;
628 u32 tmp; 429 u32 tmp;
430 u32 disabled_rb_mask;
629 int i, j; 431 int i, j;
630 432
631 switch (rdev->family) { 433 switch (rdev->family) {
@@ -650,6 +452,7 @@ static void cayman_gpu_init(struct radeon_device *rdev)
650 rdev->config.cayman.sc_prim_fifo_size = 0x100; 452 rdev->config.cayman.sc_prim_fifo_size = 0x100;
651 rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30; 453 rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
652 rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130; 454 rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
455 gb_addr_config = CAYMAN_GB_ADDR_CONFIG_GOLDEN;
653 break; 456 break;
654 case CHIP_ARUBA: 457 case CHIP_ARUBA:
655 default: 458 default:
@@ -687,6 +490,7 @@ static void cayman_gpu_init(struct radeon_device *rdev)
687 rdev->config.cayman.sc_prim_fifo_size = 0x40; 490 rdev->config.cayman.sc_prim_fifo_size = 0x40;
688 rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30; 491 rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
689 rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130; 492 rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
493 gb_addr_config = ARUBA_GB_ADDR_CONFIG_GOLDEN;
690 break; 494 break;
691 } 495 }
692 496
@@ -706,39 +510,6 @@ static void cayman_gpu_init(struct radeon_device *rdev)
706 mc_shared_chmap = RREG32(MC_SHARED_CHMAP); 510 mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
707 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG); 511 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
708 512
709 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE);
710 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG);
711 cgts_tcc_disable = 0xffff0000;
712 for (i = 0; i < rdev->config.cayman.max_texture_channel_caches; i++)
713 cgts_tcc_disable &= ~(1 << (16 + i));
714 gc_user_rb_backend_disable = RREG32(GC_USER_RB_BACKEND_DISABLE);
715 gc_user_shader_pipe_config = RREG32(GC_USER_SHADER_PIPE_CONFIG);
716 cgts_user_tcc_disable = RREG32(CGTS_USER_TCC_DISABLE);
717
718 rdev->config.cayman.num_shader_engines = rdev->config.cayman.max_shader_engines;
719 tmp = ((~gc_user_shader_pipe_config) & INACTIVE_QD_PIPES_MASK) >> INACTIVE_QD_PIPES_SHIFT;
720 rdev->config.cayman.num_shader_pipes_per_simd = r600_count_pipe_bits(tmp);
721 rdev->config.cayman.num_tile_pipes = rdev->config.cayman.max_tile_pipes;
722 tmp = ((~gc_user_shader_pipe_config) & INACTIVE_SIMDS_MASK) >> INACTIVE_SIMDS_SHIFT;
723 rdev->config.cayman.num_simds_per_se = r600_count_pipe_bits(tmp);
724 tmp = ((~gc_user_rb_backend_disable) & BACKEND_DISABLE_MASK) >> BACKEND_DISABLE_SHIFT;
725 rdev->config.cayman.num_backends_per_se = r600_count_pipe_bits(tmp);
726 tmp = (gc_user_rb_backend_disable & BACKEND_DISABLE_MASK) >> BACKEND_DISABLE_SHIFT;
727 rdev->config.cayman.backend_disable_mask_per_asic =
728 cayman_get_disable_mask_per_asic(rdev, tmp, CAYMAN_MAX_BACKENDS_PER_SE_MASK,
729 rdev->config.cayman.num_shader_engines);
730 rdev->config.cayman.backend_map =
731 cayman_get_tile_pipe_to_backend_map(rdev, rdev->config.cayman.num_tile_pipes,
732 rdev->config.cayman.num_backends_per_se *
733 rdev->config.cayman.num_shader_engines,
734 &rdev->config.cayman.backend_disable_mask_per_asic,
735 rdev->config.cayman.num_shader_engines);
736 tmp = ((~cgts_user_tcc_disable) & TCC_DISABLE_MASK) >> TCC_DISABLE_SHIFT;
737 rdev->config.cayman.num_texture_channel_caches = r600_count_pipe_bits(tmp);
738 tmp = (mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT;
739 rdev->config.cayman.mem_max_burst_length_bytes = (tmp + 1) * 256;
740 if (rdev->config.cayman.mem_max_burst_length_bytes > 512)
741 rdev->config.cayman.mem_max_burst_length_bytes = 512;
742 tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT; 513 tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
743 rdev->config.cayman.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024; 514 rdev->config.cayman.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
744 if (rdev->config.cayman.mem_row_size_in_kb > 4) 515 if (rdev->config.cayman.mem_row_size_in_kb > 4)
@@ -748,73 +519,6 @@ static void cayman_gpu_init(struct radeon_device *rdev)
748 rdev->config.cayman.num_gpus = 1; 519 rdev->config.cayman.num_gpus = 1;
749 rdev->config.cayman.multi_gpu_tile_size = 64; 520 rdev->config.cayman.multi_gpu_tile_size = 64;
750 521
751 //gb_addr_config = 0x02011003
752#if 0
753 gb_addr_config = RREG32(GB_ADDR_CONFIG);
754#else
755 gb_addr_config = 0;
756 switch (rdev->config.cayman.num_tile_pipes) {
757 case 1:
758 default:
759 gb_addr_config |= NUM_PIPES(0);
760 break;
761 case 2:
762 gb_addr_config |= NUM_PIPES(1);
763 break;
764 case 4:
765 gb_addr_config |= NUM_PIPES(2);
766 break;
767 case 8:
768 gb_addr_config |= NUM_PIPES(3);
769 break;
770 }
771
772 tmp = (rdev->config.cayman.mem_max_burst_length_bytes / 256) - 1;
773 gb_addr_config |= PIPE_INTERLEAVE_SIZE(tmp);
774 gb_addr_config |= NUM_SHADER_ENGINES(rdev->config.cayman.num_shader_engines - 1);
775 tmp = (rdev->config.cayman.shader_engine_tile_size / 16) - 1;
776 gb_addr_config |= SHADER_ENGINE_TILE_SIZE(tmp);
777 switch (rdev->config.cayman.num_gpus) {
778 case 1:
779 default:
780 gb_addr_config |= NUM_GPUS(0);
781 break;
782 case 2:
783 gb_addr_config |= NUM_GPUS(1);
784 break;
785 case 4:
786 gb_addr_config |= NUM_GPUS(2);
787 break;
788 }
789 switch (rdev->config.cayman.multi_gpu_tile_size) {
790 case 16:
791 gb_addr_config |= MULTI_GPU_TILE_SIZE(0);
792 break;
793 case 32:
794 default:
795 gb_addr_config |= MULTI_GPU_TILE_SIZE(1);
796 break;
797 case 64:
798 gb_addr_config |= MULTI_GPU_TILE_SIZE(2);
799 break;
800 case 128:
801 gb_addr_config |= MULTI_GPU_TILE_SIZE(3);
802 break;
803 }
804 switch (rdev->config.cayman.mem_row_size_in_kb) {
805 case 1:
806 default:
807 gb_addr_config |= ROW_SIZE(0);
808 break;
809 case 2:
810 gb_addr_config |= ROW_SIZE(1);
811 break;
812 case 4:
813 gb_addr_config |= ROW_SIZE(2);
814 break;
815 }
816#endif
817
818 tmp = (gb_addr_config & NUM_PIPES_MASK) >> NUM_PIPES_SHIFT; 522 tmp = (gb_addr_config & NUM_PIPES_MASK) >> NUM_PIPES_SHIFT;
819 rdev->config.cayman.num_tile_pipes = (1 << tmp); 523 rdev->config.cayman.num_tile_pipes = (1 << tmp);
820 tmp = (gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT; 524 tmp = (gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT;
@@ -828,17 +532,7 @@ static void cayman_gpu_init(struct radeon_device *rdev)
828 tmp = (gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT; 532 tmp = (gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT;
829 rdev->config.cayman.mem_row_size_in_kb = 1 << tmp; 533 rdev->config.cayman.mem_row_size_in_kb = 1 << tmp;
830 534
831 //gb_backend_map = 0x76541032; 535
832#if 0
833 gb_backend_map = RREG32(GB_BACKEND_MAP);
834#else
835 gb_backend_map =
836 cayman_get_tile_pipe_to_backend_map(rdev, rdev->config.cayman.num_tile_pipes,
837 rdev->config.cayman.num_backends_per_se *
838 rdev->config.cayman.num_shader_engines,
839 &rdev->config.cayman.backend_disable_mask_per_asic,
840 rdev->config.cayman.num_shader_engines);
841#endif
842 /* setup tiling info dword. gb_addr_config is not adequate since it does 536 /* setup tiling info dword. gb_addr_config is not adequate since it does
843 * not have bank info, so create a custom tiling dword. 537 * not have bank info, so create a custom tiling dword.
844 * bits 3:0 num_pipes 538 * bits 3:0 num_pipes
@@ -866,33 +560,49 @@ static void cayman_gpu_init(struct radeon_device *rdev)
866 /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */ 560 /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
867 if (rdev->flags & RADEON_IS_IGP) 561 if (rdev->flags & RADEON_IS_IGP)
868 rdev->config.cayman.tile_config |= 1 << 4; 562 rdev->config.cayman.tile_config |= 1 << 4;
869 else 563 else {
870 rdev->config.cayman.tile_config |= 564 if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT)
871 ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) << 4; 565 rdev->config.cayman.tile_config |= 1 << 4;
566 else
567 rdev->config.cayman.tile_config |= 0 << 4;
568 }
872 rdev->config.cayman.tile_config |= 569 rdev->config.cayman.tile_config |=
873 ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8; 570 ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
874 rdev->config.cayman.tile_config |= 571 rdev->config.cayman.tile_config |=
875 ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12; 572 ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
876 573
877 rdev->config.cayman.backend_map = gb_backend_map; 574 tmp = 0;
878 WREG32(GB_BACKEND_MAP, gb_backend_map); 575 for (i = (rdev->config.cayman.max_shader_engines - 1); i >= 0; i--) {
576 u32 rb_disable_bitmap;
577
578 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
579 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
580 rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
581 tmp <<= 4;
582 tmp |= rb_disable_bitmap;
583 }
584 /* enabled rb are just the one not disabled :) */
585 disabled_rb_mask = tmp;
586
587 WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
588 WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
589
879 WREG32(GB_ADDR_CONFIG, gb_addr_config); 590 WREG32(GB_ADDR_CONFIG, gb_addr_config);
880 WREG32(DMIF_ADDR_CONFIG, gb_addr_config); 591 WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
881 WREG32(HDP_ADDR_CONFIG, gb_addr_config); 592 WREG32(HDP_ADDR_CONFIG, gb_addr_config);
882 593
883 /* primary versions */ 594 tmp = gb_addr_config & NUM_PIPES_MASK;
884 WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable); 595 tmp = r6xx_remap_render_backend(rdev, tmp,
885 WREG32(CC_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable); 596 rdev->config.cayman.max_backends_per_se *
886 WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config); 597 rdev->config.cayman.max_shader_engines,
598 CAYMAN_MAX_BACKENDS, disabled_rb_mask);
599 WREG32(GB_BACKEND_MAP, tmp);
887 600
601 cgts_tcc_disable = 0xffff0000;
602 for (i = 0; i < rdev->config.cayman.max_texture_channel_caches; i++)
603 cgts_tcc_disable &= ~(1 << (16 + i));
888 WREG32(CGTS_TCC_DISABLE, cgts_tcc_disable); 604 WREG32(CGTS_TCC_DISABLE, cgts_tcc_disable);
889 WREG32(CGTS_SYS_TCC_DISABLE, cgts_tcc_disable); 605 WREG32(CGTS_SYS_TCC_DISABLE, cgts_tcc_disable);
890
891 /* user versions */
892 WREG32(GC_USER_RB_BACKEND_DISABLE, cc_rb_backend_disable);
893 WREG32(GC_USER_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable);
894 WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
895
896 WREG32(CGTS_USER_SYS_TCC_DISABLE, cgts_tcc_disable); 606 WREG32(CGTS_USER_SYS_TCC_DISABLE, cgts_tcc_disable);
897 WREG32(CGTS_USER_TCC_DISABLE, cgts_tcc_disable); 607 WREG32(CGTS_USER_TCC_DISABLE, cgts_tcc_disable);
898 608
diff --git a/drivers/gpu/drm/radeon/nid.h b/drivers/gpu/drm/radeon/nid.h
index 2aa7046ada56..a0b98066e207 100644
--- a/drivers/gpu/drm/radeon/nid.h
+++ b/drivers/gpu/drm/radeon/nid.h
@@ -41,6 +41,9 @@
41#define CAYMAN_MAX_TCC 16 41#define CAYMAN_MAX_TCC 16
42#define CAYMAN_MAX_TCC_MASK 0xFF 42#define CAYMAN_MAX_TCC_MASK 0xFF
43 43
44#define CAYMAN_GB_ADDR_CONFIG_GOLDEN 0x02011003
45#define ARUBA_GB_ADDR_CONFIG_GOLDEN 0x12010001
46
44#define DMIF_ADDR_CONFIG 0xBD4 47#define DMIF_ADDR_CONFIG 0xBD4
45#define SRBM_GFX_CNTL 0x0E44 48#define SRBM_GFX_CNTL 0x0E44
46#define RINGID(x) (((x) & 0x3) << 0) 49#define RINGID(x) (((x) & 0x3) << 0)
@@ -148,6 +151,8 @@
148#define CGTS_SYS_TCC_DISABLE 0x3F90 151#define CGTS_SYS_TCC_DISABLE 0x3F90
149#define CGTS_USER_SYS_TCC_DISABLE 0x3F94 152#define CGTS_USER_SYS_TCC_DISABLE 0x3F94
150 153
154#define RLC_GFX_INDEX 0x3FC4
155
151#define CONFIG_MEMSIZE 0x5428 156#define CONFIG_MEMSIZE 0x5428
152 157
153#define HDP_MEM_COHERENCY_FLUSH_CNTL 0x5480 158#define HDP_MEM_COHERENCY_FLUSH_CNTL 0x5480
@@ -212,6 +217,12 @@
212#define SOFT_RESET_VGT (1 << 14) 217#define SOFT_RESET_VGT (1 << 14)
213#define SOFT_RESET_IA (1 << 15) 218#define SOFT_RESET_IA (1 << 15)
214 219
220#define GRBM_GFX_INDEX 0x802C
221#define INSTANCE_INDEX(x) ((x) << 0)
222#define SE_INDEX(x) ((x) << 16)
223#define INSTANCE_BROADCAST_WRITES (1 << 30)
224#define SE_BROADCAST_WRITES (1 << 31)
225
215#define SCRATCH_REG0 0x8500 226#define SCRATCH_REG0 0x8500
216#define SCRATCH_REG1 0x8504 227#define SCRATCH_REG1 0x8504
217#define SCRATCH_REG2 0x8508 228#define SCRATCH_REG2 0x8508
diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
index f388a1d73b63..45cfcea63507 100644
--- a/drivers/gpu/drm/radeon/r600.c
+++ b/drivers/gpu/drm/radeon/r600.c
@@ -1376,113 +1376,51 @@ int r600_asic_reset(struct radeon_device *rdev)
1376 return r600_gpu_soft_reset(rdev); 1376 return r600_gpu_soft_reset(rdev);
1377} 1377}
1378 1378
1379static u32 r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes, 1379u32 r6xx_remap_render_backend(struct radeon_device *rdev,
1380 u32 num_backends, 1380 u32 tiling_pipe_num,
1381 u32 backend_disable_mask) 1381 u32 max_rb_num,
1382{ 1382 u32 total_max_rb_num,
1383 u32 backend_map = 0; 1383 u32 disabled_rb_mask)
1384 u32 enabled_backends_mask; 1384{
1385 u32 enabled_backends_count; 1385 u32 rendering_pipe_num, rb_num_width, req_rb_num;
1386 u32 cur_pipe; 1386 u32 pipe_rb_ratio, pipe_rb_remain;
1387 u32 swizzle_pipe[R6XX_MAX_PIPES]; 1387 u32 data = 0, mask = 1 << (max_rb_num - 1);
1388 u32 cur_backend; 1388 unsigned i, j;
1389 u32 i; 1389
1390 1390 /* mask out the RBs that don't exist on that asic */
1391 if (num_tile_pipes > R6XX_MAX_PIPES) 1391 disabled_rb_mask |= (0xff << max_rb_num) & 0xff;
1392 num_tile_pipes = R6XX_MAX_PIPES; 1392
1393 if (num_tile_pipes < 1) 1393 rendering_pipe_num = 1 << tiling_pipe_num;
1394 num_tile_pipes = 1; 1394 req_rb_num = total_max_rb_num - r600_count_pipe_bits(disabled_rb_mask);
1395 if (num_backends > R6XX_MAX_BACKENDS) 1395 BUG_ON(rendering_pipe_num < req_rb_num);
1396 num_backends = R6XX_MAX_BACKENDS; 1396
1397 if (num_backends < 1) 1397 pipe_rb_ratio = rendering_pipe_num / req_rb_num;
1398 num_backends = 1; 1398 pipe_rb_remain = rendering_pipe_num - pipe_rb_ratio * req_rb_num;
1399 1399
1400 enabled_backends_mask = 0; 1400 if (rdev->family <= CHIP_RV740) {
1401 enabled_backends_count = 0; 1401 /* r6xx/r7xx */
1402 for (i = 0; i < R6XX_MAX_BACKENDS; ++i) { 1402 rb_num_width = 2;
1403 if (((backend_disable_mask >> i) & 1) == 0) { 1403 } else {
1404 enabled_backends_mask |= (1 << i); 1404 /* eg+ */
1405 ++enabled_backends_count; 1405 rb_num_width = 4;
1406 }
1407 if (enabled_backends_count == num_backends)
1408 break;
1409 }
1410
1411 if (enabled_backends_count == 0) {
1412 enabled_backends_mask = 1;
1413 enabled_backends_count = 1;
1414 }
1415
1416 if (enabled_backends_count != num_backends)
1417 num_backends = enabled_backends_count;
1418
1419 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R6XX_MAX_PIPES);
1420 switch (num_tile_pipes) {
1421 case 1:
1422 swizzle_pipe[0] = 0;
1423 break;
1424 case 2:
1425 swizzle_pipe[0] = 0;
1426 swizzle_pipe[1] = 1;
1427 break;
1428 case 3:
1429 swizzle_pipe[0] = 0;
1430 swizzle_pipe[1] = 1;
1431 swizzle_pipe[2] = 2;
1432 break;
1433 case 4:
1434 swizzle_pipe[0] = 0;
1435 swizzle_pipe[1] = 1;
1436 swizzle_pipe[2] = 2;
1437 swizzle_pipe[3] = 3;
1438 break;
1439 case 5:
1440 swizzle_pipe[0] = 0;
1441 swizzle_pipe[1] = 1;
1442 swizzle_pipe[2] = 2;
1443 swizzle_pipe[3] = 3;
1444 swizzle_pipe[4] = 4;
1445 break;
1446 case 6:
1447 swizzle_pipe[0] = 0;
1448 swizzle_pipe[1] = 2;
1449 swizzle_pipe[2] = 4;
1450 swizzle_pipe[3] = 5;
1451 swizzle_pipe[4] = 1;
1452 swizzle_pipe[5] = 3;
1453 break;
1454 case 7:
1455 swizzle_pipe[0] = 0;
1456 swizzle_pipe[1] = 2;
1457 swizzle_pipe[2] = 4;
1458 swizzle_pipe[3] = 6;
1459 swizzle_pipe[4] = 1;
1460 swizzle_pipe[5] = 3;
1461 swizzle_pipe[6] = 5;
1462 break;
1463 case 8:
1464 swizzle_pipe[0] = 0;
1465 swizzle_pipe[1] = 2;
1466 swizzle_pipe[2] = 4;
1467 swizzle_pipe[3] = 6;
1468 swizzle_pipe[4] = 1;
1469 swizzle_pipe[5] = 3;
1470 swizzle_pipe[6] = 5;
1471 swizzle_pipe[7] = 7;
1472 break;
1473 } 1406 }
1474 1407
1475 cur_backend = 0; 1408 for (i = 0; i < max_rb_num; i++) {
1476 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) { 1409 if (!(mask & disabled_rb_mask)) {
1477 while (((1 << cur_backend) & enabled_backends_mask) == 0) 1410 for (j = 0; j < pipe_rb_ratio; j++) {
1478 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS; 1411 data <<= rb_num_width;
1479 1412 data |= max_rb_num - i - 1;
1480 backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2))); 1413 }
1481 1414 if (pipe_rb_remain) {
1482 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS; 1415 data <<= rb_num_width;
1416 data |= max_rb_num - i - 1;
1417 pipe_rb_remain--;
1418 }
1419 }
1420 mask >>= 1;
1483 } 1421 }
1484 1422
1485 return backend_map; 1423 return data;
1486} 1424}
1487 1425
1488int r600_count_pipe_bits(uint32_t val) 1426int r600_count_pipe_bits(uint32_t val)
@@ -1500,7 +1438,6 @@ void r600_gpu_init(struct radeon_device *rdev)
1500{ 1438{
1501 u32 tiling_config; 1439 u32 tiling_config;
1502 u32 ramcfg; 1440 u32 ramcfg;
1503 u32 backend_map;
1504 u32 cc_rb_backend_disable; 1441 u32 cc_rb_backend_disable;
1505 u32 cc_gc_shader_pipe_config; 1442 u32 cc_gc_shader_pipe_config;
1506 u32 tmp; 1443 u32 tmp;
@@ -1511,8 +1448,9 @@ void r600_gpu_init(struct radeon_device *rdev)
1511 u32 sq_thread_resource_mgmt = 0; 1448 u32 sq_thread_resource_mgmt = 0;
1512 u32 sq_stack_resource_mgmt_1 = 0; 1449 u32 sq_stack_resource_mgmt_1 = 0;
1513 u32 sq_stack_resource_mgmt_2 = 0; 1450 u32 sq_stack_resource_mgmt_2 = 0;
1451 u32 disabled_rb_mask;
1514 1452
1515 /* FIXME: implement */ 1453 rdev->config.r600.tiling_group_size = 256;
1516 switch (rdev->family) { 1454 switch (rdev->family) {
1517 case CHIP_R600: 1455 case CHIP_R600:
1518 rdev->config.r600.max_pipes = 4; 1456 rdev->config.r600.max_pipes = 4;
@@ -1616,10 +1554,7 @@ void r600_gpu_init(struct radeon_device *rdev)
1616 rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT); 1554 rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
1617 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT); 1555 tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
1618 tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT); 1556 tiling_config |= GROUP_SIZE((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
1619 if ((ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT) 1557
1620 rdev->config.r600.tiling_group_size = 512;
1621 else
1622 rdev->config.r600.tiling_group_size = 256;
1623 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT; 1558 tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
1624 if (tmp > 3) { 1559 if (tmp > 3) {
1625 tiling_config |= ROW_TILING(3); 1560 tiling_config |= ROW_TILING(3);
@@ -1631,32 +1566,36 @@ void r600_gpu_init(struct radeon_device *rdev)
1631 tiling_config |= BANK_SWAPS(1); 1566 tiling_config |= BANK_SWAPS(1);
1632 1567
1633 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000; 1568 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
1634 cc_rb_backend_disable |= 1569 tmp = R6XX_MAX_BACKENDS -
1635 BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK << rdev->config.r600.max_backends) & R6XX_MAX_BACKENDS_MASK); 1570 r600_count_pipe_bits((cc_rb_backend_disable >> 16) & R6XX_MAX_BACKENDS_MASK);
1636 1571 if (tmp < rdev->config.r600.max_backends) {
1637 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00; 1572 rdev->config.r600.max_backends = tmp;
1638 cc_gc_shader_pipe_config |= 1573 }
1639 INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK << rdev->config.r600.max_pipes) & R6XX_MAX_PIPES_MASK); 1574
1640 cc_gc_shader_pipe_config |= 1575 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0x00ffff00;
1641 INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK << rdev->config.r600.max_simds) & R6XX_MAX_SIMDS_MASK); 1576 tmp = R6XX_MAX_PIPES -
1642 1577 r600_count_pipe_bits((cc_gc_shader_pipe_config >> 8) & R6XX_MAX_PIPES_MASK);
1643 backend_map = r600_get_tile_pipe_to_backend_map(rdev->config.r600.max_tile_pipes, 1578 if (tmp < rdev->config.r600.max_pipes) {
1644 (R6XX_MAX_BACKENDS - 1579 rdev->config.r600.max_pipes = tmp;
1645 r600_count_pipe_bits((cc_rb_backend_disable & 1580 }
1646 R6XX_MAX_BACKENDS_MASK) >> 16)), 1581 tmp = R6XX_MAX_SIMDS -
1647 (cc_rb_backend_disable >> 16)); 1582 r600_count_pipe_bits((cc_gc_shader_pipe_config >> 16) & R6XX_MAX_SIMDS_MASK);
1583 if (tmp < rdev->config.r600.max_simds) {
1584 rdev->config.r600.max_simds = tmp;
1585 }
1586
1587 disabled_rb_mask = (RREG32(CC_RB_BACKEND_DISABLE) >> 16) & R6XX_MAX_BACKENDS_MASK;
1588 tmp = (tiling_config & PIPE_TILING__MASK) >> PIPE_TILING__SHIFT;
1589 tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.r600.max_backends,
1590 R6XX_MAX_BACKENDS, disabled_rb_mask);
1591 tiling_config |= tmp << 16;
1592 rdev->config.r600.backend_map = tmp;
1593
1648 rdev->config.r600.tile_config = tiling_config; 1594 rdev->config.r600.tile_config = tiling_config;
1649 rdev->config.r600.backend_map = backend_map;
1650 tiling_config |= BACKEND_MAP(backend_map);
1651 WREG32(GB_TILING_CONFIG, tiling_config); 1595 WREG32(GB_TILING_CONFIG, tiling_config);
1652 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff); 1596 WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
1653 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff); 1597 WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
1654 1598
1655 /* Setup pipes */
1656 WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
1657 WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
1658 WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
1659
1660 tmp = R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8); 1599 tmp = R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
1661 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK); 1600 WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
1662 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK); 1601 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
diff --git a/drivers/gpu/drm/radeon/r600d.h b/drivers/gpu/drm/radeon/r600d.h
index 15bd3b216243..a0dbf1fe6a40 100644
--- a/drivers/gpu/drm/radeon/r600d.h
+++ b/drivers/gpu/drm/radeon/r600d.h
@@ -219,6 +219,8 @@
219#define BACKEND_MAP(x) ((x) << 16) 219#define BACKEND_MAP(x) ((x) << 16)
220 220
221#define GB_TILING_CONFIG 0x98F0 221#define GB_TILING_CONFIG 0x98F0
222#define PIPE_TILING__SHIFT 1
223#define PIPE_TILING__MASK 0x0000000e
222 224
223#define GC_USER_SHADER_PIPE_CONFIG 0x8954 225#define GC_USER_SHADER_PIPE_CONFIG 0x8954
224#define INACTIVE_QD_PIPES(x) ((x) << 8) 226#define INACTIVE_QD_PIPES(x) ((x) << 8)
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 492654f8ee74..85dac33e3cce 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -346,6 +346,9 @@ struct radeon_bo {
346 /* Constant after initialization */ 346 /* Constant after initialization */
347 struct radeon_device *rdev; 347 struct radeon_device *rdev;
348 struct drm_gem_object gem_base; 348 struct drm_gem_object gem_base;
349
350 struct ttm_bo_kmap_obj dma_buf_vmap;
351 int vmapping_count;
349}; 352};
350#define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base) 353#define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
351 354
@@ -1845,6 +1848,11 @@ extern struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock);
1845extern void r600_hdmi_enable(struct drm_encoder *encoder); 1848extern void r600_hdmi_enable(struct drm_encoder *encoder);
1846extern void r600_hdmi_disable(struct drm_encoder *encoder); 1849extern void r600_hdmi_disable(struct drm_encoder *encoder);
1847extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode); 1850extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
1851extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
1852 u32 tiling_pipe_num,
1853 u32 max_rb_num,
1854 u32 total_max_rb_num,
1855 u32 enabled_rb_mask);
1848 1856
1849/* 1857/*
1850 * evergreen functions used by radeon_encoder.c 1858 * evergreen functions used by radeon_encoder.c
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index 0137689ed461..142f89462aa4 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -147,6 +147,7 @@ static int radeon_cs_sync_rings(struct radeon_cs_parser *p)
147 sync_to_ring, p->ring); 147 sync_to_ring, p->ring);
148} 148}
149 149
150/* XXX: note that this is called from the legacy UMS CS ioctl as well */
150int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) 151int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
151{ 152{
152 struct drm_radeon_cs *cs = data; 153 struct drm_radeon_cs *cs = data;
@@ -245,22 +246,24 @@ int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
245 } 246 }
246 } 247 }
247 248
248 if ((p->cs_flags & RADEON_CS_USE_VM) && 249 /* these are KMS only */
249 !p->rdev->vm_manager.enabled) { 250 if (p->rdev) {
250 DRM_ERROR("VM not active on asic!\n"); 251 if ((p->cs_flags & RADEON_CS_USE_VM) &&
251 return -EINVAL; 252 !p->rdev->vm_manager.enabled) {
252 } 253 DRM_ERROR("VM not active on asic!\n");
253 254 return -EINVAL;
254 /* we only support VM on SI+ */ 255 }
255 if ((p->rdev->family >= CHIP_TAHITI) &&
256 ((p->cs_flags & RADEON_CS_USE_VM) == 0)) {
257 DRM_ERROR("VM required on SI+!\n");
258 return -EINVAL;
259 }
260 256
261 if (radeon_cs_get_ring(p, ring, priority)) 257 /* we only support VM on SI+ */
262 return -EINVAL; 258 if ((p->rdev->family >= CHIP_TAHITI) &&
259 ((p->cs_flags & RADEON_CS_USE_VM) == 0)) {
260 DRM_ERROR("VM required on SI+!\n");
261 return -EINVAL;
262 }
263 263
264 if (radeon_cs_get_ring(p, ring, priority))
265 return -EINVAL;
266 }
264 267
265 /* deal with non-vm */ 268 /* deal with non-vm */
266 if ((p->chunk_ib_idx != -1) && 269 if ((p->chunk_ib_idx != -1) &&
diff --git a/drivers/gpu/drm/radeon/radeon_prime.c b/drivers/gpu/drm/radeon/radeon_prime.c
index b8f835d8ecb4..8ddab4c76710 100644
--- a/drivers/gpu/drm/radeon/radeon_prime.c
+++ b/drivers/gpu/drm/radeon/radeon_prime.c
@@ -85,6 +85,47 @@ static void radeon_gem_kunmap(struct dma_buf *dma_buf, unsigned long page_num, v
85 85
86} 86}
87 87
88static int radeon_gem_prime_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
89{
90 return -EINVAL;
91}
92
93static void *radeon_gem_prime_vmap(struct dma_buf *dma_buf)
94{
95 struct radeon_bo *bo = dma_buf->priv;
96 struct drm_device *dev = bo->rdev->ddev;
97 int ret;
98
99 mutex_lock(&dev->struct_mutex);
100 if (bo->vmapping_count) {
101 bo->vmapping_count++;
102 goto out_unlock;
103 }
104
105 ret = ttm_bo_kmap(&bo->tbo, 0, bo->tbo.num_pages,
106 &bo->dma_buf_vmap);
107 if (ret) {
108 mutex_unlock(&dev->struct_mutex);
109 return ERR_PTR(ret);
110 }
111 bo->vmapping_count = 1;
112out_unlock:
113 mutex_unlock(&dev->struct_mutex);
114 return bo->dma_buf_vmap.virtual;
115}
116
117static void radeon_gem_prime_vunmap(struct dma_buf *dma_buf, void *vaddr)
118{
119 struct radeon_bo *bo = dma_buf->priv;
120 struct drm_device *dev = bo->rdev->ddev;
121
122 mutex_lock(&dev->struct_mutex);
123 bo->vmapping_count--;
124 if (bo->vmapping_count == 0) {
125 ttm_bo_kunmap(&bo->dma_buf_vmap);
126 }
127 mutex_unlock(&dev->struct_mutex);
128}
88const static struct dma_buf_ops radeon_dmabuf_ops = { 129const static struct dma_buf_ops radeon_dmabuf_ops = {
89 .map_dma_buf = radeon_gem_map_dma_buf, 130 .map_dma_buf = radeon_gem_map_dma_buf,
90 .unmap_dma_buf = radeon_gem_unmap_dma_buf, 131 .unmap_dma_buf = radeon_gem_unmap_dma_buf,
@@ -93,6 +134,9 @@ const static struct dma_buf_ops radeon_dmabuf_ops = {
93 .kmap_atomic = radeon_gem_kmap_atomic, 134 .kmap_atomic = radeon_gem_kmap_atomic,
94 .kunmap = radeon_gem_kunmap, 135 .kunmap = radeon_gem_kunmap,
95 .kunmap_atomic = radeon_gem_kunmap_atomic, 136 .kunmap_atomic = radeon_gem_kunmap_atomic,
137 .mmap = radeon_gem_prime_mmap,
138 .vmap = radeon_gem_prime_vmap,
139 .vunmap = radeon_gem_prime_vunmap,
96}; 140};
97 141
98static int radeon_prime_create(struct drm_device *dev, 142static int radeon_prime_create(struct drm_device *dev,
diff --git a/drivers/gpu/drm/radeon/rv770.c b/drivers/gpu/drm/radeon/rv770.c
index c2f473bc13b8..04ddc365a908 100644
--- a/drivers/gpu/drm/radeon/rv770.c
+++ b/drivers/gpu/drm/radeon/rv770.c
@@ -151,6 +151,8 @@ int rv770_pcie_gart_enable(struct radeon_device *rdev)
151 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp); 151 WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp);
152 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp); 152 WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp);
153 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp); 153 WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp);
154 if (rdev->family == CHIP_RV740)
155 WREG32(MC_VM_MD_L1_TLB3_CNTL, tmp);
154 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp); 156 WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp);
155 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); 157 WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp);
156 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); 158 WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp);
@@ -363,180 +365,6 @@ void r700_cp_fini(struct radeon_device *rdev)
363/* 365/*
364 * Core functions 366 * Core functions
365 */ 367 */
366static u32 r700_get_tile_pipe_to_backend_map(struct radeon_device *rdev,
367 u32 num_tile_pipes,
368 u32 num_backends,
369 u32 backend_disable_mask)
370{
371 u32 backend_map = 0;
372 u32 enabled_backends_mask;
373 u32 enabled_backends_count;
374 u32 cur_pipe;
375 u32 swizzle_pipe[R7XX_MAX_PIPES];
376 u32 cur_backend;
377 u32 i;
378 bool force_no_swizzle;
379
380 if (num_tile_pipes > R7XX_MAX_PIPES)
381 num_tile_pipes = R7XX_MAX_PIPES;
382 if (num_tile_pipes < 1)
383 num_tile_pipes = 1;
384 if (num_backends > R7XX_MAX_BACKENDS)
385 num_backends = R7XX_MAX_BACKENDS;
386 if (num_backends < 1)
387 num_backends = 1;
388
389 enabled_backends_mask = 0;
390 enabled_backends_count = 0;
391 for (i = 0; i < R7XX_MAX_BACKENDS; ++i) {
392 if (((backend_disable_mask >> i) & 1) == 0) {
393 enabled_backends_mask |= (1 << i);
394 ++enabled_backends_count;
395 }
396 if (enabled_backends_count == num_backends)
397 break;
398 }
399
400 if (enabled_backends_count == 0) {
401 enabled_backends_mask = 1;
402 enabled_backends_count = 1;
403 }
404
405 if (enabled_backends_count != num_backends)
406 num_backends = enabled_backends_count;
407
408 switch (rdev->family) {
409 case CHIP_RV770:
410 case CHIP_RV730:
411 force_no_swizzle = false;
412 break;
413 case CHIP_RV710:
414 case CHIP_RV740:
415 default:
416 force_no_swizzle = true;
417 break;
418 }
419
420 memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R7XX_MAX_PIPES);
421 switch (num_tile_pipes) {
422 case 1:
423 swizzle_pipe[0] = 0;
424 break;
425 case 2:
426 swizzle_pipe[0] = 0;
427 swizzle_pipe[1] = 1;
428 break;
429 case 3:
430 if (force_no_swizzle) {
431 swizzle_pipe[0] = 0;
432 swizzle_pipe[1] = 1;
433 swizzle_pipe[2] = 2;
434 } else {
435 swizzle_pipe[0] = 0;
436 swizzle_pipe[1] = 2;
437 swizzle_pipe[2] = 1;
438 }
439 break;
440 case 4:
441 if (force_no_swizzle) {
442 swizzle_pipe[0] = 0;
443 swizzle_pipe[1] = 1;
444 swizzle_pipe[2] = 2;
445 swizzle_pipe[3] = 3;
446 } else {
447 swizzle_pipe[0] = 0;
448 swizzle_pipe[1] = 2;
449 swizzle_pipe[2] = 3;
450 swizzle_pipe[3] = 1;
451 }
452 break;
453 case 5:
454 if (force_no_swizzle) {
455 swizzle_pipe[0] = 0;
456 swizzle_pipe[1] = 1;
457 swizzle_pipe[2] = 2;
458 swizzle_pipe[3] = 3;
459 swizzle_pipe[4] = 4;
460 } else {
461 swizzle_pipe[0] = 0;
462 swizzle_pipe[1] = 2;
463 swizzle_pipe[2] = 4;
464 swizzle_pipe[3] = 1;
465 swizzle_pipe[4] = 3;
466 }
467 break;
468 case 6:
469 if (force_no_swizzle) {
470 swizzle_pipe[0] = 0;
471 swizzle_pipe[1] = 1;
472 swizzle_pipe[2] = 2;
473 swizzle_pipe[3] = 3;
474 swizzle_pipe[4] = 4;
475 swizzle_pipe[5] = 5;
476 } else {
477 swizzle_pipe[0] = 0;
478 swizzle_pipe[1] = 2;
479 swizzle_pipe[2] = 4;
480 swizzle_pipe[3] = 5;
481 swizzle_pipe[4] = 3;
482 swizzle_pipe[5] = 1;
483 }
484 break;
485 case 7:
486 if (force_no_swizzle) {
487 swizzle_pipe[0] = 0;
488 swizzle_pipe[1] = 1;
489 swizzle_pipe[2] = 2;
490 swizzle_pipe[3] = 3;
491 swizzle_pipe[4] = 4;
492 swizzle_pipe[5] = 5;
493 swizzle_pipe[6] = 6;
494 } else {
495 swizzle_pipe[0] = 0;
496 swizzle_pipe[1] = 2;
497 swizzle_pipe[2] = 4;
498 swizzle_pipe[3] = 6;
499 swizzle_pipe[4] = 3;
500 swizzle_pipe[5] = 1;
501 swizzle_pipe[6] = 5;
502 }
503 break;
504 case 8:
505 if (force_no_swizzle) {
506 swizzle_pipe[0] = 0;
507 swizzle_pipe[1] = 1;
508 swizzle_pipe[2] = 2;
509 swizzle_pipe[3] = 3;
510 swizzle_pipe[4] = 4;
511 swizzle_pipe[5] = 5;
512 swizzle_pipe[6] = 6;
513 swizzle_pipe[7] = 7;
514 } else {
515 swizzle_pipe[0] = 0;
516 swizzle_pipe[1] = 2;
517 swizzle_pipe[2] = 4;
518 swizzle_pipe[3] = 6;
519 swizzle_pipe[4] = 3;
520 swizzle_pipe[5] = 1;
521 swizzle_pipe[6] = 7;
522 swizzle_pipe[7] = 5;
523 }
524 break;
525 }
526
527 cur_backend = 0;
528 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
529 while (((1 << cur_backend) & enabled_backends_mask) == 0)
530 cur_backend = (cur_backend + 1) % R7XX_MAX_BACKENDS;
531
532 backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
533
534 cur_backend = (cur_backend + 1) % R7XX_MAX_BACKENDS;
535 }
536
537 return backend_map;
538}
539
540static void rv770_gpu_init(struct radeon_device *rdev) 368static void rv770_gpu_init(struct radeon_device *rdev)
541{ 369{
542 int i, j, num_qd_pipes; 370 int i, j, num_qd_pipes;
@@ -552,14 +380,17 @@ static void rv770_gpu_init(struct radeon_device *rdev)
552 u32 sq_thread_resource_mgmt; 380 u32 sq_thread_resource_mgmt;
553 u32 hdp_host_path_cntl; 381 u32 hdp_host_path_cntl;
554 u32 sq_dyn_gpr_size_simd_ab_0; 382 u32 sq_dyn_gpr_size_simd_ab_0;
555 u32 backend_map;
556 u32 gb_tiling_config = 0; 383 u32 gb_tiling_config = 0;
557 u32 cc_rb_backend_disable = 0; 384 u32 cc_rb_backend_disable = 0;
558 u32 cc_gc_shader_pipe_config = 0; 385 u32 cc_gc_shader_pipe_config = 0;
559 u32 mc_arb_ramcfg; 386 u32 mc_arb_ramcfg;
560 u32 db_debug4; 387 u32 db_debug4, tmp;
388 u32 inactive_pipes, shader_pipe_config;
389 u32 disabled_rb_mask;
390 unsigned active_number;
561 391
562 /* setup chip specs */ 392 /* setup chip specs */
393 rdev->config.rv770.tiling_group_size = 256;
563 switch (rdev->family) { 394 switch (rdev->family) {
564 case CHIP_RV770: 395 case CHIP_RV770:
565 rdev->config.rv770.max_pipes = 4; 396 rdev->config.rv770.max_pipes = 4;
@@ -670,33 +501,70 @@ static void rv770_gpu_init(struct radeon_device *rdev)
670 /* setup tiling, simd, pipe config */ 501 /* setup tiling, simd, pipe config */
671 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG); 502 mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
672 503
504 shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG);
505 inactive_pipes = (shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> INACTIVE_QD_PIPES_SHIFT;
506 for (i = 0, tmp = 1, active_number = 0; i < R7XX_MAX_PIPES; i++) {
507 if (!(inactive_pipes & tmp)) {
508 active_number++;
509 }
510 tmp <<= 1;
511 }
512 if (active_number == 1) {
513 WREG32(SPI_CONFIG_CNTL, DISABLE_INTERP_1);
514 } else {
515 WREG32(SPI_CONFIG_CNTL, 0);
516 }
517
518 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
519 tmp = R7XX_MAX_BACKENDS - r600_count_pipe_bits(cc_rb_backend_disable >> 16);
520 if (tmp < rdev->config.rv770.max_backends) {
521 rdev->config.rv770.max_backends = tmp;
522 }
523
524 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
525 tmp = R7XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config >> 8) & R7XX_MAX_PIPES_MASK);
526 if (tmp < rdev->config.rv770.max_pipes) {
527 rdev->config.rv770.max_pipes = tmp;
528 }
529 tmp = R7XX_MAX_SIMDS - r600_count_pipe_bits((cc_gc_shader_pipe_config >> 16) & R7XX_MAX_SIMDS_MASK);
530 if (tmp < rdev->config.rv770.max_simds) {
531 rdev->config.rv770.max_simds = tmp;
532 }
533
673 switch (rdev->config.rv770.max_tile_pipes) { 534 switch (rdev->config.rv770.max_tile_pipes) {
674 case 1: 535 case 1:
675 default: 536 default:
676 gb_tiling_config |= PIPE_TILING(0); 537 gb_tiling_config = PIPE_TILING(0);
677 break; 538 break;
678 case 2: 539 case 2:
679 gb_tiling_config |= PIPE_TILING(1); 540 gb_tiling_config = PIPE_TILING(1);
680 break; 541 break;
681 case 4: 542 case 4:
682 gb_tiling_config |= PIPE_TILING(2); 543 gb_tiling_config = PIPE_TILING(2);
683 break; 544 break;
684 case 8: 545 case 8:
685 gb_tiling_config |= PIPE_TILING(3); 546 gb_tiling_config = PIPE_TILING(3);
686 break; 547 break;
687 } 548 }
688 rdev->config.rv770.tiling_npipes = rdev->config.rv770.max_tile_pipes; 549 rdev->config.rv770.tiling_npipes = rdev->config.rv770.max_tile_pipes;
689 550
551 disabled_rb_mask = (RREG32(CC_RB_BACKEND_DISABLE) >> 16) & R7XX_MAX_BACKENDS_MASK;
552 tmp = (gb_tiling_config & PIPE_TILING__MASK) >> PIPE_TILING__SHIFT;
553 tmp = r6xx_remap_render_backend(rdev, tmp, rdev->config.rv770.max_backends,
554 R7XX_MAX_BACKENDS, disabled_rb_mask);
555 gb_tiling_config |= tmp << 16;
556 rdev->config.rv770.backend_map = tmp;
557
690 if (rdev->family == CHIP_RV770) 558 if (rdev->family == CHIP_RV770)
691 gb_tiling_config |= BANK_TILING(1); 559 gb_tiling_config |= BANK_TILING(1);
692 else 560 else {
693 gb_tiling_config |= BANK_TILING((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT); 561 if ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT)
562 gb_tiling_config |= BANK_TILING(1);
563 else
564 gb_tiling_config |= BANK_TILING(0);
565 }
694 rdev->config.rv770.tiling_nbanks = 4 << ((gb_tiling_config >> 4) & 0x3); 566 rdev->config.rv770.tiling_nbanks = 4 << ((gb_tiling_config >> 4) & 0x3);
695 gb_tiling_config |= GROUP_SIZE((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT); 567 gb_tiling_config |= GROUP_SIZE((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT);
696 if ((mc_arb_ramcfg & BURSTLENGTH_MASK) >> BURSTLENGTH_SHIFT)
697 rdev->config.rv770.tiling_group_size = 512;
698 else
699 rdev->config.rv770.tiling_group_size = 256;
700 if (((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT) > 3) { 568 if (((mc_arb_ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT) > 3) {
701 gb_tiling_config |= ROW_TILING(3); 569 gb_tiling_config |= ROW_TILING(3);
702 gb_tiling_config |= SAMPLE_SPLIT(3); 570 gb_tiling_config |= SAMPLE_SPLIT(3);
@@ -708,47 +576,19 @@ static void rv770_gpu_init(struct radeon_device *rdev)
708 } 576 }
709 577
710 gb_tiling_config |= BANK_SWAPS(1); 578 gb_tiling_config |= BANK_SWAPS(1);
711
712 cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
713 cc_rb_backend_disable |=
714 BACKEND_DISABLE((R7XX_MAX_BACKENDS_MASK << rdev->config.rv770.max_backends) & R7XX_MAX_BACKENDS_MASK);
715
716 cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
717 cc_gc_shader_pipe_config |=
718 INACTIVE_QD_PIPES((R7XX_MAX_PIPES_MASK << rdev->config.rv770.max_pipes) & R7XX_MAX_PIPES_MASK);
719 cc_gc_shader_pipe_config |=
720 INACTIVE_SIMDS((R7XX_MAX_SIMDS_MASK << rdev->config.rv770.max_simds) & R7XX_MAX_SIMDS_MASK);
721
722 if (rdev->family == CHIP_RV740)
723 backend_map = 0x28;
724 else
725 backend_map = r700_get_tile_pipe_to_backend_map(rdev,
726 rdev->config.rv770.max_tile_pipes,
727 (R7XX_MAX_BACKENDS -
728 r600_count_pipe_bits((cc_rb_backend_disable &
729 R7XX_MAX_BACKENDS_MASK) >> 16)),
730 (cc_rb_backend_disable >> 16));
731
732 rdev->config.rv770.tile_config = gb_tiling_config; 579 rdev->config.rv770.tile_config = gb_tiling_config;
733 rdev->config.rv770.backend_map = backend_map;
734 gb_tiling_config |= BACKEND_MAP(backend_map);
735 580
736 WREG32(GB_TILING_CONFIG, gb_tiling_config); 581 WREG32(GB_TILING_CONFIG, gb_tiling_config);
737 WREG32(DCP_TILING_CONFIG, (gb_tiling_config & 0xffff)); 582 WREG32(DCP_TILING_CONFIG, (gb_tiling_config & 0xffff));
738 WREG32(HDP_TILING_CONFIG, (gb_tiling_config & 0xffff)); 583 WREG32(HDP_TILING_CONFIG, (gb_tiling_config & 0xffff));
739 584
740 WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
741 WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
742 WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
743 WREG32(CC_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable);
744
745 WREG32(CGTS_SYS_TCC_DISABLE, 0); 585 WREG32(CGTS_SYS_TCC_DISABLE, 0);
746 WREG32(CGTS_TCC_DISABLE, 0); 586 WREG32(CGTS_TCC_DISABLE, 0);
747 WREG32(CGTS_USER_SYS_TCC_DISABLE, 0); 587 WREG32(CGTS_USER_SYS_TCC_DISABLE, 0);
748 WREG32(CGTS_USER_TCC_DISABLE, 0); 588 WREG32(CGTS_USER_TCC_DISABLE, 0);
749 589
750 num_qd_pipes = 590
751 R7XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8); 591 num_qd_pipes = R7XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
752 WREG32(VGT_OUT_DEALLOC_CNTL, (num_qd_pipes * 4) & DEALLOC_DIST_MASK); 592 WREG32(VGT_OUT_DEALLOC_CNTL, (num_qd_pipes * 4) & DEALLOC_DIST_MASK);
753 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((num_qd_pipes * 4) - 2) & VTX_REUSE_DEPTH_MASK); 593 WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((num_qd_pipes * 4) - 2) & VTX_REUSE_DEPTH_MASK);
754 594
@@ -809,8 +649,6 @@ static void rv770_gpu_init(struct radeon_device *rdev)
809 649
810 WREG32(VGT_NUM_INSTANCES, 1); 650 WREG32(VGT_NUM_INSTANCES, 1);
811 651
812 WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
813
814 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4)); 652 WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
815 653
816 WREG32(CP_PERFMON_CNTL, 0); 654 WREG32(CP_PERFMON_CNTL, 0);
diff --git a/drivers/gpu/drm/radeon/rv770d.h b/drivers/gpu/drm/radeon/rv770d.h
index 9c549f702f2f..fdc089896011 100644
--- a/drivers/gpu/drm/radeon/rv770d.h
+++ b/drivers/gpu/drm/radeon/rv770d.h
@@ -106,10 +106,13 @@
106#define BACKEND_MAP(x) ((x) << 16) 106#define BACKEND_MAP(x) ((x) << 16)
107 107
108#define GB_TILING_CONFIG 0x98F0 108#define GB_TILING_CONFIG 0x98F0
109#define PIPE_TILING__SHIFT 1
110#define PIPE_TILING__MASK 0x0000000e
109 111
110#define GC_USER_SHADER_PIPE_CONFIG 0x8954 112#define GC_USER_SHADER_PIPE_CONFIG 0x8954
111#define INACTIVE_QD_PIPES(x) ((x) << 8) 113#define INACTIVE_QD_PIPES(x) ((x) << 8)
112#define INACTIVE_QD_PIPES_MASK 0x0000FF00 114#define INACTIVE_QD_PIPES_MASK 0x0000FF00
115#define INACTIVE_QD_PIPES_SHIFT 8
113#define INACTIVE_SIMDS(x) ((x) << 16) 116#define INACTIVE_SIMDS(x) ((x) << 16)
114#define INACTIVE_SIMDS_MASK 0x00FF0000 117#define INACTIVE_SIMDS_MASK 0x00FF0000
115 118
@@ -174,6 +177,7 @@
174#define MC_VM_MD_L1_TLB0_CNTL 0x2654 177#define MC_VM_MD_L1_TLB0_CNTL 0x2654
175#define MC_VM_MD_L1_TLB1_CNTL 0x2658 178#define MC_VM_MD_L1_TLB1_CNTL 0x2658
176#define MC_VM_MD_L1_TLB2_CNTL 0x265C 179#define MC_VM_MD_L1_TLB2_CNTL 0x265C
180#define MC_VM_MD_L1_TLB3_CNTL 0x2698
177#define MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR 0x203C 181#define MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR 0x203C
178#define MC_VM_SYSTEM_APERTURE_HIGH_ADDR 0x2038 182#define MC_VM_SYSTEM_APERTURE_HIGH_ADDR 0x2038
179#define MC_VM_SYSTEM_APERTURE_LOW_ADDR 0x2034 183#define MC_VM_SYSTEM_APERTURE_LOW_ADDR 0x2034
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 36792bd4da77..b67cfcaa661f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1834,6 +1834,7 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
1834 spin_unlock(&glob->lru_lock); 1834 spin_unlock(&glob->lru_lock);
1835 (void) ttm_bo_cleanup_refs(bo, false, false, false); 1835 (void) ttm_bo_cleanup_refs(bo, false, false, false);
1836 kref_put(&bo->list_kref, ttm_bo_release_list); 1836 kref_put(&bo->list_kref, ttm_bo_release_list);
1837 spin_lock(&glob->lru_lock);
1837 continue; 1838 continue;
1838 } 1839 }
1839 1840
diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
index a029ee39b0c5..ce9a61179925 100644
--- a/drivers/gpu/drm/udl/udl_fb.c
+++ b/drivers/gpu/drm/udl/udl_fb.c
@@ -156,8 +156,17 @@ int udl_handle_damage(struct udl_framebuffer *fb, int x, int y,
156 if (!fb->active_16) 156 if (!fb->active_16)
157 return 0; 157 return 0;
158 158
159 if (!fb->obj->vmapping) 159 if (!fb->obj->vmapping) {
160 udl_gem_vmap(fb->obj); 160 ret = udl_gem_vmap(fb->obj);
161 if (ret == -ENOMEM) {
162 DRM_ERROR("failed to vmap fb\n");
163 return 0;
164 }
165 if (!fb->obj->vmapping) {
166 DRM_ERROR("failed to vmapping\n");
167 return 0;
168 }
169 }
161 170
162 start_cycles = get_cycles(); 171 start_cycles = get_cycles();
163 172
diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c
index 97acc9c6c95b..7bd65bdd15a8 100644
--- a/drivers/gpu/drm/udl/udl_gem.c
+++ b/drivers/gpu/drm/udl/udl_gem.c
@@ -180,6 +180,18 @@ int udl_gem_vmap(struct udl_gem_object *obj)
180 int page_count = obj->base.size / PAGE_SIZE; 180 int page_count = obj->base.size / PAGE_SIZE;
181 int ret; 181 int ret;
182 182
183 if (obj->base.import_attach) {
184 ret = dma_buf_begin_cpu_access(obj->base.import_attach->dmabuf,
185 0, obj->base.size, DMA_BIDIRECTIONAL);
186 if (ret)
187 return -EINVAL;
188
189 obj->vmapping = dma_buf_vmap(obj->base.import_attach->dmabuf);
190 if (!obj->vmapping)
191 return -ENOMEM;
192 return 0;
193 }
194
183 ret = udl_gem_get_pages(obj, GFP_KERNEL); 195 ret = udl_gem_get_pages(obj, GFP_KERNEL);
184 if (ret) 196 if (ret)
185 return ret; 197 return ret;
@@ -192,6 +204,13 @@ int udl_gem_vmap(struct udl_gem_object *obj)
192 204
193void udl_gem_vunmap(struct udl_gem_object *obj) 205void udl_gem_vunmap(struct udl_gem_object *obj)
194{ 206{
207 if (obj->base.import_attach) {
208 dma_buf_vunmap(obj->base.import_attach->dmabuf, obj->vmapping);
209 dma_buf_end_cpu_access(obj->base.import_attach->dmabuf, 0,
210 obj->base.size, DMA_BIDIRECTIONAL);
211 return;
212 }
213
195 if (obj->vmapping) 214 if (obj->vmapping)
196 vunmap(obj->vmapping); 215 vunmap(obj->vmapping);
197 216
@@ -202,12 +221,12 @@ void udl_gem_free_object(struct drm_gem_object *gem_obj)
202{ 221{
203 struct udl_gem_object *obj = to_udl_bo(gem_obj); 222 struct udl_gem_object *obj = to_udl_bo(gem_obj);
204 223
205 if (gem_obj->import_attach)
206 drm_prime_gem_destroy(gem_obj, obj->sg);
207
208 if (obj->vmapping) 224 if (obj->vmapping)
209 udl_gem_vunmap(obj); 225 udl_gem_vunmap(obj);
210 226
227 if (gem_obj->import_attach)
228 drm_prime_gem_destroy(gem_obj, obj->sg);
229
211 if (obj->pages) 230 if (obj->pages)
212 udl_gem_put_pages(obj); 231 udl_gem_put_pages(obj);
213 232
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmr.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmr.c
index 51c9ba5cd2fb..21ee78226560 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmr.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmr.c
@@ -66,7 +66,7 @@ static int vmw_gmr2_bind(struct vmw_private *dev_priv,
66 cmd += sizeof(remap_cmd) / sizeof(uint32); 66 cmd += sizeof(remap_cmd) / sizeof(uint32);
67 67
68 for (i = 0; i < num_pages; ++i) { 68 for (i = 0; i < num_pages; ++i) {
69 if (VMW_PPN_SIZE > 4) 69 if (VMW_PPN_SIZE <= 4)
70 *cmd = page_to_pfn(*pages++); 70 *cmd = page_to_pfn(*pages++);
71 else 71 else
72 *((uint64_t *)cmd) = page_to_pfn(*pages++); 72 *((uint64_t *)cmd) = page_to_pfn(*pages++);
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 444143e5f28c..d99db5623acf 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -1653,7 +1653,6 @@ mpt_mapresources(MPT_ADAPTER *ioc)
1653 unsigned long port; 1653 unsigned long port;
1654 u32 msize; 1654 u32 msize;
1655 u32 psize; 1655 u32 psize;
1656 u8 revision;
1657 int r = -ENODEV; 1656 int r = -ENODEV;
1658 struct pci_dev *pdev; 1657 struct pci_dev *pdev;
1659 1658
@@ -1670,8 +1669,6 @@ mpt_mapresources(MPT_ADAPTER *ioc)
1670 return r; 1669 return r;
1671 } 1670 }
1672 1671
1673 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
1674
1675 if (sizeof(dma_addr_t) > 4) { 1672 if (sizeof(dma_addr_t) > 4) {
1676 const uint64_t required_mask = dma_get_required_mask 1673 const uint64_t required_mask = dma_get_required_mask
1677 (&pdev->dev); 1674 (&pdev->dev);
@@ -1779,7 +1776,6 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1779 MPT_ADAPTER *ioc; 1776 MPT_ADAPTER *ioc;
1780 u8 cb_idx; 1777 u8 cb_idx;
1781 int r = -ENODEV; 1778 int r = -ENODEV;
1782 u8 revision;
1783 u8 pcixcmd; 1779 u8 pcixcmd;
1784 static int mpt_ids = 0; 1780 static int mpt_ids = 0;
1785#ifdef CONFIG_PROC_FS 1781#ifdef CONFIG_PROC_FS
@@ -1887,8 +1883,8 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1887 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "facts @ %p, pfacts[0] @ %p\n", 1883 dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "facts @ %p, pfacts[0] @ %p\n",
1888 ioc->name, &ioc->facts, &ioc->pfacts[0])); 1884 ioc->name, &ioc->facts, &ioc->pfacts[0]));
1889 1885
1890 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision); 1886 mpt_get_product_name(pdev->vendor, pdev->device, pdev->revision,
1891 mpt_get_product_name(pdev->vendor, pdev->device, revision, ioc->prod_name); 1887 ioc->prod_name);
1892 1888
1893 switch (pdev->device) 1889 switch (pdev->device)
1894 { 1890 {
@@ -1903,7 +1899,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1903 break; 1899 break;
1904 1900
1905 case MPI_MANUFACTPAGE_DEVICEID_FC929X: 1901 case MPI_MANUFACTPAGE_DEVICEID_FC929X:
1906 if (revision < XL_929) { 1902 if (pdev->revision < XL_929) {
1907 /* 929X Chip Fix. Set Split transactions level 1903 /* 929X Chip Fix. Set Split transactions level
1908 * for PCIX. Set MOST bits to zero. 1904 * for PCIX. Set MOST bits to zero.
1909 */ 1905 */
@@ -1934,7 +1930,7 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1934 /* 1030 Chip Fix. Disable Split transactions 1930 /* 1030 Chip Fix. Disable Split transactions
1935 * for PCIX. Set MOST bits to zero if Rev < C0( = 8). 1931 * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
1936 */ 1932 */
1937 if (revision < C0_1030) { 1933 if (pdev->revision < C0_1030) {
1938 pci_read_config_byte(pdev, 0x6a, &pcixcmd); 1934 pci_read_config_byte(pdev, 0x6a, &pcixcmd);
1939 pcixcmd &= 0x8F; 1935 pcixcmd &= 0x8F;
1940 pci_write_config_byte(pdev, 0x6a, pcixcmd); 1936 pci_write_config_byte(pdev, 0x6a, pcixcmd);
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index 6e6e16aab9da..b383b6961e59 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -1250,7 +1250,6 @@ mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
1250 int iocnum; 1250 int iocnum;
1251 unsigned int port; 1251 unsigned int port;
1252 int cim_rev; 1252 int cim_rev;
1253 u8 revision;
1254 struct scsi_device *sdev; 1253 struct scsi_device *sdev;
1255 VirtDevice *vdevice; 1254 VirtDevice *vdevice;
1256 1255
@@ -1324,8 +1323,7 @@ mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
1324 pdev = (struct pci_dev *) ioc->pcidev; 1323 pdev = (struct pci_dev *) ioc->pcidev;
1325 1324
1326 karg->pciId = pdev->device; 1325 karg->pciId = pdev->device;
1327 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision); 1326 karg->hwRev = pdev->revision;
1328 karg->hwRev = revision;
1329 karg->subSystemDevice = pdev->subsystem_device; 1327 karg->subSystemDevice = pdev->subsystem_device;
1330 karg->subSystemVendor = pdev->subsystem_vendor; 1328 karg->subSystemVendor = pdev->subsystem_vendor;
1331 1329
diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c
index 671c8bc14bbc..50e83dc5dc49 100644
--- a/drivers/mfd/db8500-prcmu.c
+++ b/drivers/mfd/db8500-prcmu.c
@@ -2735,6 +2735,7 @@ static struct regulator_consumer_supply db8500_vape_consumers[] = {
2735 REGULATOR_SUPPLY("vcore", "uart2"), 2735 REGULATOR_SUPPLY("vcore", "uart2"),
2736 REGULATOR_SUPPLY("v-ape", "nmk-ske-keypad.0"), 2736 REGULATOR_SUPPLY("v-ape", "nmk-ske-keypad.0"),
2737 REGULATOR_SUPPLY("v-hsi", "ste_hsi.0"), 2737 REGULATOR_SUPPLY("v-hsi", "ste_hsi.0"),
2738 REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
2738}; 2739};
2739 2740
2740static struct regulator_consumer_supply db8500_vsmps2_consumers[] = { 2741static struct regulator_consumer_supply db8500_vsmps2_consumers[] = {
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index 5760c1a4b3f6..27143e042af5 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -128,7 +128,7 @@ config MTD_AFS_PARTS
128 128
129config MTD_OF_PARTS 129config MTD_OF_PARTS
130 tristate "OpenFirmware partitioning information support" 130 tristate "OpenFirmware partitioning information support"
131 default Y 131 default y
132 depends on OF 132 depends on OF
133 help 133 help
134 This provides a partition parsing function which derives 134 This provides a partition parsing function which derives
diff --git a/drivers/mtd/bcm63xxpart.c b/drivers/mtd/bcm63xxpart.c
index 608321ee056e..63d2a64331f7 100644
--- a/drivers/mtd/bcm63xxpart.c
+++ b/drivers/mtd/bcm63xxpart.c
@@ -4,7 +4,7 @@
4 * Copyright © 2006-2008 Florian Fainelli <florian@openwrt.org> 4 * Copyright © 2006-2008 Florian Fainelli <florian@openwrt.org>
5 * Mike Albon <malbon@openwrt.org> 5 * Mike Albon <malbon@openwrt.org>
6 * Copyright © 2009-2010 Daniel Dickinson <openwrt@cshore.neomailbox.net> 6 * Copyright © 2009-2010 Daniel Dickinson <openwrt@cshore.neomailbox.net>
7 * Copyright © 2011 Jonas Gorski <jonas.gorski@gmail.com> 7 * Copyright © 2011-2012 Jonas Gorski <jonas.gorski@gmail.com>
8 * 8 *
9 * 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
10 * 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
@@ -82,6 +82,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
82 int namelen = 0; 82 int namelen = 0;
83 int i; 83 int i;
84 u32 computed_crc; 84 u32 computed_crc;
85 bool rootfs_first = false;
85 86
86 if (bcm63xx_detect_cfe(master)) 87 if (bcm63xx_detect_cfe(master))
87 return -EINVAL; 88 return -EINVAL;
@@ -109,6 +110,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
109 char *boardid = &(buf->board_id[0]); 110 char *boardid = &(buf->board_id[0]);
110 char *tagversion = &(buf->tag_version[0]); 111 char *tagversion = &(buf->tag_version[0]);
111 112
113 sscanf(buf->flash_image_start, "%u", &rootfsaddr);
112 sscanf(buf->kernel_address, "%u", &kerneladdr); 114 sscanf(buf->kernel_address, "%u", &kerneladdr);
113 sscanf(buf->kernel_length, "%u", &kernellen); 115 sscanf(buf->kernel_length, "%u", &kernellen);
114 sscanf(buf->total_length, "%u", &totallen); 116 sscanf(buf->total_length, "%u", &totallen);
@@ -117,10 +119,19 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
117 tagversion, boardid); 119 tagversion, boardid);
118 120
119 kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE; 121 kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE;
120 rootfsaddr = kerneladdr + kernellen; 122 rootfsaddr = rootfsaddr - BCM63XX_EXTENDED_SIZE;
121 spareaddr = roundup(totallen, master->erasesize) + cfelen; 123 spareaddr = roundup(totallen, master->erasesize) + cfelen;
122 sparelen = master->size - spareaddr - nvramlen; 124 sparelen = master->size - spareaddr - nvramlen;
123 rootfslen = spareaddr - rootfsaddr; 125
126 if (rootfsaddr < kerneladdr) {
127 /* default Broadcom layout */
128 rootfslen = kerneladdr - rootfsaddr;
129 rootfs_first = true;
130 } else {
131 /* OpenWrt layout */
132 rootfsaddr = kerneladdr + kernellen;
133 rootfslen = spareaddr - rootfsaddr;
134 }
124 } else { 135 } else {
125 pr_warn("CFE boot tag CRC invalid (expected %08x, actual %08x)\n", 136 pr_warn("CFE boot tag CRC invalid (expected %08x, actual %08x)\n",
126 buf->header_crc, computed_crc); 137 buf->header_crc, computed_crc);
@@ -156,18 +167,26 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
156 curpart++; 167 curpart++;
157 168
158 if (kernellen > 0) { 169 if (kernellen > 0) {
159 parts[curpart].name = "kernel"; 170 int kernelpart = curpart;
160 parts[curpart].offset = kerneladdr; 171
161 parts[curpart].size = kernellen; 172 if (rootfslen > 0 && rootfs_first)
173 kernelpart++;
174 parts[kernelpart].name = "kernel";
175 parts[kernelpart].offset = kerneladdr;
176 parts[kernelpart].size = kernellen;
162 curpart++; 177 curpart++;
163 } 178 }
164 179
165 if (rootfslen > 0) { 180 if (rootfslen > 0) {
166 parts[curpart].name = "rootfs"; 181 int rootfspart = curpart;
167 parts[curpart].offset = rootfsaddr; 182
168 parts[curpart].size = rootfslen; 183 if (kernellen > 0 && rootfs_first)
169 if (sparelen > 0) 184 rootfspart--;
170 parts[curpart].size += sparelen; 185 parts[rootfspart].name = "rootfs";
186 parts[rootfspart].offset = rootfsaddr;
187 parts[rootfspart].size = rootfslen;
188 if (sparelen > 0 && !rootfs_first)
189 parts[rootfspart].size += sparelen;
171 curpart++; 190 curpart++;
172 } 191 }
173 192
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index d02592e6a0f0..22d0493a026f 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -317,7 +317,7 @@ static void fixup_s29gl064n_sectors(struct mtd_info *mtd)
317 317
318 if ((cfi->cfiq->EraseRegionInfo[0] & 0xffff) == 0x003f) { 318 if ((cfi->cfiq->EraseRegionInfo[0] & 0xffff) == 0x003f) {
319 cfi->cfiq->EraseRegionInfo[0] |= 0x0040; 319 cfi->cfiq->EraseRegionInfo[0] |= 0x0040;
320 pr_warning("%s: Bad S29GL064N CFI data, adjust from 64 to 128 sectors\n", mtd->name); 320 pr_warning("%s: Bad S29GL064N CFI data; adjust from 64 to 128 sectors\n", mtd->name);
321 } 321 }
322} 322}
323 323
@@ -328,10 +328,23 @@ static void fixup_s29gl032n_sectors(struct mtd_info *mtd)
328 328
329 if ((cfi->cfiq->EraseRegionInfo[1] & 0xffff) == 0x007e) { 329 if ((cfi->cfiq->EraseRegionInfo[1] & 0xffff) == 0x007e) {
330 cfi->cfiq->EraseRegionInfo[1] &= ~0x0040; 330 cfi->cfiq->EraseRegionInfo[1] &= ~0x0040;
331 pr_warning("%s: Bad S29GL032N CFI data, adjust from 127 to 63 sectors\n", mtd->name); 331 pr_warning("%s: Bad S29GL032N CFI data; adjust from 127 to 63 sectors\n", mtd->name);
332 } 332 }
333} 333}
334 334
335static void fixup_s29ns512p_sectors(struct mtd_info *mtd)
336{
337 struct map_info *map = mtd->priv;
338 struct cfi_private *cfi = map->fldrv_priv;
339
340 /*
341 * S29NS512P flash uses more than 8bits to report number of sectors,
342 * which is not permitted by CFI.
343 */
344 cfi->cfiq->EraseRegionInfo[0] = 0x020001ff;
345 pr_warning("%s: Bad S29NS512P CFI data; adjust to 512 sectors\n", mtd->name);
346}
347
335/* Used to fix CFI-Tables of chips without Extended Query Tables */ 348/* Used to fix CFI-Tables of chips without Extended Query Tables */
336static struct cfi_fixup cfi_nopri_fixup_table[] = { 349static struct cfi_fixup cfi_nopri_fixup_table[] = {
337 { CFI_MFR_SST, 0x234a, fixup_sst39vf }, /* SST39VF1602 */ 350 { CFI_MFR_SST, 0x234a, fixup_sst39vf }, /* SST39VF1602 */
@@ -362,6 +375,7 @@ static struct cfi_fixup cfi_fixup_table[] = {
362 { CFI_MFR_AMD, 0x1301, fixup_s29gl064n_sectors }, 375 { CFI_MFR_AMD, 0x1301, fixup_s29gl064n_sectors },
363 { CFI_MFR_AMD, 0x1a00, fixup_s29gl032n_sectors }, 376 { CFI_MFR_AMD, 0x1a00, fixup_s29gl032n_sectors },
364 { CFI_MFR_AMD, 0x1a01, fixup_s29gl032n_sectors }, 377 { CFI_MFR_AMD, 0x1a01, fixup_s29gl032n_sectors },
378 { CFI_MFR_AMD, 0x3f00, fixup_s29ns512p_sectors },
365 { CFI_MFR_SST, 0x536a, fixup_sst38vf640x_sectorsize }, /* SST38VF6402 */ 379 { CFI_MFR_SST, 0x536a, fixup_sst38vf640x_sectorsize }, /* SST38VF6402 */
366 { CFI_MFR_SST, 0x536b, fixup_sst38vf640x_sectorsize }, /* SST38VF6401 */ 380 { CFI_MFR_SST, 0x536b, fixup_sst38vf640x_sectorsize }, /* SST38VF6401 */
367 { CFI_MFR_SST, 0x536c, fixup_sst38vf640x_sectorsize }, /* SST38VF6404 */ 381 { CFI_MFR_SST, 0x536c, fixup_sst38vf640x_sectorsize }, /* SST38VF6404 */
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index ddf9ec6d9168..4558e0f4d07f 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -70,7 +70,7 @@ struct cmdline_mtd_partition {
70/* mtdpart_setup() parses into here */ 70/* mtdpart_setup() parses into here */
71static struct cmdline_mtd_partition *partitions; 71static struct cmdline_mtd_partition *partitions;
72 72
73/* the command line passed to mtdpart_setupd() */ 73/* the command line passed to mtdpart_setup() */
74static char *cmdline; 74static char *cmdline;
75static int cmdline_parsed = 0; 75static int cmdline_parsed = 0;
76 76
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index a4a80b742e65..681e2ee0f2d6 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -52,8 +52,6 @@ static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len)
52 52
53 while (pages) { 53 while (pages) {
54 page = page_read(mapping, index); 54 page = page_read(mapping, index);
55 if (!page)
56 return -ENOMEM;
57 if (IS_ERR(page)) 55 if (IS_ERR(page))
58 return PTR_ERR(page); 56 return PTR_ERR(page);
59 57
@@ -112,8 +110,6 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
112 len = len - cpylen; 110 len = len - cpylen;
113 111
114 page = page_read(dev->blkdev->bd_inode->i_mapping, index); 112 page = page_read(dev->blkdev->bd_inode->i_mapping, index);
115 if (!page)
116 return -ENOMEM;
117 if (IS_ERR(page)) 113 if (IS_ERR(page))
118 return PTR_ERR(page); 114 return PTR_ERR(page);
119 115
@@ -148,8 +144,6 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf,
148 len = len - cpylen; 144 len = len - cpylen;
149 145
150 page = page_read(mapping, index); 146 page = page_read(mapping, index);
151 if (!page)
152 return -ENOMEM;
153 if (IS_ERR(page)) 147 if (IS_ERR(page))
154 return PTR_ERR(page); 148 return PTR_ERR(page);
155 149
@@ -271,7 +265,6 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
271 dev->mtd.flags = MTD_CAP_RAM; 265 dev->mtd.flags = MTD_CAP_RAM;
272 dev->mtd._erase = block2mtd_erase; 266 dev->mtd._erase = block2mtd_erase;
273 dev->mtd._write = block2mtd_write; 267 dev->mtd._write = block2mtd_write;
274 dev->mtd._writev = mtd_writev;
275 dev->mtd._sync = block2mtd_sync; 268 dev->mtd._sync = block2mtd_sync;
276 dev->mtd._read = block2mtd_read; 269 dev->mtd._read = block2mtd_read;
277 dev->mtd.priv = dev; 270 dev->mtd.priv = dev;
diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index 50aa90aa7a7f..f70854d728fe 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -227,7 +227,7 @@ static void doc_read_data_area(struct docg3 *docg3, void *buf, int len,
227 u8 data8, *dst8; 227 u8 data8, *dst8;
228 228
229 doc_dbg("doc_read_data_area(buf=%p, len=%d)\n", buf, len); 229 doc_dbg("doc_read_data_area(buf=%p, len=%d)\n", buf, len);
230 cdr = len & 0x3; 230 cdr = len & 0x1;
231 len4 = len - cdr; 231 len4 = len - cdr;
232 232
233 if (first) 233 if (first)
@@ -732,12 +732,24 @@ err:
732 * @len: the number of bytes to be read (must be a multiple of 4) 732 * @len: the number of bytes to be read (must be a multiple of 4)
733 * @buf: the buffer to be filled in (or NULL is forget bytes) 733 * @buf: the buffer to be filled in (or NULL is forget bytes)
734 * @first: 1 if first time read, DOC_READADDRESS should be set 734 * @first: 1 if first time read, DOC_READADDRESS should be set
735 * @last_odd: 1 if last read ended up on an odd byte
736 *
737 * Reads bytes from a prepared page. There is a trickery here : if the last read
738 * ended up on an odd offset in the 1024 bytes double page, ie. between the 2
739 * planes, the first byte must be read apart. If a word (16bit) read was used,
740 * the read would return the byte of plane 2 as low *and* high endian, which
741 * will mess the read.
735 * 742 *
736 */ 743 */
737static int doc_read_page_getbytes(struct docg3 *docg3, int len, u_char *buf, 744static int doc_read_page_getbytes(struct docg3 *docg3, int len, u_char *buf,
738 int first) 745 int first, int last_odd)
739{ 746{
740 doc_read_data_area(docg3, buf, len, first); 747 if (last_odd && len > 0) {
748 doc_read_data_area(docg3, buf, 1, first);
749 doc_read_data_area(docg3, buf ? buf + 1 : buf, len - 1, 0);
750 } else {
751 doc_read_data_area(docg3, buf, len, first);
752 }
741 doc_delay(docg3, 2); 753 doc_delay(docg3, 2);
742 return len; 754 return len;
743} 755}
@@ -850,6 +862,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
850 u8 *buf = ops->datbuf; 862 u8 *buf = ops->datbuf;
851 size_t len, ooblen, nbdata, nboob; 863 size_t len, ooblen, nbdata, nboob;
852 u8 hwecc[DOC_ECC_BCH_SIZE], eccconf1; 864 u8 hwecc[DOC_ECC_BCH_SIZE], eccconf1;
865 int max_bitflips = 0;
853 866
854 if (buf) 867 if (buf)
855 len = ops->len; 868 len = ops->len;
@@ -876,7 +889,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
876 ret = 0; 889 ret = 0;
877 skip = from % DOC_LAYOUT_PAGE_SIZE; 890 skip = from % DOC_LAYOUT_PAGE_SIZE;
878 mutex_lock(&docg3->cascade->lock); 891 mutex_lock(&docg3->cascade->lock);
879 while (!ret && (len > 0 || ooblen > 0)) { 892 while (ret >= 0 && (len > 0 || ooblen > 0)) {
880 calc_block_sector(from - skip, &block0, &block1, &page, &ofs, 893 calc_block_sector(from - skip, &block0, &block1, &page, &ofs,
881 docg3->reliable); 894 docg3->reliable);
882 nbdata = min_t(size_t, len, DOC_LAYOUT_PAGE_SIZE - skip); 895 nbdata = min_t(size_t, len, DOC_LAYOUT_PAGE_SIZE - skip);
@@ -887,20 +900,20 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
887 ret = doc_read_page_ecc_init(docg3, DOC_ECC_BCH_TOTAL_BYTES); 900 ret = doc_read_page_ecc_init(docg3, DOC_ECC_BCH_TOTAL_BYTES);
888 if (ret < 0) 901 if (ret < 0)
889 goto err_in_read; 902 goto err_in_read;
890 ret = doc_read_page_getbytes(docg3, skip, NULL, 1); 903 ret = doc_read_page_getbytes(docg3, skip, NULL, 1, 0);
891 if (ret < skip) 904 if (ret < skip)
892 goto err_in_read; 905 goto err_in_read;
893 ret = doc_read_page_getbytes(docg3, nbdata, buf, 0); 906 ret = doc_read_page_getbytes(docg3, nbdata, buf, 0, skip % 2);
894 if (ret < nbdata) 907 if (ret < nbdata)
895 goto err_in_read; 908 goto err_in_read;
896 doc_read_page_getbytes(docg3, 909 doc_read_page_getbytes(docg3,
897 DOC_LAYOUT_PAGE_SIZE - nbdata - skip, 910 DOC_LAYOUT_PAGE_SIZE - nbdata - skip,
898 NULL, 0); 911 NULL, 0, (skip + nbdata) % 2);
899 ret = doc_read_page_getbytes(docg3, nboob, oobbuf, 0); 912 ret = doc_read_page_getbytes(docg3, nboob, oobbuf, 0, 0);
900 if (ret < nboob) 913 if (ret < nboob)
901 goto err_in_read; 914 goto err_in_read;
902 doc_read_page_getbytes(docg3, DOC_LAYOUT_OOB_SIZE - nboob, 915 doc_read_page_getbytes(docg3, DOC_LAYOUT_OOB_SIZE - nboob,
903 NULL, 0); 916 NULL, 0, nboob % 2);
904 917
905 doc_get_bch_hw_ecc(docg3, hwecc); 918 doc_get_bch_hw_ecc(docg3, hwecc);
906 eccconf1 = doc_register_readb(docg3, DOC_ECCCONF1); 919 eccconf1 = doc_register_readb(docg3, DOC_ECCCONF1);
@@ -936,7 +949,8 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from,
936 } 949 }
937 if (ret > 0) { 950 if (ret > 0) {
938 mtd->ecc_stats.corrected += ret; 951 mtd->ecc_stats.corrected += ret;
939 ret = -EUCLEAN; 952 max_bitflips = max(max_bitflips, ret);
953 ret = max_bitflips;
940 } 954 }
941 } 955 }
942 956
@@ -1004,7 +1018,7 @@ static int doc_reload_bbt(struct docg3 *docg3)
1004 DOC_LAYOUT_PAGE_SIZE); 1018 DOC_LAYOUT_PAGE_SIZE);
1005 if (!ret) 1019 if (!ret)
1006 doc_read_page_getbytes(docg3, DOC_LAYOUT_PAGE_SIZE, 1020 doc_read_page_getbytes(docg3, DOC_LAYOUT_PAGE_SIZE,
1007 buf, 1); 1021 buf, 1, 0);
1008 buf += DOC_LAYOUT_PAGE_SIZE; 1022 buf += DOC_LAYOUT_PAGE_SIZE;
1009 } 1023 }
1010 doc_read_page_finish(docg3); 1024 doc_read_page_finish(docg3);
@@ -1064,10 +1078,10 @@ static int doc_get_erase_count(struct docg3 *docg3, loff_t from)
1064 ret = doc_reset_seq(docg3); 1078 ret = doc_reset_seq(docg3);
1065 if (!ret) 1079 if (!ret)
1066 ret = doc_read_page_prepare(docg3, block0, block1, page, 1080 ret = doc_read_page_prepare(docg3, block0, block1, page,
1067 ofs + DOC_LAYOUT_WEAR_OFFSET); 1081 ofs + DOC_LAYOUT_WEAR_OFFSET, 0);
1068 if (!ret) 1082 if (!ret)
1069 ret = doc_read_page_getbytes(docg3, DOC_LAYOUT_WEAR_SIZE, 1083 ret = doc_read_page_getbytes(docg3, DOC_LAYOUT_WEAR_SIZE,
1070 buf, 1); 1084 buf, 1, 0);
1071 doc_read_page_finish(docg3); 1085 doc_read_page_finish(docg3);
1072 1086
1073 if (ret || (buf[0] != DOC_ERASE_MARK) || (buf[2] != DOC_ERASE_MARK)) 1087 if (ret || (buf[0] != DOC_ERASE_MARK) || (buf[2] != DOC_ERASE_MARK))
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 1924d247c1cb..5d0d68c3fe27 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -639,12 +639,16 @@ static const struct spi_device_id m25p_ids[] = {
639 { "en25q32b", INFO(0x1c3016, 0, 64 * 1024, 64, 0) }, 639 { "en25q32b", INFO(0x1c3016, 0, 64 * 1024, 64, 0) },
640 { "en25p64", INFO(0x1c2017, 0, 64 * 1024, 128, 0) }, 640 { "en25p64", INFO(0x1c2017, 0, 64 * 1024, 128, 0) },
641 641
642 /* Everspin */
643 { "mr25h256", CAT25_INFO( 32 * 1024, 1, 256, 2) },
644
642 /* Intel/Numonyx -- xxxs33b */ 645 /* Intel/Numonyx -- xxxs33b */
643 { "160s33b", INFO(0x898911, 0, 64 * 1024, 32, 0) }, 646 { "160s33b", INFO(0x898911, 0, 64 * 1024, 32, 0) },
644 { "320s33b", INFO(0x898912, 0, 64 * 1024, 64, 0) }, 647 { "320s33b", INFO(0x898912, 0, 64 * 1024, 64, 0) },
645 { "640s33b", INFO(0x898913, 0, 64 * 1024, 128, 0) }, 648 { "640s33b", INFO(0x898913, 0, 64 * 1024, 128, 0) },
646 649
647 /* Macronix */ 650 /* Macronix */
651 { "mx25l2005a", INFO(0xc22012, 0, 64 * 1024, 4, SECT_4K) },
648 { "mx25l4005a", INFO(0xc22013, 0, 64 * 1024, 8, SECT_4K) }, 652 { "mx25l4005a", INFO(0xc22013, 0, 64 * 1024, 8, SECT_4K) },
649 { "mx25l8005", INFO(0xc22014, 0, 64 * 1024, 16, 0) }, 653 { "mx25l8005", INFO(0xc22014, 0, 64 * 1024, 16, 0) },
650 { "mx25l1606e", INFO(0xc22015, 0, 64 * 1024, 32, SECT_4K) }, 654 { "mx25l1606e", INFO(0xc22015, 0, 64 * 1024, 32, SECT_4K) },
@@ -728,6 +732,7 @@ static const struct spi_device_id m25p_ids[] = {
728 { "w25q32", INFO(0xef4016, 0, 64 * 1024, 64, SECT_4K) }, 732 { "w25q32", INFO(0xef4016, 0, 64 * 1024, 64, SECT_4K) },
729 { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) }, 733 { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) },
730 { "w25q64", INFO(0xef4017, 0, 64 * 1024, 128, SECT_4K) }, 734 { "w25q64", INFO(0xef4017, 0, 64 * 1024, 128, SECT_4K) },
735 { "w25q80", INFO(0xef5014, 0, 64 * 1024, 16, SECT_4K) },
731 736
732 /* Catalyst / On Semiconductor -- non-JEDEC */ 737 /* Catalyst / On Semiconductor -- non-JEDEC */
733 { "cat25c11", CAT25_INFO( 16, 8, 16, 1) }, 738 { "cat25c11", CAT25_INFO( 16, 8, 16, 1) },
diff --git a/drivers/mtd/devices/spear_smi.c b/drivers/mtd/devices/spear_smi.c
index 797d43cd3550..67960362681e 100644
--- a/drivers/mtd/devices/spear_smi.c
+++ b/drivers/mtd/devices/spear_smi.c
@@ -990,9 +990,9 @@ static int __devinit spear_smi_probe(struct platform_device *pdev)
990 goto err_clk; 990 goto err_clk;
991 } 991 }
992 992
993 ret = clk_enable(dev->clk); 993 ret = clk_prepare_enable(dev->clk);
994 if (ret) 994 if (ret)
995 goto err_clk_enable; 995 goto err_clk_prepare_enable;
996 996
997 ret = request_irq(irq, spear_smi_int_handler, 0, pdev->name, dev); 997 ret = request_irq(irq, spear_smi_int_handler, 0, pdev->name, dev);
998 if (ret) { 998 if (ret) {
@@ -1020,8 +1020,8 @@ err_bank_setup:
1020 free_irq(irq, dev); 1020 free_irq(irq, dev);
1021 platform_set_drvdata(pdev, NULL); 1021 platform_set_drvdata(pdev, NULL);
1022err_irq: 1022err_irq:
1023 clk_disable(dev->clk); 1023 clk_disable_unprepare(dev->clk);
1024err_clk_enable: 1024err_clk_prepare_enable:
1025 clk_put(dev->clk); 1025 clk_put(dev->clk);
1026err_clk: 1026err_clk:
1027 iounmap(dev->io_base); 1027 iounmap(dev->io_base);
@@ -1074,7 +1074,7 @@ static int __devexit spear_smi_remove(struct platform_device *pdev)
1074 irq = platform_get_irq(pdev, 0); 1074 irq = platform_get_irq(pdev, 0);
1075 free_irq(irq, dev); 1075 free_irq(irq, dev);
1076 1076
1077 clk_disable(dev->clk); 1077 clk_disable_unprepare(dev->clk);
1078 clk_put(dev->clk); 1078 clk_put(dev->clk);
1079 iounmap(dev->io_base); 1079 iounmap(dev->io_base);
1080 kfree(dev); 1080 kfree(dev);
@@ -1091,7 +1091,7 @@ int spear_smi_suspend(struct platform_device *pdev, pm_message_t state)
1091 struct spear_smi *dev = platform_get_drvdata(pdev); 1091 struct spear_smi *dev = platform_get_drvdata(pdev);
1092 1092
1093 if (dev && dev->clk) 1093 if (dev && dev->clk)
1094 clk_disable(dev->clk); 1094 clk_disable_unprepare(dev->clk);
1095 1095
1096 return 0; 1096 return 0;
1097} 1097}
@@ -1102,7 +1102,7 @@ int spear_smi_resume(struct platform_device *pdev)
1102 int ret = -EPERM; 1102 int ret = -EPERM;
1103 1103
1104 if (dev && dev->clk) 1104 if (dev && dev->clk)
1105 ret = clk_enable(dev->clk); 1105 ret = clk_prepare_enable(dev->clk);
1106 1106
1107 if (!ret) 1107 if (!ret)
1108 spear_smi_hw_init(dev); 1108 spear_smi_hw_init(dev);
diff --git a/drivers/mtd/lpddr/qinfo_probe.c b/drivers/mtd/lpddr/qinfo_probe.c
index dbfe17baf046..45abed67f1ef 100644
--- a/drivers/mtd/lpddr/qinfo_probe.c
+++ b/drivers/mtd/lpddr/qinfo_probe.c
@@ -57,7 +57,7 @@ static struct qinfo_query_info qinfo_array[] = {
57 57
58static long lpddr_get_qinforec_pos(struct map_info *map, char *id_str) 58static long lpddr_get_qinforec_pos(struct map_info *map, char *id_str)
59{ 59{
60 int qinfo_lines = sizeof(qinfo_array)/sizeof(struct qinfo_query_info); 60 int qinfo_lines = ARRAY_SIZE(qinfo_array);
61 int i; 61 int i;
62 int bankwidth = map_bankwidth(map) * 8; 62 int bankwidth = map_bankwidth(map) * 8;
63 int major, minor; 63 int major, minor;
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 8af67cfd671a..5ba2458e799a 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -224,7 +224,7 @@ config MTD_CK804XROM
224 224
225config MTD_SCB2_FLASH 225config MTD_SCB2_FLASH
226 tristate "BIOS flash chip on Intel SCB2 boards" 226 tristate "BIOS flash chip on Intel SCB2 boards"
227 depends on X86 && MTD_JEDECPROBE 227 depends on X86 && MTD_JEDECPROBE && PCI
228 help 228 help
229 Support for treating the BIOS flash chip on Intel SCB2 boards 229 Support for treating the BIOS flash chip on Intel SCB2 boards
230 as an MTD device - with this you can reprogram your BIOS. 230 as an MTD device - with this you can reprogram your BIOS.
diff --git a/drivers/mtd/maps/intel_vr_nor.c b/drivers/mtd/maps/intel_vr_nor.c
index 92e1f41634c7..93f03175c82d 100644
--- a/drivers/mtd/maps/intel_vr_nor.c
+++ b/drivers/mtd/maps/intel_vr_nor.c
@@ -260,18 +260,7 @@ static struct pci_driver vr_nor_pci_driver = {
260 .id_table = vr_nor_pci_ids, 260 .id_table = vr_nor_pci_ids,
261}; 261};
262 262
263static int __init vr_nor_mtd_init(void) 263module_pci_driver(vr_nor_pci_driver);
264{
265 return pci_register_driver(&vr_nor_pci_driver);
266}
267
268static void __exit vr_nor_mtd_exit(void)
269{
270 pci_unregister_driver(&vr_nor_pci_driver);
271}
272
273module_init(vr_nor_mtd_init);
274module_exit(vr_nor_mtd_exit);
275 264
276MODULE_AUTHOR("Andy Lowe"); 265MODULE_AUTHOR("Andy Lowe");
277MODULE_DESCRIPTION("MTD map driver for NOR flash on Intel Vermilion Range"); 266MODULE_DESCRIPTION("MTD map driver for NOR flash on Intel Vermilion Range");
diff --git a/drivers/mtd/maps/pci.c b/drivers/mtd/maps/pci.c
index 1d005a3e9b41..f14ce0af763f 100644
--- a/drivers/mtd/maps/pci.c
+++ b/drivers/mtd/maps/pci.c
@@ -352,18 +352,7 @@ static struct pci_driver mtd_pci_driver = {
352 .id_table = mtd_pci_ids, 352 .id_table = mtd_pci_ids,
353}; 353};
354 354
355static int __init mtd_pci_maps_init(void) 355module_pci_driver(mtd_pci_driver);
356{
357 return pci_register_driver(&mtd_pci_driver);
358}
359
360static void __exit mtd_pci_maps_exit(void)
361{
362 pci_unregister_driver(&mtd_pci_driver);
363}
364
365module_init(mtd_pci_maps_init);
366module_exit(mtd_pci_maps_exit);
367 356
368MODULE_LICENSE("GPL"); 357MODULE_LICENSE("GPL");
369MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); 358MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
diff --git a/drivers/mtd/maps/scb2_flash.c b/drivers/mtd/maps/scb2_flash.c
index 934a72c80078..9dcbc684abdb 100644
--- a/drivers/mtd/maps/scb2_flash.c
+++ b/drivers/mtd/maps/scb2_flash.c
@@ -234,20 +234,7 @@ static struct pci_driver scb2_flash_driver = {
234 .remove = __devexit_p(scb2_flash_remove), 234 .remove = __devexit_p(scb2_flash_remove),
235}; 235};
236 236
237static int __init 237module_pci_driver(scb2_flash_driver);
238scb2_flash_init(void)
239{
240 return pci_register_driver(&scb2_flash_driver);
241}
242
243static void __exit
244scb2_flash_exit(void)
245{
246 pci_unregister_driver(&scb2_flash_driver);
247}
248
249module_init(scb2_flash_init);
250module_exit(scb2_flash_exit);
251 238
252MODULE_LICENSE("GPL"); 239MODULE_LICENSE("GPL");
253MODULE_AUTHOR("Tim Hockin <thockin@sun.com>"); 240MODULE_AUTHOR("Tim Hockin <thockin@sun.com>");
diff --git a/drivers/mtd/maps/wr_sbc82xx_flash.c b/drivers/mtd/maps/wr_sbc82xx_flash.c
index 71b0ba797912..e7534c82f93a 100644
--- a/drivers/mtd/maps/wr_sbc82xx_flash.c
+++ b/drivers/mtd/maps/wr_sbc82xx_flash.c
@@ -59,7 +59,7 @@ static struct mtd_partition bigflash_parts[] = {
59 } 59 }
60}; 60};
61 61
62static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL}; 62static const char *part_probes[] __initconst = {"cmdlinepart", "RedBoot", NULL};
63 63
64#define init_sbc82xx_one_flash(map, br, or) \ 64#define init_sbc82xx_one_flash(map, br, or) \
65do { \ 65do { \
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index c837507dfb1c..575730744fdb 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -250,6 +250,43 @@ static ssize_t mtd_name_show(struct device *dev,
250} 250}
251static DEVICE_ATTR(name, S_IRUGO, mtd_name_show, NULL); 251static DEVICE_ATTR(name, S_IRUGO, mtd_name_show, NULL);
252 252
253static ssize_t mtd_ecc_strength_show(struct device *dev,
254 struct device_attribute *attr, char *buf)
255{
256 struct mtd_info *mtd = dev_get_drvdata(dev);
257
258 return snprintf(buf, PAGE_SIZE, "%u\n", mtd->ecc_strength);
259}
260static DEVICE_ATTR(ecc_strength, S_IRUGO, mtd_ecc_strength_show, NULL);
261
262static ssize_t mtd_bitflip_threshold_show(struct device *dev,
263 struct device_attribute *attr,
264 char *buf)
265{
266 struct mtd_info *mtd = dev_get_drvdata(dev);
267
268 return snprintf(buf, PAGE_SIZE, "%u\n", mtd->bitflip_threshold);
269}
270
271static ssize_t mtd_bitflip_threshold_store(struct device *dev,
272 struct device_attribute *attr,
273 const char *buf, size_t count)
274{
275 struct mtd_info *mtd = dev_get_drvdata(dev);
276 unsigned int bitflip_threshold;
277 int retval;
278
279 retval = kstrtouint(buf, 0, &bitflip_threshold);
280 if (retval)
281 return retval;
282
283 mtd->bitflip_threshold = bitflip_threshold;
284 return count;
285}
286static DEVICE_ATTR(bitflip_threshold, S_IRUGO | S_IWUSR,
287 mtd_bitflip_threshold_show,
288 mtd_bitflip_threshold_store);
289
253static struct attribute *mtd_attrs[] = { 290static struct attribute *mtd_attrs[] = {
254 &dev_attr_type.attr, 291 &dev_attr_type.attr,
255 &dev_attr_flags.attr, 292 &dev_attr_flags.attr,
@@ -260,6 +297,8 @@ static struct attribute *mtd_attrs[] = {
260 &dev_attr_oobsize.attr, 297 &dev_attr_oobsize.attr,
261 &dev_attr_numeraseregions.attr, 298 &dev_attr_numeraseregions.attr,
262 &dev_attr_name.attr, 299 &dev_attr_name.attr,
300 &dev_attr_ecc_strength.attr,
301 &dev_attr_bitflip_threshold.attr,
263 NULL, 302 NULL,
264}; 303};
265 304
@@ -322,6 +361,10 @@ int add_mtd_device(struct mtd_info *mtd)
322 mtd->index = i; 361 mtd->index = i;
323 mtd->usecount = 0; 362 mtd->usecount = 0;
324 363
364 /* default value if not set by driver */
365 if (mtd->bitflip_threshold == 0)
366 mtd->bitflip_threshold = mtd->ecc_strength;
367
325 if (is_power_of_2(mtd->erasesize)) 368 if (is_power_of_2(mtd->erasesize))
326 mtd->erasesize_shift = ffs(mtd->erasesize) - 1; 369 mtd->erasesize_shift = ffs(mtd->erasesize) - 1;
327 else 370 else
@@ -757,12 +800,24 @@ EXPORT_SYMBOL_GPL(mtd_get_unmapped_area);
757int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, 800int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
758 u_char *buf) 801 u_char *buf)
759{ 802{
803 int ret_code;
760 *retlen = 0; 804 *retlen = 0;
761 if (from < 0 || from > mtd->size || len > mtd->size - from) 805 if (from < 0 || from > mtd->size || len > mtd->size - from)
762 return -EINVAL; 806 return -EINVAL;
763 if (!len) 807 if (!len)
764 return 0; 808 return 0;
765 return mtd->_read(mtd, from, len, retlen, buf); 809
810 /*
811 * In the absence of an error, drivers return a non-negative integer
812 * representing the maximum number of bitflips that were corrected on
813 * any one ecc region (if applicable; zero otherwise).
814 */
815 ret_code = mtd->_read(mtd, from, len, retlen, buf);
816 if (unlikely(ret_code < 0))
817 return ret_code;
818 if (mtd->ecc_strength == 0)
819 return 0; /* device lacks ecc */
820 return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0;
766} 821}
767EXPORT_SYMBOL_GPL(mtd_read); 822EXPORT_SYMBOL_GPL(mtd_read);
768 823
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 9651c06de0a9..d518e4db8a0b 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -67,12 +67,12 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
67 stats = part->master->ecc_stats; 67 stats = part->master->ecc_stats;
68 res = part->master->_read(part->master, from + part->offset, len, 68 res = part->master->_read(part->master, from + part->offset, len,
69 retlen, buf); 69 retlen, buf);
70 if (unlikely(res)) { 70 if (unlikely(mtd_is_eccerr(res)))
71 if (mtd_is_bitflip(res)) 71 mtd->ecc_stats.failed +=
72 mtd->ecc_stats.corrected += part->master->ecc_stats.corrected - stats.corrected; 72 part->master->ecc_stats.failed - stats.failed;
73 if (mtd_is_eccerr(res)) 73 else
74 mtd->ecc_stats.failed += part->master->ecc_stats.failed - stats.failed; 74 mtd->ecc_stats.corrected +=
75 } 75 part->master->ecc_stats.corrected - stats.corrected;
76 return res; 76 return res;
77} 77}
78 78
@@ -517,6 +517,8 @@ static struct mtd_part *allocate_partition(struct mtd_info *master,
517 517
518 slave->mtd.ecclayout = master->ecclayout; 518 slave->mtd.ecclayout = master->ecclayout;
519 slave->mtd.ecc_strength = master->ecc_strength; 519 slave->mtd.ecc_strength = master->ecc_strength;
520 slave->mtd.bitflip_threshold = master->bitflip_threshold;
521
520 if (master->_block_isbad) { 522 if (master->_block_isbad) {
521 uint64_t offs = 0; 523 uint64_t offs = 0;
522 524
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 7d17cecad69d..31bb7e5b504a 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -115,6 +115,46 @@ config MTD_NAND_OMAP2
115 Support for NAND flash on Texas Instruments OMAP2, OMAP3 and OMAP4 115 Support for NAND flash on Texas Instruments OMAP2, OMAP3 and OMAP4
116 platforms. 116 platforms.
117 117
118config MTD_NAND_OMAP_BCH
119 depends on MTD_NAND && MTD_NAND_OMAP2 && ARCH_OMAP3
120 bool "Enable support for hardware BCH error correction"
121 default n
122 select BCH
123 select BCH_CONST_PARAMS
124 help
125 Support for hardware BCH error correction.
126
127choice
128 prompt "BCH error correction capability"
129 depends on MTD_NAND_OMAP_BCH
130
131config MTD_NAND_OMAP_BCH8
132 bool "8 bits / 512 bytes (recommended)"
133 help
134 Support correcting up to 8 bitflips per 512-byte block.
135 This will use 13 bytes of spare area per 512 bytes of page data.
136 This is the recommended mode, as 4-bit mode does not work
137 on some OMAP3 revisions, due to a hardware bug.
138
139config MTD_NAND_OMAP_BCH4
140 bool "4 bits / 512 bytes"
141 help
142 Support correcting up to 4 bitflips per 512-byte block.
143 This will use 7 bytes of spare area per 512 bytes of page data.
144 Note that this mode does not work on some OMAP3 revisions, due to a
145 hardware bug. Please check your OMAP datasheet before selecting this
146 mode.
147
148endchoice
149
150if MTD_NAND_OMAP_BCH
151config BCH_CONST_M
152 default 13
153config BCH_CONST_T
154 default 4 if MTD_NAND_OMAP_BCH4
155 default 8 if MTD_NAND_OMAP_BCH8
156endif
157
118config MTD_NAND_IDS 158config MTD_NAND_IDS
119 tristate 159 tristate
120 160
@@ -440,7 +480,7 @@ config MTD_NAND_NANDSIM
440 480
441config MTD_NAND_GPMI_NAND 481config MTD_NAND_GPMI_NAND
442 bool "GPMI NAND Flash Controller driver" 482 bool "GPMI NAND Flash Controller driver"
443 depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28) 483 depends on MTD_NAND && (SOC_IMX23 || SOC_IMX28 || SOC_IMX6Q)
444 help 484 help
445 Enables NAND Flash support for IMX23 or IMX28. 485 Enables NAND Flash support for IMX23 or IMX28.
446 The GPMI controller is very powerful, with the help of BCH 486 The GPMI controller is very powerful, with the help of BCH
diff --git a/drivers/mtd/nand/alauda.c b/drivers/mtd/nand/alauda.c
index 4f20e1d8bef1..60a0dfdb0808 100644
--- a/drivers/mtd/nand/alauda.c
+++ b/drivers/mtd/nand/alauda.c
@@ -414,7 +414,7 @@ static int alauda_bounce_read(struct mtd_info *mtd, loff_t from, size_t len,
414 } 414 }
415 err = 0; 415 err = 0;
416 if (corrected) 416 if (corrected)
417 err = -EUCLEAN; 417 err = 1; /* return max_bitflips per ecc step */
418 if (uncorrected) 418 if (uncorrected)
419 err = -EBADMSG; 419 err = -EBADMSG;
420out: 420out:
@@ -446,7 +446,7 @@ static int alauda_read(struct mtd_info *mtd, loff_t from, size_t len,
446 } 446 }
447 err = 0; 447 err = 0;
448 if (corrected) 448 if (corrected)
449 err = -EUCLEAN; 449 err = 1; /* return max_bitflips per ecc step */
450 if (uncorrected) 450 if (uncorrected)
451 err = -EBADMSG; 451 err = -EBADMSG;
452 return err; 452 return err;
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 2165576a1c67..97ac6712bb19 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -324,9 +324,10 @@ static int atmel_nand_calculate(struct mtd_info *mtd,
324 * mtd: mtd info structure 324 * mtd: mtd info structure
325 * chip: nand chip info structure 325 * chip: nand chip info structure
326 * buf: buffer to store read data 326 * buf: buffer to store read data
327 * oob_required: caller expects OOB data read to chip->oob_poi
327 */ 328 */
328static int atmel_nand_read_page(struct mtd_info *mtd, 329static int atmel_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
329 struct nand_chip *chip, uint8_t *buf, int page) 330 uint8_t *buf, int oob_required, int page)
330{ 331{
331 int eccsize = chip->ecc.size; 332 int eccsize = chip->ecc.size;
332 int eccbytes = chip->ecc.bytes; 333 int eccbytes = chip->ecc.bytes;
@@ -335,6 +336,7 @@ static int atmel_nand_read_page(struct mtd_info *mtd,
335 uint8_t *oob = chip->oob_poi; 336 uint8_t *oob = chip->oob_poi;
336 uint8_t *ecc_pos; 337 uint8_t *ecc_pos;
337 int stat; 338 int stat;
339 unsigned int max_bitflips = 0;
338 340
339 /* 341 /*
340 * Errata: ALE is incorrectly wired up to the ECC controller 342 * Errata: ALE is incorrectly wired up to the ECC controller
@@ -371,10 +373,12 @@ static int atmel_nand_read_page(struct mtd_info *mtd,
371 /* check if there's an error */ 373 /* check if there's an error */
372 stat = chip->ecc.correct(mtd, p, oob, NULL); 374 stat = chip->ecc.correct(mtd, p, oob, NULL);
373 375
374 if (stat < 0) 376 if (stat < 0) {
375 mtd->ecc_stats.failed++; 377 mtd->ecc_stats.failed++;
376 else 378 } else {
377 mtd->ecc_stats.corrected += stat; 379 mtd->ecc_stats.corrected += stat;
380 max_bitflips = max_t(unsigned int, max_bitflips, stat);
381 }
378 382
379 /* get back to oob start (end of page) */ 383 /* get back to oob start (end of page) */
380 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1); 384 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1);
@@ -382,7 +386,7 @@ static int atmel_nand_read_page(struct mtd_info *mtd,
382 /* read the oob */ 386 /* read the oob */
383 chip->read_buf(mtd, oob, mtd->oobsize); 387 chip->read_buf(mtd, oob, mtd->oobsize);
384 388
385 return 0; 389 return max_bitflips;
386} 390}
387 391
388/* 392/*
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 73abbc3e093e..9f609d2dcf62 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -508,8 +508,6 @@ static int __devinit au1550nd_probe(struct platform_device *pdev)
508 this->chip_delay = 30; 508 this->chip_delay = 30;
509 this->ecc.mode = NAND_ECC_SOFT; 509 this->ecc.mode = NAND_ECC_SOFT;
510 510
511 this->options = NAND_NO_AUTOINCR;
512
513 if (pd->devwidth) 511 if (pd->devwidth)
514 this->options |= NAND_BUSWIDTH_16; 512 this->options |= NAND_BUSWIDTH_16;
515 513
diff --git a/drivers/mtd/nand/bcm_umi_bch.c b/drivers/mtd/nand/bcm_umi_bch.c
index a930666d0687..5914bb32e001 100644
--- a/drivers/mtd/nand/bcm_umi_bch.c
+++ b/drivers/mtd/nand/bcm_umi_bch.c
@@ -22,9 +22,9 @@
22 22
23/* ---- Private Function Prototypes -------------------------------------- */ 23/* ---- Private Function Prototypes -------------------------------------- */
24static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd, 24static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd,
25 struct nand_chip *chip, uint8_t *buf, int page); 25 struct nand_chip *chip, uint8_t *buf, int oob_required, int page);
26static void bcm_umi_bch_write_page_hwecc(struct mtd_info *mtd, 26static void bcm_umi_bch_write_page_hwecc(struct mtd_info *mtd,
27 struct nand_chip *chip, const uint8_t *buf); 27 struct nand_chip *chip, const uint8_t *buf, int oob_required);
28 28
29/* ---- Private Variables ------------------------------------------------ */ 29/* ---- Private Variables ------------------------------------------------ */
30 30
@@ -103,11 +103,12 @@ static struct nand_ecclayout nand_hw_eccoob_4096 = {
103* @mtd: mtd info structure 103* @mtd: mtd info structure
104* @chip: nand chip info structure 104* @chip: nand chip info structure
105* @buf: buffer to store read data 105* @buf: buffer to store read data
106* @oob_required: caller expects OOB data read to chip->oob_poi
106* 107*
107***************************************************************************/ 108***************************************************************************/
108static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd, 109static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd,
109 struct nand_chip *chip, uint8_t * buf, 110 struct nand_chip *chip, uint8_t * buf,
110 int page) 111 int oob_required, int page)
111{ 112{
112 int sectorIdx = 0; 113 int sectorIdx = 0;
113 int eccsize = chip->ecc.size; 114 int eccsize = chip->ecc.size;
@@ -116,6 +117,7 @@ static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd,
116 uint8_t eccCalc[NAND_ECC_NUM_BYTES]; 117 uint8_t eccCalc[NAND_ECC_NUM_BYTES];
117 int sectorOobSize = mtd->oobsize / eccsteps; 118 int sectorOobSize = mtd->oobsize / eccsteps;
118 int stat; 119 int stat;
120 unsigned int max_bitflips = 0;
119 121
120 for (sectorIdx = 0; sectorIdx < eccsteps; 122 for (sectorIdx = 0; sectorIdx < eccsteps;
121 sectorIdx++, datap += eccsize) { 123 sectorIdx++, datap += eccsize) {
@@ -177,9 +179,10 @@ static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd,
177 } 179 }
178#endif 180#endif
179 mtd->ecc_stats.corrected += stat; 181 mtd->ecc_stats.corrected += stat;
182 max_bitflips = max_t(unsigned int, max_bitflips, stat);
180 } 183 }
181 } 184 }
182 return 0; 185 return max_bitflips;
183} 186}
184 187
185/**************************************************************************** 188/****************************************************************************
@@ -188,10 +191,11 @@ static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd,
188* @mtd: mtd info structure 191* @mtd: mtd info structure
189* @chip: nand chip info structure 192* @chip: nand chip info structure
190* @buf: data buffer 193* @buf: data buffer
194* @oob_required: must write chip->oob_poi to OOB
191* 195*
192***************************************************************************/ 196***************************************************************************/
193static void bcm_umi_bch_write_page_hwecc(struct mtd_info *mtd, 197static void bcm_umi_bch_write_page_hwecc(struct mtd_info *mtd,
194 struct nand_chip *chip, const uint8_t *buf) 198 struct nand_chip *chip, const uint8_t *buf, int oob_required)
195{ 199{
196 int sectorIdx = 0; 200 int sectorIdx = 0;
197 int eccsize = chip->ecc.size; 201 int eccsize = chip->ecc.size;
diff --git a/drivers/mtd/nand/bcm_umi_nand.c b/drivers/mtd/nand/bcm_umi_nand.c
index 6908cdde3065..c855e7cd337b 100644
--- a/drivers/mtd/nand/bcm_umi_nand.c
+++ b/drivers/mtd/nand/bcm_umi_nand.c
@@ -341,7 +341,7 @@ static int bcm_umi_nand_verify_buf(struct mtd_info *mtd, const u_char * buf,
341 * for MLC parts which may have permanently stuck bits. 341 * for MLC parts which may have permanently stuck bits.
342 */ 342 */
343 struct nand_chip *chip = mtd->priv; 343 struct nand_chip *chip = mtd->priv;
344 int ret = chip->ecc.read_page(mtd, chip, readbackbuf, 0); 344 int ret = chip->ecc.read_page(mtd, chip, readbackbuf, 0, 0);
345 if (ret < 0) 345 if (ret < 0)
346 return -EFAULT; 346 return -EFAULT;
347 else { 347 else {
@@ -476,12 +476,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
476 this->badblock_pattern = &largepage_bbt; 476 this->badblock_pattern = &largepage_bbt;
477 } 477 }
478 478
479 /* 479 this->ecc.strength = 8;
480 * FIXME: ecc strength value of 6 bits per 512 bytes of data is a
481 * conservative guess, given 13 ecc bytes and using bch alg.
482 * (Assume Galois field order m=15 to allow a margin of error.)
483 */
484 this->ecc.strength = 6;
485 480
486#endif 481#endif
487 482
diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index d7b86b925de5..3f1c18599cbd 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -558,7 +558,7 @@ static void bf5xx_nand_dma_write_buf(struct mtd_info *mtd,
558} 558}
559 559
560static int bf5xx_nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 560static int bf5xx_nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
561 uint8_t *buf, int page) 561 uint8_t *buf, int oob_required, int page)
562{ 562{
563 bf5xx_nand_read_buf(mtd, buf, mtd->writesize); 563 bf5xx_nand_read_buf(mtd, buf, mtd->writesize);
564 bf5xx_nand_read_buf(mtd, chip->oob_poi, mtd->oobsize); 564 bf5xx_nand_read_buf(mtd, chip->oob_poi, mtd->oobsize);
@@ -567,7 +567,7 @@ static int bf5xx_nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip
567} 567}
568 568
569static void bf5xx_nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 569static void bf5xx_nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
570 const uint8_t *buf) 570 const uint8_t *buf, int oob_required)
571{ 571{
572 bf5xx_nand_write_buf(mtd, buf, mtd->writesize); 572 bf5xx_nand_write_buf(mtd, buf, mtd->writesize);
573 bf5xx_nand_write_buf(mtd, chip->oob_poi, mtd->oobsize); 573 bf5xx_nand_write_buf(mtd, chip->oob_poi, mtd->oobsize);
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index 2a96e1a12062..41371ba1a811 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -364,25 +364,27 @@ static int cafe_nand_write_oob(struct mtd_info *mtd,
364 364
365/* Don't use -- use nand_read_oob_std for now */ 365/* Don't use -- use nand_read_oob_std for now */
366static int cafe_nand_read_oob(struct mtd_info *mtd, struct nand_chip *chip, 366static int cafe_nand_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
367 int page, int sndcmd) 367 int page)
368{ 368{
369 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page); 369 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
370 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); 370 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
371 return 1; 371 return 0;
372} 372}
373/** 373/**
374 * cafe_nand_read_page_syndrome - [REPLACEABLE] hardware ecc syndrome based page read 374 * cafe_nand_read_page_syndrome - [REPLACEABLE] hardware ecc syndrome based page read
375 * @mtd: mtd info structure 375 * @mtd: mtd info structure
376 * @chip: nand chip info structure 376 * @chip: nand chip info structure
377 * @buf: buffer to store read data 377 * @buf: buffer to store read data
378 * @oob_required: caller expects OOB data read to chip->oob_poi
378 * 379 *
379 * The hw generator calculates the error syndrome automatically. Therefor 380 * The hw generator calculates the error syndrome automatically. Therefor
380 * we need a special oob layout and handling. 381 * we need a special oob layout and handling.
381 */ 382 */
382static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip, 383static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
383 uint8_t *buf, int page) 384 uint8_t *buf, int oob_required, int page)
384{ 385{
385 struct cafe_priv *cafe = mtd->priv; 386 struct cafe_priv *cafe = mtd->priv;
387 unsigned int max_bitflips = 0;
386 388
387 cafe_dev_dbg(&cafe->pdev->dev, "ECC result %08x SYN1,2 %08x\n", 389 cafe_dev_dbg(&cafe->pdev->dev, "ECC result %08x SYN1,2 %08x\n",
388 cafe_readl(cafe, NAND_ECC_RESULT), 390 cafe_readl(cafe, NAND_ECC_RESULT),
@@ -449,10 +451,11 @@ static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
449 } else { 451 } else {
450 dev_dbg(&cafe->pdev->dev, "Corrected %d symbol errors\n", n); 452 dev_dbg(&cafe->pdev->dev, "Corrected %d symbol errors\n", n);
451 mtd->ecc_stats.corrected += n; 453 mtd->ecc_stats.corrected += n;
454 max_bitflips = max_t(unsigned int, max_bitflips, n);
452 } 455 }
453 } 456 }
454 457
455 return 0; 458 return max_bitflips;
456} 459}
457 460
458static struct nand_ecclayout cafe_oobinfo_2048 = { 461static struct nand_ecclayout cafe_oobinfo_2048 = {
@@ -518,7 +521,8 @@ static struct nand_bbt_descr cafe_bbt_mirror_descr_512 = {
518 521
519 522
520static void cafe_nand_write_page_lowlevel(struct mtd_info *mtd, 523static void cafe_nand_write_page_lowlevel(struct mtd_info *mtd,
521 struct nand_chip *chip, const uint8_t *buf) 524 struct nand_chip *chip,
525 const uint8_t *buf, int oob_required)
522{ 526{
523 struct cafe_priv *cafe = mtd->priv; 527 struct cafe_priv *cafe = mtd->priv;
524 528
@@ -530,16 +534,17 @@ static void cafe_nand_write_page_lowlevel(struct mtd_info *mtd,
530} 534}
531 535
532static int cafe_nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, 536static int cafe_nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
533 const uint8_t *buf, int page, int cached, int raw) 537 const uint8_t *buf, int oob_required, int page,
538 int cached, int raw)
534{ 539{
535 int status; 540 int status;
536 541
537 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); 542 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
538 543
539 if (unlikely(raw)) 544 if (unlikely(raw))
540 chip->ecc.write_page_raw(mtd, chip, buf); 545 chip->ecc.write_page_raw(mtd, chip, buf, oob_required);
541 else 546 else
542 chip->ecc.write_page(mtd, chip, buf); 547 chip->ecc.write_page(mtd, chip, buf, oob_required);
543 548
544 /* 549 /*
545 * Cached progamming disabled for now, Not sure if its worth the 550 * Cached progamming disabled for now, Not sure if its worth the
@@ -685,7 +690,7 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
685 690
686 /* Enable the following for a flash based bad block table */ 691 /* Enable the following for a flash based bad block table */
687 cafe->nand.bbt_options = NAND_BBT_USE_FLASH; 692 cafe->nand.bbt_options = NAND_BBT_USE_FLASH;
688 cafe->nand.options = NAND_NO_AUTOINCR | NAND_OWN_BUFFERS; 693 cafe->nand.options = NAND_OWN_BUFFERS;
689 694
690 if (skipbbt) { 695 if (skipbbt) {
691 cafe->nand.options |= NAND_SKIP_BBTSCAN; 696 cafe->nand.options |= NAND_SKIP_BBTSCAN;
@@ -888,17 +893,7 @@ static struct pci_driver cafe_nand_pci_driver = {
888 .resume = cafe_nand_resume, 893 .resume = cafe_nand_resume,
889}; 894};
890 895
891static int __init cafe_nand_init(void) 896module_pci_driver(cafe_nand_pci_driver);
892{
893 return pci_register_driver(&cafe_nand_pci_driver);
894}
895
896static void __exit cafe_nand_exit(void)
897{
898 pci_unregister_driver(&cafe_nand_pci_driver);
899}
900module_init(cafe_nand_init);
901module_exit(cafe_nand_exit);
902 897
903MODULE_LICENSE("GPL"); 898MODULE_LICENSE("GPL");
904MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 899MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c
index 821c34c62500..adb6c3ef37fb 100644
--- a/drivers/mtd/nand/cs553x_nand.c
+++ b/drivers/mtd/nand/cs553x_nand.c
@@ -240,7 +240,6 @@ static int __init cs553x_init_one(int cs, int mmio, unsigned long adr)
240 240
241 /* Enable the following for a flash based bad block table */ 241 /* Enable the following for a flash based bad block table */
242 this->bbt_options = NAND_BBT_USE_FLASH; 242 this->bbt_options = NAND_BBT_USE_FLASH;
243 this->options = NAND_NO_AUTOINCR;
244 243
245 /* Scan to find existence of the device */ 244 /* Scan to find existence of the device */
246 if (nand_scan(new_mtd, 1)) { 245 if (nand_scan(new_mtd, 1)) {
diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index a9e57d686297..0650aafa0dd2 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -924,9 +924,10 @@ bool is_erased(uint8_t *buf, int len)
924#define ECC_LAST_ERR(x) ((x) & ERR_CORRECTION_INFO__LAST_ERR_INFO) 924#define ECC_LAST_ERR(x) ((x) & ERR_CORRECTION_INFO__LAST_ERR_INFO)
925 925
926static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf, 926static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf,
927 uint32_t irq_status) 927 uint32_t irq_status, unsigned int *max_bitflips)
928{ 928{
929 bool check_erased_page = false; 929 bool check_erased_page = false;
930 unsigned int bitflips = 0;
930 931
931 if (irq_status & INTR_STATUS__ECC_ERR) { 932 if (irq_status & INTR_STATUS__ECC_ERR) {
932 /* read the ECC errors. we'll ignore them for now */ 933 /* read the ECC errors. we'll ignore them for now */
@@ -965,6 +966,7 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf,
965 /* correct the ECC error */ 966 /* correct the ECC error */
966 buf[offset] ^= err_correction_value; 967 buf[offset] ^= err_correction_value;
967 denali->mtd.ecc_stats.corrected++; 968 denali->mtd.ecc_stats.corrected++;
969 bitflips++;
968 } 970 }
969 } else { 971 } else {
970 /* if the error is not correctable, need to 972 /* if the error is not correctable, need to
@@ -984,6 +986,7 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf,
984 clear_interrupts(denali); 986 clear_interrupts(denali);
985 denali_set_intr_modes(denali, true); 987 denali_set_intr_modes(denali, true);
986 } 988 }
989 *max_bitflips = bitflips;
987 return check_erased_page; 990 return check_erased_page;
988} 991}
989 992
@@ -1084,7 +1087,7 @@ static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
1084 * by write_page above. 1087 * by write_page above.
1085 * */ 1088 * */
1086static void denali_write_page(struct mtd_info *mtd, struct nand_chip *chip, 1089static void denali_write_page(struct mtd_info *mtd, struct nand_chip *chip,
1087 const uint8_t *buf) 1090 const uint8_t *buf, int oob_required)
1088{ 1091{
1089 /* for regular page writes, we let HW handle all the ECC 1092 /* for regular page writes, we let HW handle all the ECC
1090 * data written to the device. */ 1093 * data written to the device. */
@@ -1096,7 +1099,7 @@ static void denali_write_page(struct mtd_info *mtd, struct nand_chip *chip,
1096 * write_page() function above. 1099 * write_page() function above.
1097 */ 1100 */
1098static void denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 1101static void denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1099 const uint8_t *buf) 1102 const uint8_t *buf, int oob_required)
1100{ 1103{
1101 /* for raw page writes, we want to disable ECC and simply write 1104 /* for raw page writes, we want to disable ECC and simply write
1102 whatever data is in the buffer. */ 1105 whatever data is in the buffer. */
@@ -1110,17 +1113,17 @@ static int denali_write_oob(struct mtd_info *mtd, struct nand_chip *chip,
1110} 1113}
1111 1114
1112static int denali_read_oob(struct mtd_info *mtd, struct nand_chip *chip, 1115static int denali_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
1113 int page, int sndcmd) 1116 int page)
1114{ 1117{
1115 read_oob_data(mtd, chip->oob_poi, page); 1118 read_oob_data(mtd, chip->oob_poi, page);
1116 1119
1117 return 0; /* notify NAND core to send command to 1120 return 0;
1118 NAND device. */
1119} 1121}
1120 1122
1121static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip, 1123static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
1122 uint8_t *buf, int page) 1124 uint8_t *buf, int oob_required, int page)
1123{ 1125{
1126 unsigned int max_bitflips;
1124 struct denali_nand_info *denali = mtd_to_denali(mtd); 1127 struct denali_nand_info *denali = mtd_to_denali(mtd);
1125 1128
1126 dma_addr_t addr = denali->buf.dma_buf; 1129 dma_addr_t addr = denali->buf.dma_buf;
@@ -1153,7 +1156,7 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
1153 1156
1154 memcpy(buf, denali->buf.buf, mtd->writesize); 1157 memcpy(buf, denali->buf.buf, mtd->writesize);
1155 1158
1156 check_erased_page = handle_ecc(denali, buf, irq_status); 1159 check_erased_page = handle_ecc(denali, buf, irq_status, &max_bitflips);
1157 denali_enable_dma(denali, false); 1160 denali_enable_dma(denali, false);
1158 1161
1159 if (check_erased_page) { 1162 if (check_erased_page) {
@@ -1167,11 +1170,11 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
1167 denali->mtd.ecc_stats.failed++; 1170 denali->mtd.ecc_stats.failed++;
1168 } 1171 }
1169 } 1172 }
1170 return 0; 1173 return max_bitflips;
1171} 1174}
1172 1175
1173static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 1176static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1174 uint8_t *buf, int page) 1177 uint8_t *buf, int oob_required, int page)
1175{ 1178{
1176 struct denali_nand_info *denali = mtd_to_denali(mtd); 1179 struct denali_nand_info *denali = mtd_to_denali(mtd);
1177 1180
@@ -1702,17 +1705,4 @@ static struct pci_driver denali_pci_driver = {
1702 .remove = denali_pci_remove, 1705 .remove = denali_pci_remove,
1703}; 1706};
1704 1707
1705static int __devinit denali_init(void) 1708module_pci_driver(denali_pci_driver);
1706{
1707 printk(KERN_INFO "Spectra MTD driver\n");
1708 return pci_register_driver(&denali_pci_driver);
1709}
1710
1711/* Free memory */
1712static void __devexit denali_exit(void)
1713{
1714 pci_unregister_driver(&denali_pci_driver);
1715}
1716
1717module_init(denali_init);
1718module_exit(denali_exit);
diff --git a/drivers/mtd/nand/docg4.c b/drivers/mtd/nand/docg4.c
index b08202664543..a225e49a5623 100644
--- a/drivers/mtd/nand/docg4.c
+++ b/drivers/mtd/nand/docg4.c
@@ -720,6 +720,7 @@ static int read_page(struct mtd_info *mtd, struct nand_chip *nand,
720 struct docg4_priv *doc = nand->priv; 720 struct docg4_priv *doc = nand->priv;
721 void __iomem *docptr = doc->virtadr; 721 void __iomem *docptr = doc->virtadr;
722 uint16_t status, edc_err, *buf16; 722 uint16_t status, edc_err, *buf16;
723 int bits_corrected = 0;
723 724
724 dev_dbg(doc->dev, "%s: page %08x\n", __func__, page); 725 dev_dbg(doc->dev, "%s: page %08x\n", __func__, page);
725 726
@@ -772,7 +773,7 @@ static int read_page(struct mtd_info *mtd, struct nand_chip *nand,
772 773
773 /* If bitflips are reported, attempt to correct with ecc */ 774 /* If bitflips are reported, attempt to correct with ecc */
774 if (edc_err & DOC_ECCCONF1_BCH_SYNDROM_ERR) { 775 if (edc_err & DOC_ECCCONF1_BCH_SYNDROM_ERR) {
775 int bits_corrected = correct_data(mtd, buf, page); 776 bits_corrected = correct_data(mtd, buf, page);
776 if (bits_corrected == -EBADMSG) 777 if (bits_corrected == -EBADMSG)
777 mtd->ecc_stats.failed++; 778 mtd->ecc_stats.failed++;
778 else 779 else
@@ -781,24 +782,24 @@ static int read_page(struct mtd_info *mtd, struct nand_chip *nand,
781 } 782 }
782 783
783 writew(0, docptr + DOC_DATAEND); 784 writew(0, docptr + DOC_DATAEND);
784 return 0; 785 return bits_corrected;
785} 786}
786 787
787 788
788static int docg4_read_page_raw(struct mtd_info *mtd, struct nand_chip *nand, 789static int docg4_read_page_raw(struct mtd_info *mtd, struct nand_chip *nand,
789 uint8_t *buf, int page) 790 uint8_t *buf, int oob_required, int page)
790{ 791{
791 return read_page(mtd, nand, buf, page, false); 792 return read_page(mtd, nand, buf, page, false);
792} 793}
793 794
794static int docg4_read_page(struct mtd_info *mtd, struct nand_chip *nand, 795static int docg4_read_page(struct mtd_info *mtd, struct nand_chip *nand,
795 uint8_t *buf, int page) 796 uint8_t *buf, int oob_required, int page)
796{ 797{
797 return read_page(mtd, nand, buf, page, true); 798 return read_page(mtd, nand, buf, page, true);
798} 799}
799 800
800static int docg4_read_oob(struct mtd_info *mtd, struct nand_chip *nand, 801static int docg4_read_oob(struct mtd_info *mtd, struct nand_chip *nand,
801 int page, int sndcmd) 802 int page)
802{ 803{
803 struct docg4_priv *doc = nand->priv; 804 struct docg4_priv *doc = nand->priv;
804 void __iomem *docptr = doc->virtadr; 805 void __iomem *docptr = doc->virtadr;
@@ -952,13 +953,13 @@ static void write_page(struct mtd_info *mtd, struct nand_chip *nand,
952} 953}
953 954
954static void docg4_write_page_raw(struct mtd_info *mtd, struct nand_chip *nand, 955static void docg4_write_page_raw(struct mtd_info *mtd, struct nand_chip *nand,
955 const uint8_t *buf) 956 const uint8_t *buf, int oob_required)
956{ 957{
957 return write_page(mtd, nand, buf, false); 958 return write_page(mtd, nand, buf, false);
958} 959}
959 960
960static void docg4_write_page(struct mtd_info *mtd, struct nand_chip *nand, 961static void docg4_write_page(struct mtd_info *mtd, struct nand_chip *nand,
961 const uint8_t *buf) 962 const uint8_t *buf, int oob_required)
962{ 963{
963 return write_page(mtd, nand, buf, true); 964 return write_page(mtd, nand, buf, true);
964} 965}
@@ -1002,7 +1003,7 @@ static int __init read_factory_bbt(struct mtd_info *mtd)
1002 return -ENOMEM; 1003 return -ENOMEM;
1003 1004
1004 read_page_prologue(mtd, g4_addr); 1005 read_page_prologue(mtd, g4_addr);
1005 status = docg4_read_page(mtd, nand, buf, DOCG4_FACTORY_BBT_PAGE); 1006 status = docg4_read_page(mtd, nand, buf, 0, DOCG4_FACTORY_BBT_PAGE);
1006 if (status) 1007 if (status)
1007 goto exit; 1008 goto exit;
1008 1009
@@ -1079,7 +1080,7 @@ static int docg4_block_markbad(struct mtd_info *mtd, loff_t ofs)
1079 1080
1080 /* write first page of block */ 1081 /* write first page of block */
1081 write_page_prologue(mtd, g4_addr); 1082 write_page_prologue(mtd, g4_addr);
1082 docg4_write_page(mtd, nand, buf); 1083 docg4_write_page(mtd, nand, buf, 1);
1083 ret = pageprog(mtd); 1084 ret = pageprog(mtd);
1084 if (!ret) 1085 if (!ret)
1085 mtd->ecc_stats.badblocks++; 1086 mtd->ecc_stats.badblocks++;
@@ -1192,8 +1193,7 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
1192 nand->ecc.prepad = 8; 1193 nand->ecc.prepad = 8;
1193 nand->ecc.bytes = 8; 1194 nand->ecc.bytes = 8;
1194 nand->ecc.strength = DOCG4_T; 1195 nand->ecc.strength = DOCG4_T;
1195 nand->options = 1196 nand->options = NAND_BUSWIDTH_16 | NAND_NO_SUBPAGE_WRITE;
1196 NAND_BUSWIDTH_16 | NAND_NO_SUBPAGE_WRITE | NAND_NO_AUTOINCR;
1197 nand->IO_ADDR_R = nand->IO_ADDR_W = doc->virtadr + DOC_IOSPACE_DATA; 1197 nand->IO_ADDR_R = nand->IO_ADDR_W = doc->virtadr + DOC_IOSPACE_DATA;
1198 nand->controller = &nand->hwcontrol; 1198 nand->controller = &nand->hwcontrol;
1199 spin_lock_init(&nand->controller->lock); 1199 spin_lock_init(&nand->controller->lock);
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index 80b5264f0a32..784293806110 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -75,6 +75,7 @@ struct fsl_elbc_fcm_ctrl {
75 unsigned int use_mdr; /* Non zero if the MDR is to be set */ 75 unsigned int use_mdr; /* Non zero if the MDR is to be set */
76 unsigned int oob; /* Non zero if operating on OOB data */ 76 unsigned int oob; /* Non zero if operating on OOB data */
77 unsigned int counter; /* counter for the initializations */ 77 unsigned int counter; /* counter for the initializations */
78 unsigned int max_bitflips; /* Saved during READ0 cmd */
78}; 79};
79 80
80/* These map to the positions used by the FCM hardware ECC generator */ 81/* These map to the positions used by the FCM hardware ECC generator */
@@ -253,6 +254,8 @@ static int fsl_elbc_run_command(struct mtd_info *mtd)
253 if (chip->ecc.mode != NAND_ECC_HW) 254 if (chip->ecc.mode != NAND_ECC_HW)
254 return 0; 255 return 0;
255 256
257 elbc_fcm_ctrl->max_bitflips = 0;
258
256 if (elbc_fcm_ctrl->read_bytes == mtd->writesize + mtd->oobsize) { 259 if (elbc_fcm_ctrl->read_bytes == mtd->writesize + mtd->oobsize) {
257 uint32_t lteccr = in_be32(&lbc->lteccr); 260 uint32_t lteccr = in_be32(&lbc->lteccr);
258 /* 261 /*
@@ -262,11 +265,16 @@ static int fsl_elbc_run_command(struct mtd_info *mtd)
262 * bits 28-31 are uncorrectable errors, marked elsewhere. 265 * bits 28-31 are uncorrectable errors, marked elsewhere.
263 * for small page nand only 1 bit is used. 266 * for small page nand only 1 bit is used.
264 * if the ELBC doesn't have the lteccr register it reads 0 267 * if the ELBC doesn't have the lteccr register it reads 0
268 * FIXME: 4 bits can be corrected on NANDs with 2k pages, so
269 * count the number of sub-pages with bitflips and update
270 * ecc_stats.corrected accordingly.
265 */ 271 */
266 if (lteccr & 0x000F000F) 272 if (lteccr & 0x000F000F)
267 out_be32(&lbc->lteccr, 0x000F000F); /* clear lteccr */ 273 out_be32(&lbc->lteccr, 0x000F000F); /* clear lteccr */
268 if (lteccr & 0x000F0000) 274 if (lteccr & 0x000F0000) {
269 mtd->ecc_stats.corrected++; 275 mtd->ecc_stats.corrected++;
276 elbc_fcm_ctrl->max_bitflips = 1;
277 }
270 } 278 }
271 279
272 return 0; 280 return 0;
@@ -738,26 +746,28 @@ static int fsl_elbc_chip_init_tail(struct mtd_info *mtd)
738 return 0; 746 return 0;
739} 747}
740 748
741static int fsl_elbc_read_page(struct mtd_info *mtd, 749static int fsl_elbc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
742 struct nand_chip *chip, 750 uint8_t *buf, int oob_required, int page)
743 uint8_t *buf,
744 int page)
745{ 751{
752 struct fsl_elbc_mtd *priv = chip->priv;
753 struct fsl_lbc_ctrl *ctrl = priv->ctrl;
754 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = ctrl->nand;
755
746 fsl_elbc_read_buf(mtd, buf, mtd->writesize); 756 fsl_elbc_read_buf(mtd, buf, mtd->writesize);
747 fsl_elbc_read_buf(mtd, chip->oob_poi, mtd->oobsize); 757 if (oob_required)
758 fsl_elbc_read_buf(mtd, chip->oob_poi, mtd->oobsize);
748 759
749 if (fsl_elbc_wait(mtd, chip) & NAND_STATUS_FAIL) 760 if (fsl_elbc_wait(mtd, chip) & NAND_STATUS_FAIL)
750 mtd->ecc_stats.failed++; 761 mtd->ecc_stats.failed++;
751 762
752 return 0; 763 return elbc_fcm_ctrl->max_bitflips;
753} 764}
754 765
755/* ECC will be calculated automatically, and errors will be detected in 766/* ECC will be calculated automatically, and errors will be detected in
756 * waitfunc. 767 * waitfunc.
757 */ 768 */
758static void fsl_elbc_write_page(struct mtd_info *mtd, 769static void fsl_elbc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
759 struct nand_chip *chip, 770 const uint8_t *buf, int oob_required)
760 const uint8_t *buf)
761{ 771{
762 fsl_elbc_write_buf(mtd, buf, mtd->writesize); 772 fsl_elbc_write_buf(mtd, buf, mtd->writesize);
763 fsl_elbc_write_buf(mtd, chip->oob_poi, mtd->oobsize); 773 fsl_elbc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
@@ -795,7 +805,7 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
795 chip->bbt_md = &bbt_mirror_descr; 805 chip->bbt_md = &bbt_mirror_descr;
796 806
797 /* set up nand options */ 807 /* set up nand options */
798 chip->options = NAND_NO_READRDY | NAND_NO_AUTOINCR; 808 chip->options = NAND_NO_READRDY;
799 chip->bbt_options = NAND_BBT_USE_FLASH; 809 chip->bbt_options = NAND_BBT_USE_FLASH;
800 810
801 chip->controller = &elbc_fcm_ctrl->controller; 811 chip->controller = &elbc_fcm_ctrl->controller;
@@ -814,11 +824,6 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
814 chip->ecc.size = 512; 824 chip->ecc.size = 512;
815 chip->ecc.bytes = 3; 825 chip->ecc.bytes = 3;
816 chip->ecc.strength = 1; 826 chip->ecc.strength = 1;
817 /*
818 * FIXME: can hardware ecc correct 4 bitflips if page size is
819 * 2k? Then does hardware report number of corrections for this
820 * case? If so, ecc_stats reporting needs to be fixed as well.
821 */
822 } else { 827 } else {
823 /* otherwise fall back to default software ECC */ 828 /* otherwise fall back to default software ECC */
824 chip->ecc.mode = NAND_ECC_SOFT; 829 chip->ecc.mode = NAND_ECC_SOFT;
diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c
index c30ac7b83d28..9602c1b7e27e 100644
--- a/drivers/mtd/nand/fsl_ifc_nand.c
+++ b/drivers/mtd/nand/fsl_ifc_nand.c
@@ -63,6 +63,7 @@ struct fsl_ifc_nand_ctrl {
63 unsigned int oob; /* Non zero if operating on OOB data */ 63 unsigned int oob; /* Non zero if operating on OOB data */
64 unsigned int eccread; /* Non zero for a full-page ECC read */ 64 unsigned int eccread; /* Non zero for a full-page ECC read */
65 unsigned int counter; /* counter for the initializations */ 65 unsigned int counter; /* counter for the initializations */
66 unsigned int max_bitflips; /* Saved during READ0 cmd */
66}; 67};
67 68
68static struct fsl_ifc_nand_ctrl *ifc_nand_ctrl; 69static struct fsl_ifc_nand_ctrl *ifc_nand_ctrl;
@@ -262,6 +263,8 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
262 if (ctrl->nand_stat & IFC_NAND_EVTER_STAT_WPER) 263 if (ctrl->nand_stat & IFC_NAND_EVTER_STAT_WPER)
263 dev_err(priv->dev, "NAND Flash Write Protect Error\n"); 264 dev_err(priv->dev, "NAND Flash Write Protect Error\n");
264 265
266 nctrl->max_bitflips = 0;
267
265 if (nctrl->eccread) { 268 if (nctrl->eccread) {
266 int errors; 269 int errors;
267 int bufnum = nctrl->page & priv->bufnum_mask; 270 int bufnum = nctrl->page & priv->bufnum_mask;
@@ -290,6 +293,9 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
290 } 293 }
291 294
292 mtd->ecc_stats.corrected += errors; 295 mtd->ecc_stats.corrected += errors;
296 nctrl->max_bitflips = max_t(unsigned int,
297 nctrl->max_bitflips,
298 errors);
293 } 299 }
294 300
295 nctrl->eccread = 0; 301 nctrl->eccread = 0;
@@ -375,21 +381,31 @@ static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command,
375 381
376 return; 382 return;
377 383
378 /* READID must read all 8 possible bytes */
379 case NAND_CMD_READID: 384 case NAND_CMD_READID:
385 case NAND_CMD_PARAM: {
386 int timing = IFC_FIR_OP_RB;
387 if (command == NAND_CMD_PARAM)
388 timing = IFC_FIR_OP_RBCD;
389
380 out_be32(&ifc->ifc_nand.nand_fir0, 390 out_be32(&ifc->ifc_nand.nand_fir0,
381 (IFC_FIR_OP_CMD0 << IFC_NAND_FIR0_OP0_SHIFT) | 391 (IFC_FIR_OP_CMD0 << IFC_NAND_FIR0_OP0_SHIFT) |
382 (IFC_FIR_OP_UA << IFC_NAND_FIR0_OP1_SHIFT) | 392 (IFC_FIR_OP_UA << IFC_NAND_FIR0_OP1_SHIFT) |
383 (IFC_FIR_OP_RB << IFC_NAND_FIR0_OP2_SHIFT)); 393 (timing << IFC_NAND_FIR0_OP2_SHIFT));
384 out_be32(&ifc->ifc_nand.nand_fcr0, 394 out_be32(&ifc->ifc_nand.nand_fcr0,
385 NAND_CMD_READID << IFC_NAND_FCR0_CMD0_SHIFT); 395 command << IFC_NAND_FCR0_CMD0_SHIFT);
386 /* 8 bytes for manuf, device and exts */ 396 out_be32(&ifc->ifc_nand.row3, column);
387 out_be32(&ifc->ifc_nand.nand_fbcr, 8); 397
388 ifc_nand_ctrl->read_bytes = 8; 398 /*
399 * although currently it's 8 bytes for READID, we always read
400 * the maximum 256 bytes(for PARAM)
401 */
402 out_be32(&ifc->ifc_nand.nand_fbcr, 256);
403 ifc_nand_ctrl->read_bytes = 256;
389 404
390 set_addr(mtd, 0, 0, 0); 405 set_addr(mtd, 0, 0, 0);
391 fsl_ifc_run_command(mtd); 406 fsl_ifc_run_command(mtd);
392 return; 407 return;
408 }
393 409
394 /* ERASE1 stores the block and page address */ 410 /* ERASE1 stores the block and page address */
395 case NAND_CMD_ERASE1: 411 case NAND_CMD_ERASE1:
@@ -682,15 +698,16 @@ static int fsl_ifc_wait(struct mtd_info *mtd, struct nand_chip *chip)
682 return nand_fsr | NAND_STATUS_WP; 698 return nand_fsr | NAND_STATUS_WP;
683} 699}
684 700
685static int fsl_ifc_read_page(struct mtd_info *mtd, 701static int fsl_ifc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
686 struct nand_chip *chip, 702 uint8_t *buf, int oob_required, int page)
687 uint8_t *buf, int page)
688{ 703{
689 struct fsl_ifc_mtd *priv = chip->priv; 704 struct fsl_ifc_mtd *priv = chip->priv;
690 struct fsl_ifc_ctrl *ctrl = priv->ctrl; 705 struct fsl_ifc_ctrl *ctrl = priv->ctrl;
706 struct fsl_ifc_nand_ctrl *nctrl = ifc_nand_ctrl;
691 707
692 fsl_ifc_read_buf(mtd, buf, mtd->writesize); 708 fsl_ifc_read_buf(mtd, buf, mtd->writesize);
693 fsl_ifc_read_buf(mtd, chip->oob_poi, mtd->oobsize); 709 if (oob_required)
710 fsl_ifc_read_buf(mtd, chip->oob_poi, mtd->oobsize);
694 711
695 if (ctrl->nand_stat & IFC_NAND_EVTER_STAT_ECCER) 712 if (ctrl->nand_stat & IFC_NAND_EVTER_STAT_ECCER)
696 dev_err(priv->dev, "NAND Flash ECC Uncorrectable Error\n"); 713 dev_err(priv->dev, "NAND Flash ECC Uncorrectable Error\n");
@@ -698,15 +715,14 @@ static int fsl_ifc_read_page(struct mtd_info *mtd,
698 if (ctrl->nand_stat != IFC_NAND_EVTER_STAT_OPC) 715 if (ctrl->nand_stat != IFC_NAND_EVTER_STAT_OPC)
699 mtd->ecc_stats.failed++; 716 mtd->ecc_stats.failed++;
700 717
701 return 0; 718 return nctrl->max_bitflips;
702} 719}
703 720
704/* ECC will be calculated automatically, and errors will be detected in 721/* ECC will be calculated automatically, and errors will be detected in
705 * waitfunc. 722 * waitfunc.
706 */ 723 */
707static void fsl_ifc_write_page(struct mtd_info *mtd, 724static void fsl_ifc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
708 struct nand_chip *chip, 725 const uint8_t *buf, int oob_required)
709 const uint8_t *buf)
710{ 726{
711 fsl_ifc_write_buf(mtd, buf, mtd->writesize); 727 fsl_ifc_write_buf(mtd, buf, mtd->writesize);
712 fsl_ifc_write_buf(mtd, chip->oob_poi, mtd->oobsize); 728 fsl_ifc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
@@ -789,7 +805,7 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
789 out_be32(&ifc->ifc_nand.ncfgr, 0x0); 805 out_be32(&ifc->ifc_nand.ncfgr, 0x0);
790 806
791 /* set up nand options */ 807 /* set up nand options */
792 chip->options = NAND_NO_READRDY | NAND_NO_AUTOINCR; 808 chip->options = NAND_NO_READRDY;
793 chip->bbt_options = NAND_BBT_USE_FLASH; 809 chip->bbt_options = NAND_BBT_USE_FLASH;
794 810
795 811
@@ -811,6 +827,7 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
811 /* Hardware generates ECC per 512 Bytes */ 827 /* Hardware generates ECC per 512 Bytes */
812 chip->ecc.size = 512; 828 chip->ecc.size = 512;
813 chip->ecc.bytes = 8; 829 chip->ecc.bytes = 8;
830 chip->ecc.strength = 4;
814 831
815 switch (csor & CSOR_NAND_PGS_MASK) { 832 switch (csor & CSOR_NAND_PGS_MASK) {
816 case CSOR_NAND_PGS_512: 833 case CSOR_NAND_PGS_512:
diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index 1b8330e1155a..38d26240d8b1 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -692,6 +692,7 @@ static void fsmc_write_buf_dma(struct mtd_info *mtd, const uint8_t *buf,
692 * @mtd: mtd info structure 692 * @mtd: mtd info structure
693 * @chip: nand chip info structure 693 * @chip: nand chip info structure
694 * @buf: buffer to store read data 694 * @buf: buffer to store read data
695 * @oob_required: caller expects OOB data read to chip->oob_poi
695 * @page: page number to read 696 * @page: page number to read
696 * 697 *
697 * This routine is needed for fsmc version 8 as reading from NAND chip has to be 698 * This routine is needed for fsmc version 8 as reading from NAND chip has to be
@@ -701,7 +702,7 @@ static void fsmc_write_buf_dma(struct mtd_info *mtd, const uint8_t *buf,
701 * max of 8 bits) 702 * max of 8 bits)
702 */ 703 */
703static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, 704static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
704 uint8_t *buf, int page) 705 uint8_t *buf, int oob_required, int page)
705{ 706{
706 struct fsmc_nand_data *host = container_of(mtd, 707 struct fsmc_nand_data *host = container_of(mtd,
707 struct fsmc_nand_data, mtd); 708 struct fsmc_nand_data, mtd);
@@ -720,6 +721,7 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
720 */ 721 */
721 uint16_t ecc_oob[7]; 722 uint16_t ecc_oob[7];
722 uint8_t *oob = (uint8_t *)&ecc_oob[0]; 723 uint8_t *oob = (uint8_t *)&ecc_oob[0];
724 unsigned int max_bitflips = 0;
723 725
724 for (i = 0, s = 0; s < eccsteps; s++, i += eccbytes, p += eccsize) { 726 for (i = 0, s = 0; s < eccsteps; s++, i += eccbytes, p += eccsize) {
725 chip->cmdfunc(mtd, NAND_CMD_READ0, s * eccsize, page); 727 chip->cmdfunc(mtd, NAND_CMD_READ0, s * eccsize, page);
@@ -748,13 +750,15 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
748 chip->ecc.calculate(mtd, p, &ecc_calc[i]); 750 chip->ecc.calculate(mtd, p, &ecc_calc[i]);
749 751
750 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); 752 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
751 if (stat < 0) 753 if (stat < 0) {
752 mtd->ecc_stats.failed++; 754 mtd->ecc_stats.failed++;
753 else 755 } else {
754 mtd->ecc_stats.corrected += stat; 756 mtd->ecc_stats.corrected += stat;
757 max_bitflips = max_t(unsigned int, max_bitflips, stat);
758 }
755 } 759 }
756 760
757 return 0; 761 return max_bitflips;
758} 762}
759 763
760/* 764/*
@@ -994,9 +998,9 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
994 return PTR_ERR(host->clk); 998 return PTR_ERR(host->clk);
995 } 999 }
996 1000
997 ret = clk_enable(host->clk); 1001 ret = clk_prepare_enable(host->clk);
998 if (ret) 1002 if (ret)
999 goto err_clk_enable; 1003 goto err_clk_prepare_enable;
1000 1004
1001 /* 1005 /*
1002 * This device ID is actually a common AMBA ID as used on the 1006 * This device ID is actually a common AMBA ID as used on the
@@ -1176,8 +1180,8 @@ err_req_write_chnl:
1176 if (host->mode == USE_DMA_ACCESS) 1180 if (host->mode == USE_DMA_ACCESS)
1177 dma_release_channel(host->read_dma_chan); 1181 dma_release_channel(host->read_dma_chan);
1178err_req_read_chnl: 1182err_req_read_chnl:
1179 clk_disable(host->clk); 1183 clk_disable_unprepare(host->clk);
1180err_clk_enable: 1184err_clk_prepare_enable:
1181 clk_put(host->clk); 1185 clk_put(host->clk);
1182 return ret; 1186 return ret;
1183} 1187}
@@ -1198,7 +1202,7 @@ static int fsmc_nand_remove(struct platform_device *pdev)
1198 dma_release_channel(host->write_dma_chan); 1202 dma_release_channel(host->write_dma_chan);
1199 dma_release_channel(host->read_dma_chan); 1203 dma_release_channel(host->read_dma_chan);
1200 } 1204 }
1201 clk_disable(host->clk); 1205 clk_disable_unprepare(host->clk);
1202 clk_put(host->clk); 1206 clk_put(host->clk);
1203 } 1207 }
1204 1208
@@ -1210,7 +1214,7 @@ static int fsmc_nand_suspend(struct device *dev)
1210{ 1214{
1211 struct fsmc_nand_data *host = dev_get_drvdata(dev); 1215 struct fsmc_nand_data *host = dev_get_drvdata(dev);
1212 if (host) 1216 if (host)
1213 clk_disable(host->clk); 1217 clk_disable_unprepare(host->clk);
1214 return 0; 1218 return 0;
1215} 1219}
1216 1220
@@ -1218,7 +1222,7 @@ static int fsmc_nand_resume(struct device *dev)
1218{ 1222{
1219 struct fsmc_nand_data *host = dev_get_drvdata(dev); 1223 struct fsmc_nand_data *host = dev_get_drvdata(dev);
1220 if (host) { 1224 if (host) {
1221 clk_enable(host->clk); 1225 clk_prepare_enable(host->clk);
1222 fsmc_nand_setup(host->regs_va, host->bank, 1226 fsmc_nand_setup(host->regs_va, host->bank,
1223 host->nand.options & NAND_BUSWIDTH_16, 1227 host->nand.options & NAND_BUSWIDTH_16,
1224 host->dev_timings); 1228 host->dev_timings);
diff --git a/drivers/mtd/nand/gpmi-nand/bch-regs.h b/drivers/mtd/nand/gpmi-nand/bch-regs.h
index 4effb8c579db..a0924515c396 100644
--- a/drivers/mtd/nand/gpmi-nand/bch-regs.h
+++ b/drivers/mtd/nand/gpmi-nand/bch-regs.h
@@ -51,15 +51,26 @@
51 51
52#define BP_BCH_FLASH0LAYOUT0_ECC0 12 52#define BP_BCH_FLASH0LAYOUT0_ECC0 12
53#define BM_BCH_FLASH0LAYOUT0_ECC0 (0xf << BP_BCH_FLASH0LAYOUT0_ECC0) 53#define BM_BCH_FLASH0LAYOUT0_ECC0 (0xf << BP_BCH_FLASH0LAYOUT0_ECC0)
54#define BF_BCH_FLASH0LAYOUT0_ECC0(v) \ 54#define MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0 11
55 (((v) << BP_BCH_FLASH0LAYOUT0_ECC0) & BM_BCH_FLASH0LAYOUT0_ECC0) 55#define MX6Q_BM_BCH_FLASH0LAYOUT0_ECC0 (0x1f << MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0)
56#define BF_BCH_FLASH0LAYOUT0_ECC0(v, x) \
57 (GPMI_IS_MX6Q(x) \
58 ? (((v) << MX6Q_BP_BCH_FLASH0LAYOUT0_ECC0) \
59 & MX6Q_BM_BCH_FLASH0LAYOUT0_ECC0) \
60 : (((v) << BP_BCH_FLASH0LAYOUT0_ECC0) \
61 & BM_BCH_FLASH0LAYOUT0_ECC0) \
62 )
56 63
57#define BP_BCH_FLASH0LAYOUT0_DATA0_SIZE 0 64#define BP_BCH_FLASH0LAYOUT0_DATA0_SIZE 0
58#define BM_BCH_FLASH0LAYOUT0_DATA0_SIZE \ 65#define BM_BCH_FLASH0LAYOUT0_DATA0_SIZE \
59 (0xfff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE) 66 (0xfff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
60#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v) \ 67#define MX6Q_BM_BCH_FLASH0LAYOUT0_DATA0_SIZE \
61 (((v) << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)\ 68 (0x3ff << BP_BCH_FLASH0LAYOUT0_DATA0_SIZE)
62 & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE) 69#define BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(v, x) \
70 (GPMI_IS_MX6Q(x) \
71 ? (((v) >> 2) & MX6Q_BM_BCH_FLASH0LAYOUT0_DATA0_SIZE) \
72 : ((v) & BM_BCH_FLASH0LAYOUT0_DATA0_SIZE) \
73 )
63 74
64#define HW_BCH_FLASH0LAYOUT1 0x00000090 75#define HW_BCH_FLASH0LAYOUT1 0x00000090
65 76
@@ -72,13 +83,24 @@
72 83
73#define BP_BCH_FLASH0LAYOUT1_ECCN 12 84#define BP_BCH_FLASH0LAYOUT1_ECCN 12
74#define BM_BCH_FLASH0LAYOUT1_ECCN (0xf << BP_BCH_FLASH0LAYOUT1_ECCN) 85#define BM_BCH_FLASH0LAYOUT1_ECCN (0xf << BP_BCH_FLASH0LAYOUT1_ECCN)
75#define BF_BCH_FLASH0LAYOUT1_ECCN(v) \ 86#define MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN 11
76 (((v) << BP_BCH_FLASH0LAYOUT1_ECCN) & BM_BCH_FLASH0LAYOUT1_ECCN) 87#define MX6Q_BM_BCH_FLASH0LAYOUT1_ECCN (0x1f << MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN)
88#define BF_BCH_FLASH0LAYOUT1_ECCN(v, x) \
89 (GPMI_IS_MX6Q(x) \
90 ? (((v) << MX6Q_BP_BCH_FLASH0LAYOUT1_ECCN) \
91 & MX6Q_BM_BCH_FLASH0LAYOUT1_ECCN) \
92 : (((v) << BP_BCH_FLASH0LAYOUT1_ECCN) \
93 & BM_BCH_FLASH0LAYOUT1_ECCN) \
94 )
77 95
78#define BP_BCH_FLASH0LAYOUT1_DATAN_SIZE 0 96#define BP_BCH_FLASH0LAYOUT1_DATAN_SIZE 0
79#define BM_BCH_FLASH0LAYOUT1_DATAN_SIZE \ 97#define BM_BCH_FLASH0LAYOUT1_DATAN_SIZE \
80 (0xfff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE) 98 (0xfff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
81#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v) \ 99#define MX6Q_BM_BCH_FLASH0LAYOUT1_DATAN_SIZE \
82 (((v) << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE) \ 100 (0x3ff << BP_BCH_FLASH0LAYOUT1_DATAN_SIZE)
83 & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE) 101#define BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(v, x) \
102 (GPMI_IS_MX6Q(x) \
103 ? (((v) >> 2) & MX6Q_BM_BCH_FLASH0LAYOUT1_DATAN_SIZE) \
104 : ((v) & BM_BCH_FLASH0LAYOUT1_DATAN_SIZE) \
105 )
84#endif 106#endif
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
index e8ea7107932e..a1f43329ad43 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c
@@ -21,7 +21,6 @@
21#include <linux/mtd/gpmi-nand.h> 21#include <linux/mtd/gpmi-nand.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/clk.h> 23#include <linux/clk.h>
24#include <mach/mxs.h>
25 24
26#include "gpmi-nand.h" 25#include "gpmi-nand.h"
27#include "gpmi-regs.h" 26#include "gpmi-regs.h"
@@ -37,6 +36,8 @@ struct timing_threshod timing_default_threshold = {
37 .max_dll_delay_in_ns = 16, 36 .max_dll_delay_in_ns = 16,
38}; 37};
39 38
39#define MXS_SET_ADDR 0x4
40#define MXS_CLR_ADDR 0x8
40/* 41/*
41 * Clear the bit and poll it cleared. This is usually called with 42 * Clear the bit and poll it cleared. This is usually called with
42 * a reset address and mask being either SFTRST(bit 31) or CLKGATE 43 * a reset address and mask being either SFTRST(bit 31) or CLKGATE
@@ -47,7 +48,7 @@ static int clear_poll_bit(void __iomem *addr, u32 mask)
47 int timeout = 0x400; 48 int timeout = 0x400;
48 49
49 /* clear the bit */ 50 /* clear the bit */
50 __mxs_clrl(mask, addr); 51 writel(mask, addr + MXS_CLR_ADDR);
51 52
52 /* 53 /*
53 * SFTRST needs 3 GPMI clocks to settle, the reference manual 54 * SFTRST needs 3 GPMI clocks to settle, the reference manual
@@ -92,11 +93,11 @@ static int gpmi_reset_block(void __iomem *reset_addr, bool just_enable)
92 goto error; 93 goto error;
93 94
94 /* clear CLKGATE */ 95 /* clear CLKGATE */
95 __mxs_clrl(MODULE_CLKGATE, reset_addr); 96 writel(MODULE_CLKGATE, reset_addr + MXS_CLR_ADDR);
96 97
97 if (!just_enable) { 98 if (!just_enable) {
98 /* set SFTRST to reset the block */ 99 /* set SFTRST to reset the block */
99 __mxs_setl(MODULE_SFTRST, reset_addr); 100 writel(MODULE_SFTRST, reset_addr + MXS_SET_ADDR);
100 udelay(1); 101 udelay(1);
101 102
102 /* poll CLKGATE becoming set */ 103 /* poll CLKGATE becoming set */
@@ -223,13 +224,13 @@ int bch_set_geometry(struct gpmi_nand_data *this)
223 /* Configure layout 0. */ 224 /* Configure layout 0. */
224 writel(BF_BCH_FLASH0LAYOUT0_NBLOCKS(block_count) 225 writel(BF_BCH_FLASH0LAYOUT0_NBLOCKS(block_count)
225 | BF_BCH_FLASH0LAYOUT0_META_SIZE(metadata_size) 226 | BF_BCH_FLASH0LAYOUT0_META_SIZE(metadata_size)
226 | BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength) 227 | BF_BCH_FLASH0LAYOUT0_ECC0(ecc_strength, this)
227 | BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size), 228 | BF_BCH_FLASH0LAYOUT0_DATA0_SIZE(block_size, this),
228 r->bch_regs + HW_BCH_FLASH0LAYOUT0); 229 r->bch_regs + HW_BCH_FLASH0LAYOUT0);
229 230
230 writel(BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size) 231 writel(BF_BCH_FLASH0LAYOUT1_PAGE_SIZE(page_size)
231 | BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength) 232 | BF_BCH_FLASH0LAYOUT1_ECCN(ecc_strength, this)
232 | BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size), 233 | BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this),
233 r->bch_regs + HW_BCH_FLASH0LAYOUT1); 234 r->bch_regs + HW_BCH_FLASH0LAYOUT1);
234 235
235 /* Set *all* chip selects to use layout 0. */ 236 /* Set *all* chip selects to use layout 0. */
@@ -255,11 +256,12 @@ static unsigned int ns_to_cycles(unsigned int time,
255 return max(k, min); 256 return max(k, min);
256} 257}
257 258
259#define DEF_MIN_PROP_DELAY 5
260#define DEF_MAX_PROP_DELAY 9
258/* Apply timing to current hardware conditions. */ 261/* Apply timing to current hardware conditions. */
259static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this, 262static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this,
260 struct gpmi_nfc_hardware_timing *hw) 263 struct gpmi_nfc_hardware_timing *hw)
261{ 264{
262 struct gpmi_nand_platform_data *pdata = this->pdata;
263 struct timing_threshod *nfc = &timing_default_threshold; 265 struct timing_threshod *nfc = &timing_default_threshold;
264 struct nand_chip *nand = &this->nand; 266 struct nand_chip *nand = &this->nand;
265 struct nand_timing target = this->timing; 267 struct nand_timing target = this->timing;
@@ -276,8 +278,8 @@ static int gpmi_nfc_compute_hardware_timing(struct gpmi_nand_data *this,
276 int ideal_sample_delay_in_ns; 278 int ideal_sample_delay_in_ns;
277 unsigned int sample_delay_factor; 279 unsigned int sample_delay_factor;
278 int tEYE; 280 int tEYE;
279 unsigned int min_prop_delay_in_ns = pdata->min_prop_delay_in_ns; 281 unsigned int min_prop_delay_in_ns = DEF_MIN_PROP_DELAY;
280 unsigned int max_prop_delay_in_ns = pdata->max_prop_delay_in_ns; 282 unsigned int max_prop_delay_in_ns = DEF_MAX_PROP_DELAY;
281 283
282 /* 284 /*
283 * If there are multiple chips, we need to relax the timings to allow 285 * If there are multiple chips, we need to relax the timings to allow
@@ -803,7 +805,8 @@ int gpmi_is_ready(struct gpmi_nand_data *this, unsigned chip)
803 if (GPMI_IS_MX23(this)) { 805 if (GPMI_IS_MX23(this)) {
804 mask = MX23_BM_GPMI_DEBUG_READY0 << chip; 806 mask = MX23_BM_GPMI_DEBUG_READY0 << chip;
805 reg = readl(r->gpmi_regs + HW_GPMI_DEBUG); 807 reg = readl(r->gpmi_regs + HW_GPMI_DEBUG);
806 } else if (GPMI_IS_MX28(this)) { 808 } else if (GPMI_IS_MX28(this) || GPMI_IS_MX6Q(this)) {
809 /* MX28 shares the same R/B register as MX6Q. */
807 mask = MX28_BF_GPMI_STAT_READY_BUSY(1 << chip); 810 mask = MX28_BF_GPMI_STAT_READY_BUSY(1 << chip);
808 reg = readl(r->gpmi_regs + HW_GPMI_STAT); 811 reg = readl(r->gpmi_regs + HW_GPMI_STAT);
809 } else 812 } else
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
index b68e04310bd8..a05b7b444d4f 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
@@ -25,6 +25,8 @@
25#include <linux/mtd/gpmi-nand.h> 25#include <linux/mtd/gpmi-nand.h>
26#include <linux/mtd/partitions.h> 26#include <linux/mtd/partitions.h>
27#include <linux/pinctrl/consumer.h> 27#include <linux/pinctrl/consumer.h>
28#include <linux/of.h>
29#include <linux/of_device.h>
28#include "gpmi-nand.h" 30#include "gpmi-nand.h"
29 31
30/* add our owner bbt descriptor */ 32/* add our owner bbt descriptor */
@@ -387,7 +389,7 @@ static void release_bch_irq(struct gpmi_nand_data *this)
387static bool gpmi_dma_filter(struct dma_chan *chan, void *param) 389static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
388{ 390{
389 struct gpmi_nand_data *this = param; 391 struct gpmi_nand_data *this = param;
390 struct resource *r = this->private; 392 int dma_channel = (int)this->private;
391 393
392 if (!mxs_dma_is_apbh(chan)) 394 if (!mxs_dma_is_apbh(chan))
393 return false; 395 return false;
@@ -399,7 +401,7 @@ static bool gpmi_dma_filter(struct dma_chan *chan, void *param)
399 * for mx28 : MX28_DMA_GPMI0 ~ MX28_DMA_GPMI7 401 * for mx28 : MX28_DMA_GPMI0 ~ MX28_DMA_GPMI7
400 * (These eight channels share the same IRQ!) 402 * (These eight channels share the same IRQ!)
401 */ 403 */
402 if (r->start <= chan->chan_id && chan->chan_id <= r->end) { 404 if (dma_channel == chan->chan_id) {
403 chan->private = &this->dma_data; 405 chan->private = &this->dma_data;
404 return true; 406 return true;
405 } 407 }
@@ -419,57 +421,45 @@ static void release_dma_channels(struct gpmi_nand_data *this)
419static int __devinit acquire_dma_channels(struct gpmi_nand_data *this) 421static int __devinit acquire_dma_channels(struct gpmi_nand_data *this)
420{ 422{
421 struct platform_device *pdev = this->pdev; 423 struct platform_device *pdev = this->pdev;
422 struct gpmi_nand_platform_data *pdata = this->pdata; 424 struct resource *r_dma;
423 struct resources *res = &this->resources; 425 struct device_node *dn;
424 struct resource *r, *r_dma; 426 int dma_channel;
425 unsigned int i; 427 unsigned int ret;
428 struct dma_chan *dma_chan;
429 dma_cap_mask_t mask;
430
431 /* dma channel, we only use the first one. */
432 dn = pdev->dev.of_node;
433 ret = of_property_read_u32(dn, "fsl,gpmi-dma-channel", &dma_channel);
434 if (ret) {
435 pr_err("unable to get DMA channel from dt.\n");
436 goto acquire_err;
437 }
438 this->private = (void *)dma_channel;
426 439
427 r = platform_get_resource_byname(pdev, IORESOURCE_DMA, 440 /* gpmi dma interrupt */
428 GPMI_NAND_DMA_CHANNELS_RES_NAME);
429 r_dma = platform_get_resource_byname(pdev, IORESOURCE_IRQ, 441 r_dma = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
430 GPMI_NAND_DMA_INTERRUPT_RES_NAME); 442 GPMI_NAND_DMA_INTERRUPT_RES_NAME);
431 if (!r || !r_dma) { 443 if (!r_dma) {
432 pr_err("Can't get resource for DMA\n"); 444 pr_err("Can't get resource for DMA\n");
433 return -ENXIO; 445 goto acquire_err;
434 } 446 }
447 this->dma_data.chan_irq = r_dma->start;
435 448
436 /* used in gpmi_dma_filter() */ 449 /* request dma channel */
437 this->private = r; 450 dma_cap_zero(mask);
438 451 dma_cap_set(DMA_SLAVE, mask);
439 for (i = r->start; i <= r->end; i++) {
440 struct dma_chan *dma_chan;
441 dma_cap_mask_t mask;
442 452
443 if (i - r->start >= pdata->max_chip_count) 453 dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
444 break; 454 if (!dma_chan) {
445 455 pr_err("dma_request_channel failed.\n");
446 dma_cap_zero(mask); 456 goto acquire_err;
447 dma_cap_set(DMA_SLAVE, mask);
448
449 /* get the DMA interrupt */
450 if (r_dma->start == r_dma->end) {
451 /* only register the first. */
452 if (i == r->start)
453 this->dma_data.chan_irq = r_dma->start;
454 else
455 this->dma_data.chan_irq = NO_IRQ;
456 } else
457 this->dma_data.chan_irq = r_dma->start + (i - r->start);
458
459 dma_chan = dma_request_channel(mask, gpmi_dma_filter, this);
460 if (!dma_chan)
461 goto acquire_err;
462
463 /* fill the first empty item */
464 this->dma_chans[i - r->start] = dma_chan;
465 } 457 }
466 458
467 res->dma_low_channel = r->start; 459 this->dma_chans[0] = dma_chan;
468 res->dma_high_channel = i;
469 return 0; 460 return 0;
470 461
471acquire_err: 462acquire_err:
472 pr_err("Can't acquire DMA channel %u\n", i);
473 release_dma_channels(this); 463 release_dma_channels(this);
474 return -EINVAL; 464 return -EINVAL;
475} 465}
@@ -851,7 +841,7 @@ static void block_mark_swapping(struct gpmi_nand_data *this,
851} 841}
852 842
853static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip, 843static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
854 uint8_t *buf, int page) 844 uint8_t *buf, int oob_required, int page)
855{ 845{
856 struct gpmi_nand_data *this = chip->priv; 846 struct gpmi_nand_data *this = chip->priv;
857 struct bch_geometry *nfc_geo = &this->bch_geometry; 847 struct bch_geometry *nfc_geo = &this->bch_geometry;
@@ -917,28 +907,31 @@ static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
917 mtd->ecc_stats.corrected += corrected; 907 mtd->ecc_stats.corrected += corrected;
918 } 908 }
919 909
920 /* 910 if (oob_required) {
921 * It's time to deliver the OOB bytes. See gpmi_ecc_read_oob() for 911 /*
922 * details about our policy for delivering the OOB. 912 * It's time to deliver the OOB bytes. See gpmi_ecc_read_oob()
923 * 913 * for details about our policy for delivering the OOB.
924 * We fill the caller's buffer with set bits, and then copy the block 914 *
925 * mark to th caller's buffer. Note that, if block mark swapping was 915 * We fill the caller's buffer with set bits, and then copy the
926 * necessary, it has already been done, so we can rely on the first 916 * block mark to th caller's buffer. Note that, if block mark
927 * byte of the auxiliary buffer to contain the block mark. 917 * swapping was necessary, it has already been done, so we can
928 */ 918 * rely on the first byte of the auxiliary buffer to contain
929 memset(chip->oob_poi, ~0, mtd->oobsize); 919 * the block mark.
930 chip->oob_poi[0] = ((uint8_t *) auxiliary_virt)[0]; 920 */
921 memset(chip->oob_poi, ~0, mtd->oobsize);
922 chip->oob_poi[0] = ((uint8_t *) auxiliary_virt)[0];
931 923
932 read_page_swap_end(this, buf, mtd->writesize, 924 read_page_swap_end(this, buf, mtd->writesize,
933 this->payload_virt, this->payload_phys, 925 this->payload_virt, this->payload_phys,
934 nfc_geo->payload_size, 926 nfc_geo->payload_size,
935 payload_virt, payload_phys); 927 payload_virt, payload_phys);
928 }
936exit_nfc: 929exit_nfc:
937 return ret; 930 return ret;
938} 931}
939 932
940static void gpmi_ecc_write_page(struct mtd_info *mtd, 933static void gpmi_ecc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
941 struct nand_chip *chip, const uint8_t *buf) 934 const uint8_t *buf, int oob_required)
942{ 935{
943 struct gpmi_nand_data *this = chip->priv; 936 struct gpmi_nand_data *this = chip->priv;
944 struct bch_geometry *nfc_geo = &this->bch_geometry; 937 struct bch_geometry *nfc_geo = &this->bch_geometry;
@@ -1077,7 +1070,7 @@ exit_auxiliary:
1077 * this driver. 1070 * this driver.
1078 */ 1071 */
1079static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip, 1072static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
1080 int page, int sndcmd) 1073 int page)
1081{ 1074{
1082 struct gpmi_nand_data *this = chip->priv; 1075 struct gpmi_nand_data *this = chip->priv;
1083 1076
@@ -1100,11 +1093,7 @@ static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
1100 chip->oob_poi[0] = chip->read_byte(mtd); 1093 chip->oob_poi[0] = chip->read_byte(mtd);
1101 } 1094 }
1102 1095
1103 /* 1096 return 0;
1104 * Return true, indicating that the next call to this function must send
1105 * a command.
1106 */
1107 return true;
1108} 1097}
1109 1098
1110static int 1099static int
@@ -1318,7 +1307,7 @@ static int mx23_write_transcription_stamp(struct gpmi_nand_data *this)
1318 /* Write the first page of the current stride. */ 1307 /* Write the first page of the current stride. */
1319 dev_dbg(dev, "Writing an NCB fingerprint in page 0x%x\n", page); 1308 dev_dbg(dev, "Writing an NCB fingerprint in page 0x%x\n", page);
1320 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); 1309 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
1321 chip->ecc.write_page_raw(mtd, chip, buffer); 1310 chip->ecc.write_page_raw(mtd, chip, buffer, 0);
1322 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); 1311 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
1323 1312
1324 /* Wait for the write to finish. */ 1313 /* Wait for the write to finish. */
@@ -1444,6 +1433,10 @@ static int gpmi_pre_bbt_scan(struct gpmi_nand_data *this)
1444 if (ret) 1433 if (ret)
1445 return ret; 1434 return ret;
1446 1435
1436 /* Adjust the ECC strength according to the chip. */
1437 this->nand.ecc.strength = this->bch_geometry.ecc_strength;
1438 this->mtd.ecc_strength = this->bch_geometry.ecc_strength;
1439
1447 /* NAND boot init, depends on the gpmi_set_geometry(). */ 1440 /* NAND boot init, depends on the gpmi_set_geometry(). */
1448 return nand_boot_init(this); 1441 return nand_boot_init(this);
1449} 1442}
@@ -1471,9 +1464,9 @@ void gpmi_nfc_exit(struct gpmi_nand_data *this)
1471 1464
1472static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this) 1465static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
1473{ 1466{
1474 struct gpmi_nand_platform_data *pdata = this->pdata;
1475 struct mtd_info *mtd = &this->mtd; 1467 struct mtd_info *mtd = &this->mtd;
1476 struct nand_chip *chip = &this->nand; 1468 struct nand_chip *chip = &this->nand;
1469 struct mtd_part_parser_data ppdata = {};
1477 int ret; 1470 int ret;
1478 1471
1479 /* init current chip */ 1472 /* init current chip */
@@ -1502,6 +1495,7 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
1502 chip->options |= NAND_NO_SUBPAGE_WRITE; 1495 chip->options |= NAND_NO_SUBPAGE_WRITE;
1503 chip->ecc.mode = NAND_ECC_HW; 1496 chip->ecc.mode = NAND_ECC_HW;
1504 chip->ecc.size = 1; 1497 chip->ecc.size = 1;
1498 chip->ecc.strength = 8;
1505 chip->ecc.layout = &gpmi_hw_ecclayout; 1499 chip->ecc.layout = &gpmi_hw_ecclayout;
1506 1500
1507 /* Allocate a temporary DMA buffer for reading ID in the nand_scan() */ 1501 /* Allocate a temporary DMA buffer for reading ID in the nand_scan() */
@@ -1511,14 +1505,14 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this)
1511 if (ret) 1505 if (ret)
1512 goto err_out; 1506 goto err_out;
1513 1507
1514 ret = nand_scan(mtd, pdata->max_chip_count); 1508 ret = nand_scan(mtd, 1);
1515 if (ret) { 1509 if (ret) {
1516 pr_err("Chip scan failed\n"); 1510 pr_err("Chip scan failed\n");
1517 goto err_out; 1511 goto err_out;
1518 } 1512 }
1519 1513
1520 ret = mtd_device_parse_register(mtd, NULL, NULL, 1514 ppdata.of_node = this->pdev->dev.of_node;
1521 pdata->partitions, pdata->partition_count); 1515 ret = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0);
1522 if (ret) 1516 if (ret)
1523 goto err_out; 1517 goto err_out;
1524 return 0; 1518 return 0;
@@ -1528,12 +1522,41 @@ err_out:
1528 return ret; 1522 return ret;
1529} 1523}
1530 1524
1525static const struct platform_device_id gpmi_ids[] = {
1526 { .name = "imx23-gpmi-nand", .driver_data = IS_MX23, },
1527 { .name = "imx28-gpmi-nand", .driver_data = IS_MX28, },
1528 { .name = "imx6q-gpmi-nand", .driver_data = IS_MX6Q, },
1529 {},
1530};
1531
1532static const struct of_device_id gpmi_nand_id_table[] = {
1533 {
1534 .compatible = "fsl,imx23-gpmi-nand",
1535 .data = (void *)&gpmi_ids[IS_MX23]
1536 }, {
1537 .compatible = "fsl,imx28-gpmi-nand",
1538 .data = (void *)&gpmi_ids[IS_MX28]
1539 }, {
1540 .compatible = "fsl,imx6q-gpmi-nand",
1541 .data = (void *)&gpmi_ids[IS_MX6Q]
1542 }, {}
1543};
1544MODULE_DEVICE_TABLE(of, gpmi_nand_id_table);
1545
1531static int __devinit gpmi_nand_probe(struct platform_device *pdev) 1546static int __devinit gpmi_nand_probe(struct platform_device *pdev)
1532{ 1547{
1533 struct gpmi_nand_platform_data *pdata = pdev->dev.platform_data;
1534 struct gpmi_nand_data *this; 1548 struct gpmi_nand_data *this;
1549 const struct of_device_id *of_id;
1535 int ret; 1550 int ret;
1536 1551
1552 of_id = of_match_device(gpmi_nand_id_table, &pdev->dev);
1553 if (of_id) {
1554 pdev->id_entry = of_id->data;
1555 } else {
1556 pr_err("Failed to find the right device id.\n");
1557 return -ENOMEM;
1558 }
1559
1537 this = kzalloc(sizeof(*this), GFP_KERNEL); 1560 this = kzalloc(sizeof(*this), GFP_KERNEL);
1538 if (!this) { 1561 if (!this) {
1539 pr_err("Failed to allocate per-device memory\n"); 1562 pr_err("Failed to allocate per-device memory\n");
@@ -1543,13 +1566,6 @@ static int __devinit gpmi_nand_probe(struct platform_device *pdev)
1543 platform_set_drvdata(pdev, this); 1566 platform_set_drvdata(pdev, this);
1544 this->pdev = pdev; 1567 this->pdev = pdev;
1545 this->dev = &pdev->dev; 1568 this->dev = &pdev->dev;
1546 this->pdata = pdata;
1547
1548 if (pdata->platform_init) {
1549 ret = pdata->platform_init();
1550 if (ret)
1551 goto platform_init_error;
1552 }
1553 1569
1554 ret = acquire_resources(this); 1570 ret = acquire_resources(this);
1555 if (ret) 1571 if (ret)
@@ -1567,7 +1583,6 @@ static int __devinit gpmi_nand_probe(struct platform_device *pdev)
1567 1583
1568exit_nfc_init: 1584exit_nfc_init:
1569 release_resources(this); 1585 release_resources(this);
1570platform_init_error:
1571exit_acquire_resources: 1586exit_acquire_resources:
1572 platform_set_drvdata(pdev, NULL); 1587 platform_set_drvdata(pdev, NULL);
1573 kfree(this); 1588 kfree(this);
@@ -1585,19 +1600,10 @@ static int __exit gpmi_nand_remove(struct platform_device *pdev)
1585 return 0; 1600 return 0;
1586} 1601}
1587 1602
1588static const struct platform_device_id gpmi_ids[] = {
1589 {
1590 .name = "imx23-gpmi-nand",
1591 .driver_data = IS_MX23,
1592 }, {
1593 .name = "imx28-gpmi-nand",
1594 .driver_data = IS_MX28,
1595 }, {},
1596};
1597
1598static struct platform_driver gpmi_nand_driver = { 1603static struct platform_driver gpmi_nand_driver = {
1599 .driver = { 1604 .driver = {
1600 .name = "gpmi-nand", 1605 .name = "gpmi-nand",
1606 .of_match_table = gpmi_nand_id_table,
1601 }, 1607 },
1602 .probe = gpmi_nand_probe, 1608 .probe = gpmi_nand_probe,
1603 .remove = __exit_p(gpmi_nand_remove), 1609 .remove = __exit_p(gpmi_nand_remove),
diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
index ec6180d4ff8f..ce5daa160920 100644
--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h
@@ -266,8 +266,10 @@ extern int gpmi_read_page(struct gpmi_nand_data *,
266#define STATUS_UNCORRECTABLE 0xfe 266#define STATUS_UNCORRECTABLE 0xfe
267 267
268/* Use the platform_id to distinguish different Archs. */ 268/* Use the platform_id to distinguish different Archs. */
269#define IS_MX23 0x1 269#define IS_MX23 0x0
270#define IS_MX28 0x2 270#define IS_MX28 0x1
271#define IS_MX6Q 0x2
271#define GPMI_IS_MX23(x) ((x)->pdev->id_entry->driver_data == IS_MX23) 272#define GPMI_IS_MX23(x) ((x)->pdev->id_entry->driver_data == IS_MX23)
272#define GPMI_IS_MX28(x) ((x)->pdev->id_entry->driver_data == IS_MX28) 273#define GPMI_IS_MX28(x) ((x)->pdev->id_entry->driver_data == IS_MX28)
274#define GPMI_IS_MX6Q(x) ((x)->pdev->id_entry->driver_data == IS_MX6Q)
273#endif 275#endif
diff --git a/drivers/mtd/nand/h1910.c b/drivers/mtd/nand/h1910.c
index 9bf5ce5fa22d..50166e93ba96 100644
--- a/drivers/mtd/nand/h1910.c
+++ b/drivers/mtd/nand/h1910.c
@@ -124,7 +124,6 @@ static int __init h1910_init(void)
124 /* 15 us command delay time */ 124 /* 15 us command delay time */
125 this->chip_delay = 50; 125 this->chip_delay = 50;
126 this->ecc.mode = NAND_ECC_SOFT; 126 this->ecc.mode = NAND_ECC_SOFT;
127 this->options = NAND_NO_AUTOINCR;
128 127
129 /* Scan to find existence of the device */ 128 /* Scan to find existence of the device */
130 if (nand_scan(h1910_nand_mtd, 1)) { 129 if (nand_scan(h1910_nand_mtd, 1)) {
diff --git a/drivers/mtd/nand/jz4740_nand.c b/drivers/mtd/nand/jz4740_nand.c
index e4147e8acb7c..a6fa884ae49b 100644
--- a/drivers/mtd/nand/jz4740_nand.c
+++ b/drivers/mtd/nand/jz4740_nand.c
@@ -332,11 +332,7 @@ static int __devinit jz_nand_probe(struct platform_device *pdev)
332 chip->ecc.mode = NAND_ECC_HW_OOB_FIRST; 332 chip->ecc.mode = NAND_ECC_HW_OOB_FIRST;
333 chip->ecc.size = 512; 333 chip->ecc.size = 512;
334 chip->ecc.bytes = 9; 334 chip->ecc.bytes = 9;
335 chip->ecc.strength = 2; 335 chip->ecc.strength = 4;
336 /*
337 * FIXME: ecc_strength value of 2 bits per 512 bytes of data is a
338 * conservative guess, given 9 ecc bytes and reed-solomon alg.
339 */
340 336
341 if (pdata) 337 if (pdata)
342 chip->ecc.layout = pdata->ecc_layout; 338 chip->ecc.layout = pdata->ecc_layout;
diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c
index c240cf1af961..c259c24d7986 100644
--- a/drivers/mtd/nand/mpc5121_nfc.c
+++ b/drivers/mtd/nand/mpc5121_nfc.c
@@ -734,7 +734,6 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op)
734 chip->write_buf = mpc5121_nfc_write_buf; 734 chip->write_buf = mpc5121_nfc_write_buf;
735 chip->verify_buf = mpc5121_nfc_verify_buf; 735 chip->verify_buf = mpc5121_nfc_verify_buf;
736 chip->select_chip = mpc5121_nfc_select_chip; 736 chip->select_chip = mpc5121_nfc_select_chip;
737 chip->options = NAND_NO_AUTOINCR;
738 chip->bbt_options = NAND_BBT_USE_FLASH; 737 chip->bbt_options = NAND_BBT_USE_FLASH;
739 chip->ecc.mode = NAND_ECC_SOFT; 738 chip->ecc.mode = NAND_ECC_SOFT;
740 739
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index 9e374e9bd296..c58e6a93f445 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -32,6 +32,8 @@
32#include <linux/io.h> 32#include <linux/io.h>
33#include <linux/irq.h> 33#include <linux/irq.h>
34#include <linux/completion.h> 34#include <linux/completion.h>
35#include <linux/of_device.h>
36#include <linux/of_mtd.h>
35 37
36#include <asm/mach/flash.h> 38#include <asm/mach/flash.h>
37#include <mach/mxc_nand.h> 39#include <mach/mxc_nand.h>
@@ -140,13 +142,47 @@
140 142
141#define NFC_V3_DELAY_LINE (host->regs_ip + 0x34) 143#define NFC_V3_DELAY_LINE (host->regs_ip + 0x34)
142 144
145struct mxc_nand_host;
146
147struct mxc_nand_devtype_data {
148 void (*preset)(struct mtd_info *);
149 void (*send_cmd)(struct mxc_nand_host *, uint16_t, int);
150 void (*send_addr)(struct mxc_nand_host *, uint16_t, int);
151 void (*send_page)(struct mtd_info *, unsigned int);
152 void (*send_read_id)(struct mxc_nand_host *);
153 uint16_t (*get_dev_status)(struct mxc_nand_host *);
154 int (*check_int)(struct mxc_nand_host *);
155 void (*irq_control)(struct mxc_nand_host *, int);
156 u32 (*get_ecc_status)(struct mxc_nand_host *);
157 struct nand_ecclayout *ecclayout_512, *ecclayout_2k, *ecclayout_4k;
158 void (*select_chip)(struct mtd_info *mtd, int chip);
159 int (*correct_data)(struct mtd_info *mtd, u_char *dat,
160 u_char *read_ecc, u_char *calc_ecc);
161
162 /*
163 * On i.MX21 the CONFIG2:INT bit cannot be read if interrupts are masked
164 * (CONFIG1:INT_MSK is set). To handle this the driver uses
165 * enable_irq/disable_irq_nosync instead of CONFIG1:INT_MSK
166 */
167 int irqpending_quirk;
168 int needs_ip;
169
170 size_t regs_offset;
171 size_t spare0_offset;
172 size_t axi_offset;
173
174 int spare_len;
175 int eccbytes;
176 int eccsize;
177};
178
143struct mxc_nand_host { 179struct mxc_nand_host {
144 struct mtd_info mtd; 180 struct mtd_info mtd;
145 struct nand_chip nand; 181 struct nand_chip nand;
146 struct device *dev; 182 struct device *dev;
147 183
148 void *spare0; 184 void __iomem *spare0;
149 void *main_area0; 185 void __iomem *main_area0;
150 186
151 void __iomem *base; 187 void __iomem *base;
152 void __iomem *regs; 188 void __iomem *regs;
@@ -163,16 +199,9 @@ struct mxc_nand_host {
163 199
164 uint8_t *data_buf; 200 uint8_t *data_buf;
165 unsigned int buf_start; 201 unsigned int buf_start;
166 int spare_len; 202
167 203 const struct mxc_nand_devtype_data *devtype_data;
168 void (*preset)(struct mtd_info *); 204 struct mxc_nand_platform_data pdata;
169 void (*send_cmd)(struct mxc_nand_host *, uint16_t, int);
170 void (*send_addr)(struct mxc_nand_host *, uint16_t, int);
171 void (*send_page)(struct mtd_info *, unsigned int);
172 void (*send_read_id)(struct mxc_nand_host *);
173 uint16_t (*get_dev_status)(struct mxc_nand_host *);
174 int (*check_int)(struct mxc_nand_host *);
175 void (*irq_control)(struct mxc_nand_host *, int);
176}; 205};
177 206
178/* OOB placement block for use with hardware ecc generation */ 207/* OOB placement block for use with hardware ecc generation */
@@ -242,21 +271,7 @@ static struct nand_ecclayout nandv2_hw_eccoob_4k = {
242 } 271 }
243}; 272};
244 273
245static const char *part_probes[] = { "RedBoot", "cmdlinepart", NULL }; 274static const char *part_probes[] = { "RedBoot", "cmdlinepart", "ofpart", NULL };
246
247static irqreturn_t mxc_nfc_irq(int irq, void *dev_id)
248{
249 struct mxc_nand_host *host = dev_id;
250
251 if (!host->check_int(host))
252 return IRQ_NONE;
253
254 host->irq_control(host, 0);
255
256 complete(&host->op_completion);
257
258 return IRQ_HANDLED;
259}
260 275
261static int check_int_v3(struct mxc_nand_host *host) 276static int check_int_v3(struct mxc_nand_host *host)
262{ 277{
@@ -280,26 +295,12 @@ static int check_int_v1_v2(struct mxc_nand_host *host)
280 if (!(tmp & NFC_V1_V2_CONFIG2_INT)) 295 if (!(tmp & NFC_V1_V2_CONFIG2_INT))
281 return 0; 296 return 0;
282 297
283 if (!cpu_is_mx21()) 298 if (!host->devtype_data->irqpending_quirk)
284 writew(tmp & ~NFC_V1_V2_CONFIG2_INT, NFC_V1_V2_CONFIG2); 299 writew(tmp & ~NFC_V1_V2_CONFIG2_INT, NFC_V1_V2_CONFIG2);
285 300
286 return 1; 301 return 1;
287} 302}
288 303
289/*
290 * It has been observed that the i.MX21 cannot read the CONFIG2:INT bit
291 * if interrupts are masked (CONFIG1:INT_MSK is set). To handle this, the
292 * driver can enable/disable the irq line rather than simply masking the
293 * interrupts.
294 */
295static void irq_control_mx21(struct mxc_nand_host *host, int activate)
296{
297 if (activate)
298 enable_irq(host->irq);
299 else
300 disable_irq_nosync(host->irq);
301}
302
303static void irq_control_v1_v2(struct mxc_nand_host *host, int activate) 304static void irq_control_v1_v2(struct mxc_nand_host *host, int activate)
304{ 305{
305 uint16_t tmp; 306 uint16_t tmp;
@@ -328,6 +329,47 @@ static void irq_control_v3(struct mxc_nand_host *host, int activate)
328 writel(tmp, NFC_V3_CONFIG2); 329 writel(tmp, NFC_V3_CONFIG2);
329} 330}
330 331
332static void irq_control(struct mxc_nand_host *host, int activate)
333{
334 if (host->devtype_data->irqpending_quirk) {
335 if (activate)
336 enable_irq(host->irq);
337 else
338 disable_irq_nosync(host->irq);
339 } else {
340 host->devtype_data->irq_control(host, activate);
341 }
342}
343
344static u32 get_ecc_status_v1(struct mxc_nand_host *host)
345{
346 return readw(NFC_V1_V2_ECC_STATUS_RESULT);
347}
348
349static u32 get_ecc_status_v2(struct mxc_nand_host *host)
350{
351 return readl(NFC_V1_V2_ECC_STATUS_RESULT);
352}
353
354static u32 get_ecc_status_v3(struct mxc_nand_host *host)
355{
356 return readl(NFC_V3_ECC_STATUS_RESULT);
357}
358
359static irqreturn_t mxc_nfc_irq(int irq, void *dev_id)
360{
361 struct mxc_nand_host *host = dev_id;
362
363 if (!host->devtype_data->check_int(host))
364 return IRQ_NONE;
365
366 irq_control(host, 0);
367
368 complete(&host->op_completion);
369
370 return IRQ_HANDLED;
371}
372
331/* This function polls the NANDFC to wait for the basic operation to 373/* This function polls the NANDFC to wait for the basic operation to
332 * complete by checking the INT bit of config2 register. 374 * complete by checking the INT bit of config2 register.
333 */ 375 */
@@ -336,14 +378,14 @@ static void wait_op_done(struct mxc_nand_host *host, int useirq)
336 int max_retries = 8000; 378 int max_retries = 8000;
337 379
338 if (useirq) { 380 if (useirq) {
339 if (!host->check_int(host)) { 381 if (!host->devtype_data->check_int(host)) {
340 INIT_COMPLETION(host->op_completion); 382 INIT_COMPLETION(host->op_completion);
341 host->irq_control(host, 1); 383 irq_control(host, 1);
342 wait_for_completion(&host->op_completion); 384 wait_for_completion(&host->op_completion);
343 } 385 }
344 } else { 386 } else {
345 while (max_retries-- > 0) { 387 while (max_retries-- > 0) {
346 if (host->check_int(host)) 388 if (host->devtype_data->check_int(host))
347 break; 389 break;
348 390
349 udelay(1); 391 udelay(1);
@@ -374,7 +416,7 @@ static void send_cmd_v1_v2(struct mxc_nand_host *host, uint16_t cmd, int useirq)
374 writew(cmd, NFC_V1_V2_FLASH_CMD); 416 writew(cmd, NFC_V1_V2_FLASH_CMD);
375 writew(NFC_CMD, NFC_V1_V2_CONFIG2); 417 writew(NFC_CMD, NFC_V1_V2_CONFIG2);
376 418
377 if (cpu_is_mx21() && (cmd == NAND_CMD_RESET)) { 419 if (host->devtype_data->irqpending_quirk && (cmd == NAND_CMD_RESET)) {
378 int max_retries = 100; 420 int max_retries = 100;
379 /* Reset completion is indicated by NFC_CONFIG2 */ 421 /* Reset completion is indicated by NFC_CONFIG2 */
380 /* being set to 0 */ 422 /* being set to 0 */
@@ -433,13 +475,27 @@ static void send_page_v3(struct mtd_info *mtd, unsigned int ops)
433 wait_op_done(host, false); 475 wait_op_done(host, false);
434} 476}
435 477
436static void send_page_v1_v2(struct mtd_info *mtd, unsigned int ops) 478static void send_page_v2(struct mtd_info *mtd, unsigned int ops)
479{
480 struct nand_chip *nand_chip = mtd->priv;
481 struct mxc_nand_host *host = nand_chip->priv;
482
483 /* NANDFC buffer 0 is used for page read/write */
484 writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
485
486 writew(ops, NFC_V1_V2_CONFIG2);
487
488 /* Wait for operation to complete */
489 wait_op_done(host, true);
490}
491
492static void send_page_v1(struct mtd_info *mtd, unsigned int ops)
437{ 493{
438 struct nand_chip *nand_chip = mtd->priv; 494 struct nand_chip *nand_chip = mtd->priv;
439 struct mxc_nand_host *host = nand_chip->priv; 495 struct mxc_nand_host *host = nand_chip->priv;
440 int bufs, i; 496 int bufs, i;
441 497
442 if (nfc_is_v1() && mtd->writesize > 512) 498 if (mtd->writesize > 512)
443 bufs = 4; 499 bufs = 4;
444 else 500 else
445 bufs = 1; 501 bufs = 1;
@@ -463,7 +519,7 @@ static void send_read_id_v3(struct mxc_nand_host *host)
463 519
464 wait_op_done(host, true); 520 wait_op_done(host, true);
465 521
466 memcpy(host->data_buf, host->main_area0, 16); 522 memcpy_fromio(host->data_buf, host->main_area0, 16);
467} 523}
468 524
469/* Request the NANDFC to perform a read of the NAND device ID. */ 525/* Request the NANDFC to perform a read of the NAND device ID. */
@@ -479,7 +535,7 @@ static void send_read_id_v1_v2(struct mxc_nand_host *host)
479 /* Wait for operation to complete */ 535 /* Wait for operation to complete */
480 wait_op_done(host, true); 536 wait_op_done(host, true);
481 537
482 memcpy(host->data_buf, host->main_area0, 16); 538 memcpy_fromio(host->data_buf, host->main_area0, 16);
483 539
484 if (this->options & NAND_BUSWIDTH_16) { 540 if (this->options & NAND_BUSWIDTH_16) {
485 /* compress the ID info */ 541 /* compress the ID info */
@@ -555,7 +611,7 @@ static int mxc_nand_correct_data_v1(struct mtd_info *mtd, u_char *dat,
555 * additional correction. 2-Bit errors cannot be corrected by 611 * additional correction. 2-Bit errors cannot be corrected by
556 * HW ECC, so we need to return failure 612 * HW ECC, so we need to return failure
557 */ 613 */
558 uint16_t ecc_status = readw(NFC_V1_V2_ECC_STATUS_RESULT); 614 uint16_t ecc_status = get_ecc_status_v1(host);
559 615
560 if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) { 616 if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) {
561 pr_debug("MXC_NAND: HWECC uncorrectable 2-bit ECC error\n"); 617 pr_debug("MXC_NAND: HWECC uncorrectable 2-bit ECC error\n");
@@ -580,10 +636,7 @@ static int mxc_nand_correct_data_v2_v3(struct mtd_info *mtd, u_char *dat,
580 636
581 no_subpages = mtd->writesize >> 9; 637 no_subpages = mtd->writesize >> 9;
582 638
583 if (nfc_is_v21()) 639 ecc_stat = host->devtype_data->get_ecc_status(host);
584 ecc_stat = readl(NFC_V1_V2_ECC_STATUS_RESULT);
585 else
586 ecc_stat = readl(NFC_V3_ECC_STATUS_RESULT);
587 640
588 do { 641 do {
589 err = ecc_stat & ecc_bit_mask; 642 err = ecc_stat & ecc_bit_mask;
@@ -616,7 +669,7 @@ static u_char mxc_nand_read_byte(struct mtd_info *mtd)
616 669
617 /* Check for status request */ 670 /* Check for status request */
618 if (host->status_request) 671 if (host->status_request)
619 return host->get_dev_status(host) & 0xFF; 672 return host->devtype_data->get_dev_status(host) & 0xFF;
620 673
621 ret = *(uint8_t *)(host->data_buf + host->buf_start); 674 ret = *(uint8_t *)(host->data_buf + host->buf_start);
622 host->buf_start++; 675 host->buf_start++;
@@ -682,7 +735,7 @@ static int mxc_nand_verify_buf(struct mtd_info *mtd,
682 735
683/* This function is used by upper layer for select and 736/* This function is used by upper layer for select and
684 * deselect of the NAND chip */ 737 * deselect of the NAND chip */
685static void mxc_nand_select_chip(struct mtd_info *mtd, int chip) 738static void mxc_nand_select_chip_v1_v3(struct mtd_info *mtd, int chip)
686{ 739{
687 struct nand_chip *nand_chip = mtd->priv; 740 struct nand_chip *nand_chip = mtd->priv;
688 struct mxc_nand_host *host = nand_chip->priv; 741 struct mxc_nand_host *host = nand_chip->priv;
@@ -701,11 +754,30 @@ static void mxc_nand_select_chip(struct mtd_info *mtd, int chip)
701 clk_prepare_enable(host->clk); 754 clk_prepare_enable(host->clk);
702 host->clk_act = 1; 755 host->clk_act = 1;
703 } 756 }
757}
704 758
705 if (nfc_is_v21()) { 759static void mxc_nand_select_chip_v2(struct mtd_info *mtd, int chip)
706 host->active_cs = chip; 760{
707 writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR); 761 struct nand_chip *nand_chip = mtd->priv;
762 struct mxc_nand_host *host = nand_chip->priv;
763
764 if (chip == -1) {
765 /* Disable the NFC clock */
766 if (host->clk_act) {
767 clk_disable(host->clk);
768 host->clk_act = 0;
769 }
770 return;
771 }
772
773 if (!host->clk_act) {
774 /* Enable the NFC clock */
775 clk_enable(host->clk);
776 host->clk_act = 1;
708 } 777 }
778
779 host->active_cs = chip;
780 writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
709} 781}
710 782
711/* 783/*
@@ -718,23 +790,23 @@ static void copy_spare(struct mtd_info *mtd, bool bfrom)
718 u16 i, j; 790 u16 i, j;
719 u16 n = mtd->writesize >> 9; 791 u16 n = mtd->writesize >> 9;
720 u8 *d = host->data_buf + mtd->writesize; 792 u8 *d = host->data_buf + mtd->writesize;
721 u8 *s = host->spare0; 793 u8 __iomem *s = host->spare0;
722 u16 t = host->spare_len; 794 u16 t = host->devtype_data->spare_len;
723 795
724 j = (mtd->oobsize / n >> 1) << 1; 796 j = (mtd->oobsize / n >> 1) << 1;
725 797
726 if (bfrom) { 798 if (bfrom) {
727 for (i = 0; i < n - 1; i++) 799 for (i = 0; i < n - 1; i++)
728 memcpy(d + i * j, s + i * t, j); 800 memcpy_fromio(d + i * j, s + i * t, j);
729 801
730 /* the last section */ 802 /* the last section */
731 memcpy(d + i * j, s + i * t, mtd->oobsize - i * j); 803 memcpy_fromio(d + i * j, s + i * t, mtd->oobsize - i * j);
732 } else { 804 } else {
733 for (i = 0; i < n - 1; i++) 805 for (i = 0; i < n - 1; i++)
734 memcpy(&s[i * t], &d[i * j], j); 806 memcpy_toio(&s[i * t], &d[i * j], j);
735 807
736 /* the last section */ 808 /* the last section */
737 memcpy(&s[i * t], &d[i * j], mtd->oobsize - i * j); 809 memcpy_toio(&s[i * t], &d[i * j], mtd->oobsize - i * j);
738 } 810 }
739} 811}
740 812
@@ -751,34 +823,44 @@ static void mxc_do_addr_cycle(struct mtd_info *mtd, int column, int page_addr)
751 * perform a read/write buf operation, the saved column 823 * perform a read/write buf operation, the saved column
752 * address is used to index into the full page. 824 * address is used to index into the full page.
753 */ 825 */
754 host->send_addr(host, 0, page_addr == -1); 826 host->devtype_data->send_addr(host, 0, page_addr == -1);
755 if (mtd->writesize > 512) 827 if (mtd->writesize > 512)
756 /* another col addr cycle for 2k page */ 828 /* another col addr cycle for 2k page */
757 host->send_addr(host, 0, false); 829 host->devtype_data->send_addr(host, 0, false);
758 } 830 }
759 831
760 /* Write out page address, if necessary */ 832 /* Write out page address, if necessary */
761 if (page_addr != -1) { 833 if (page_addr != -1) {
762 /* paddr_0 - p_addr_7 */ 834 /* paddr_0 - p_addr_7 */
763 host->send_addr(host, (page_addr & 0xff), false); 835 host->devtype_data->send_addr(host, (page_addr & 0xff), false);
764 836
765 if (mtd->writesize > 512) { 837 if (mtd->writesize > 512) {
766 if (mtd->size >= 0x10000000) { 838 if (mtd->size >= 0x10000000) {
767 /* paddr_8 - paddr_15 */ 839 /* paddr_8 - paddr_15 */
768 host->send_addr(host, (page_addr >> 8) & 0xff, false); 840 host->devtype_data->send_addr(host,
769 host->send_addr(host, (page_addr >> 16) & 0xff, true); 841 (page_addr >> 8) & 0xff,
842 false);
843 host->devtype_data->send_addr(host,
844 (page_addr >> 16) & 0xff,
845 true);
770 } else 846 } else
771 /* paddr_8 - paddr_15 */ 847 /* paddr_8 - paddr_15 */
772 host->send_addr(host, (page_addr >> 8) & 0xff, true); 848 host->devtype_data->send_addr(host,
849 (page_addr >> 8) & 0xff, true);
773 } else { 850 } else {
774 /* One more address cycle for higher density devices */ 851 /* One more address cycle for higher density devices */
775 if (mtd->size >= 0x4000000) { 852 if (mtd->size >= 0x4000000) {
776 /* paddr_8 - paddr_15 */ 853 /* paddr_8 - paddr_15 */
777 host->send_addr(host, (page_addr >> 8) & 0xff, false); 854 host->devtype_data->send_addr(host,
778 host->send_addr(host, (page_addr >> 16) & 0xff, true); 855 (page_addr >> 8) & 0xff,
856 false);
857 host->devtype_data->send_addr(host,
858 (page_addr >> 16) & 0xff,
859 true);
779 } else 860 } else
780 /* paddr_8 - paddr_15 */ 861 /* paddr_8 - paddr_15 */
781 host->send_addr(host, (page_addr >> 8) & 0xff, true); 862 host->devtype_data->send_addr(host,
863 (page_addr >> 8) & 0xff, true);
782 } 864 }
783 } 865 }
784} 866}
@@ -800,7 +882,35 @@ static int get_eccsize(struct mtd_info *mtd)
800 return 8; 882 return 8;
801} 883}
802 884
803static void preset_v1_v2(struct mtd_info *mtd) 885static void preset_v1(struct mtd_info *mtd)
886{
887 struct nand_chip *nand_chip = mtd->priv;
888 struct mxc_nand_host *host = nand_chip->priv;
889 uint16_t config1 = 0;
890
891 if (nand_chip->ecc.mode == NAND_ECC_HW)
892 config1 |= NFC_V1_V2_CONFIG1_ECC_EN;
893
894 if (!host->devtype_data->irqpending_quirk)
895 config1 |= NFC_V1_V2_CONFIG1_INT_MSK;
896
897 host->eccsize = 1;
898
899 writew(config1, NFC_V1_V2_CONFIG1);
900 /* preset operation */
901
902 /* Unlock the internal RAM Buffer */
903 writew(0x2, NFC_V1_V2_CONFIG);
904
905 /* Blocks to be unlocked */
906 writew(0x0, NFC_V1_UNLOCKSTART_BLKADDR);
907 writew(0xffff, NFC_V1_UNLOCKEND_BLKADDR);
908
909 /* Unlock Block Command for given address range */
910 writew(0x4, NFC_V1_V2_WRPROT);
911}
912
913static void preset_v2(struct mtd_info *mtd)
804{ 914{
805 struct nand_chip *nand_chip = mtd->priv; 915 struct nand_chip *nand_chip = mtd->priv;
806 struct mxc_nand_host *host = nand_chip->priv; 916 struct mxc_nand_host *host = nand_chip->priv;
@@ -809,13 +919,12 @@ static void preset_v1_v2(struct mtd_info *mtd)
809 if (nand_chip->ecc.mode == NAND_ECC_HW) 919 if (nand_chip->ecc.mode == NAND_ECC_HW)
810 config1 |= NFC_V1_V2_CONFIG1_ECC_EN; 920 config1 |= NFC_V1_V2_CONFIG1_ECC_EN;
811 921
812 if (nfc_is_v21()) 922 config1 |= NFC_V2_CONFIG1_FP_INT;
813 config1 |= NFC_V2_CONFIG1_FP_INT;
814 923
815 if (!cpu_is_mx21()) 924 if (!host->devtype_data->irqpending_quirk)
816 config1 |= NFC_V1_V2_CONFIG1_INT_MSK; 925 config1 |= NFC_V1_V2_CONFIG1_INT_MSK;
817 926
818 if (nfc_is_v21() && mtd->writesize) { 927 if (mtd->writesize) {
819 uint16_t pages_per_block = mtd->erasesize / mtd->writesize; 928 uint16_t pages_per_block = mtd->erasesize / mtd->writesize;
820 929
821 host->eccsize = get_eccsize(mtd); 930 host->eccsize = get_eccsize(mtd);
@@ -834,20 +943,14 @@ static void preset_v1_v2(struct mtd_info *mtd)
834 writew(0x2, NFC_V1_V2_CONFIG); 943 writew(0x2, NFC_V1_V2_CONFIG);
835 944
836 /* Blocks to be unlocked */ 945 /* Blocks to be unlocked */
837 if (nfc_is_v21()) { 946 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR0);
838 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR0); 947 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR1);
839 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR1); 948 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR2);
840 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR2); 949 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR3);
841 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR3); 950 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR0);
842 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR0); 951 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR1);
843 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR1); 952 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR2);
844 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR2); 953 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR3);
845 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR3);
846 } else if (nfc_is_v1()) {
847 writew(0x0, NFC_V1_UNLOCKSTART_BLKADDR);
848 writew(0xffff, NFC_V1_UNLOCKEND_BLKADDR);
849 } else
850 BUG();
851 954
852 /* Unlock Block Command for given address range */ 955 /* Unlock Block Command for given address range */
853 writew(0x4, NFC_V1_V2_WRPROT); 956 writew(0x4, NFC_V1_V2_WRPROT);
@@ -937,15 +1040,15 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
937 /* Command pre-processing step */ 1040 /* Command pre-processing step */
938 switch (command) { 1041 switch (command) {
939 case NAND_CMD_RESET: 1042 case NAND_CMD_RESET:
940 host->preset(mtd); 1043 host->devtype_data->preset(mtd);
941 host->send_cmd(host, command, false); 1044 host->devtype_data->send_cmd(host, command, false);
942 break; 1045 break;
943 1046
944 case NAND_CMD_STATUS: 1047 case NAND_CMD_STATUS:
945 host->buf_start = 0; 1048 host->buf_start = 0;
946 host->status_request = true; 1049 host->status_request = true;
947 1050
948 host->send_cmd(host, command, true); 1051 host->devtype_data->send_cmd(host, command, true);
949 mxc_do_addr_cycle(mtd, column, page_addr); 1052 mxc_do_addr_cycle(mtd, column, page_addr);
950 break; 1053 break;
951 1054
@@ -958,15 +1061,16 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
958 1061
959 command = NAND_CMD_READ0; /* only READ0 is valid */ 1062 command = NAND_CMD_READ0; /* only READ0 is valid */
960 1063
961 host->send_cmd(host, command, false); 1064 host->devtype_data->send_cmd(host, command, false);
962 mxc_do_addr_cycle(mtd, column, page_addr); 1065 mxc_do_addr_cycle(mtd, column, page_addr);
963 1066
964 if (mtd->writesize > 512) 1067 if (mtd->writesize > 512)
965 host->send_cmd(host, NAND_CMD_READSTART, true); 1068 host->devtype_data->send_cmd(host,
1069 NAND_CMD_READSTART, true);
966 1070
967 host->send_page(mtd, NFC_OUTPUT); 1071 host->devtype_data->send_page(mtd, NFC_OUTPUT);
968 1072
969 memcpy(host->data_buf, host->main_area0, mtd->writesize); 1073 memcpy_fromio(host->data_buf, host->main_area0, mtd->writesize);
970 copy_spare(mtd, true); 1074 copy_spare(mtd, true);
971 break; 1075 break;
972 1076
@@ -977,28 +1081,28 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
977 1081
978 host->buf_start = column; 1082 host->buf_start = column;
979 1083
980 host->send_cmd(host, command, false); 1084 host->devtype_data->send_cmd(host, command, false);
981 mxc_do_addr_cycle(mtd, column, page_addr); 1085 mxc_do_addr_cycle(mtd, column, page_addr);
982 break; 1086 break;
983 1087
984 case NAND_CMD_PAGEPROG: 1088 case NAND_CMD_PAGEPROG:
985 memcpy(host->main_area0, host->data_buf, mtd->writesize); 1089 memcpy_toio(host->main_area0, host->data_buf, mtd->writesize);
986 copy_spare(mtd, false); 1090 copy_spare(mtd, false);
987 host->send_page(mtd, NFC_INPUT); 1091 host->devtype_data->send_page(mtd, NFC_INPUT);
988 host->send_cmd(host, command, true); 1092 host->devtype_data->send_cmd(host, command, true);
989 mxc_do_addr_cycle(mtd, column, page_addr); 1093 mxc_do_addr_cycle(mtd, column, page_addr);
990 break; 1094 break;
991 1095
992 case NAND_CMD_READID: 1096 case NAND_CMD_READID:
993 host->send_cmd(host, command, true); 1097 host->devtype_data->send_cmd(host, command, true);
994 mxc_do_addr_cycle(mtd, column, page_addr); 1098 mxc_do_addr_cycle(mtd, column, page_addr);
995 host->send_read_id(host); 1099 host->devtype_data->send_read_id(host);
996 host->buf_start = column; 1100 host->buf_start = column;
997 break; 1101 break;
998 1102
999 case NAND_CMD_ERASE1: 1103 case NAND_CMD_ERASE1:
1000 case NAND_CMD_ERASE2: 1104 case NAND_CMD_ERASE2:
1001 host->send_cmd(host, command, false); 1105 host->devtype_data->send_cmd(host, command, false);
1002 mxc_do_addr_cycle(mtd, column, page_addr); 1106 mxc_do_addr_cycle(mtd, column, page_addr);
1003 1107
1004 break; 1108 break;
@@ -1032,15 +1136,191 @@ static struct nand_bbt_descr bbt_mirror_descr = {
1032 .pattern = mirror_pattern, 1136 .pattern = mirror_pattern,
1033}; 1137};
1034 1138
1139/* v1 + irqpending_quirk: i.MX21 */
1140static const struct mxc_nand_devtype_data imx21_nand_devtype_data = {
1141 .preset = preset_v1,
1142 .send_cmd = send_cmd_v1_v2,
1143 .send_addr = send_addr_v1_v2,
1144 .send_page = send_page_v1,
1145 .send_read_id = send_read_id_v1_v2,
1146 .get_dev_status = get_dev_status_v1_v2,
1147 .check_int = check_int_v1_v2,
1148 .irq_control = irq_control_v1_v2,
1149 .get_ecc_status = get_ecc_status_v1,
1150 .ecclayout_512 = &nandv1_hw_eccoob_smallpage,
1151 .ecclayout_2k = &nandv1_hw_eccoob_largepage,
1152 .ecclayout_4k = &nandv1_hw_eccoob_smallpage, /* XXX: needs fix */
1153 .select_chip = mxc_nand_select_chip_v1_v3,
1154 .correct_data = mxc_nand_correct_data_v1,
1155 .irqpending_quirk = 1,
1156 .needs_ip = 0,
1157 .regs_offset = 0xe00,
1158 .spare0_offset = 0x800,
1159 .spare_len = 16,
1160 .eccbytes = 3,
1161 .eccsize = 1,
1162};
1163
1164/* v1 + !irqpending_quirk: i.MX27, i.MX31 */
1165static const struct mxc_nand_devtype_data imx27_nand_devtype_data = {
1166 .preset = preset_v1,
1167 .send_cmd = send_cmd_v1_v2,
1168 .send_addr = send_addr_v1_v2,
1169 .send_page = send_page_v1,
1170 .send_read_id = send_read_id_v1_v2,
1171 .get_dev_status = get_dev_status_v1_v2,
1172 .check_int = check_int_v1_v2,
1173 .irq_control = irq_control_v1_v2,
1174 .get_ecc_status = get_ecc_status_v1,
1175 .ecclayout_512 = &nandv1_hw_eccoob_smallpage,
1176 .ecclayout_2k = &nandv1_hw_eccoob_largepage,
1177 .ecclayout_4k = &nandv1_hw_eccoob_smallpage, /* XXX: needs fix */
1178 .select_chip = mxc_nand_select_chip_v1_v3,
1179 .correct_data = mxc_nand_correct_data_v1,
1180 .irqpending_quirk = 0,
1181 .needs_ip = 0,
1182 .regs_offset = 0xe00,
1183 .spare0_offset = 0x800,
1184 .axi_offset = 0,
1185 .spare_len = 16,
1186 .eccbytes = 3,
1187 .eccsize = 1,
1188};
1189
1190/* v21: i.MX25, i.MX35 */
1191static const struct mxc_nand_devtype_data imx25_nand_devtype_data = {
1192 .preset = preset_v2,
1193 .send_cmd = send_cmd_v1_v2,
1194 .send_addr = send_addr_v1_v2,
1195 .send_page = send_page_v2,
1196 .send_read_id = send_read_id_v1_v2,
1197 .get_dev_status = get_dev_status_v1_v2,
1198 .check_int = check_int_v1_v2,
1199 .irq_control = irq_control_v1_v2,
1200 .get_ecc_status = get_ecc_status_v2,
1201 .ecclayout_512 = &nandv2_hw_eccoob_smallpage,
1202 .ecclayout_2k = &nandv2_hw_eccoob_largepage,
1203 .ecclayout_4k = &nandv2_hw_eccoob_4k,
1204 .select_chip = mxc_nand_select_chip_v2,
1205 .correct_data = mxc_nand_correct_data_v2_v3,
1206 .irqpending_quirk = 0,
1207 .needs_ip = 0,
1208 .regs_offset = 0x1e00,
1209 .spare0_offset = 0x1000,
1210 .axi_offset = 0,
1211 .spare_len = 64,
1212 .eccbytes = 9,
1213 .eccsize = 0,
1214};
1215
1216/* v3: i.MX51, i.MX53 */
1217static const struct mxc_nand_devtype_data imx51_nand_devtype_data = {
1218 .preset = preset_v3,
1219 .send_cmd = send_cmd_v3,
1220 .send_addr = send_addr_v3,
1221 .send_page = send_page_v3,
1222 .send_read_id = send_read_id_v3,
1223 .get_dev_status = get_dev_status_v3,
1224 .check_int = check_int_v3,
1225 .irq_control = irq_control_v3,
1226 .get_ecc_status = get_ecc_status_v3,
1227 .ecclayout_512 = &nandv2_hw_eccoob_smallpage,
1228 .ecclayout_2k = &nandv2_hw_eccoob_largepage,
1229 .ecclayout_4k = &nandv2_hw_eccoob_smallpage, /* XXX: needs fix */
1230 .select_chip = mxc_nand_select_chip_v1_v3,
1231 .correct_data = mxc_nand_correct_data_v2_v3,
1232 .irqpending_quirk = 0,
1233 .needs_ip = 1,
1234 .regs_offset = 0,
1235 .spare0_offset = 0x1000,
1236 .axi_offset = 0x1e00,
1237 .spare_len = 64,
1238 .eccbytes = 0,
1239 .eccsize = 0,
1240};
1241
1242#ifdef CONFIG_OF_MTD
1243static const struct of_device_id mxcnd_dt_ids[] = {
1244 {
1245 .compatible = "fsl,imx21-nand",
1246 .data = &imx21_nand_devtype_data,
1247 }, {
1248 .compatible = "fsl,imx27-nand",
1249 .data = &imx27_nand_devtype_data,
1250 }, {
1251 .compatible = "fsl,imx25-nand",
1252 .data = &imx25_nand_devtype_data,
1253 }, {
1254 .compatible = "fsl,imx51-nand",
1255 .data = &imx51_nand_devtype_data,
1256 },
1257 { /* sentinel */ }
1258};
1259
1260static int __init mxcnd_probe_dt(struct mxc_nand_host *host)
1261{
1262 struct device_node *np = host->dev->of_node;
1263 struct mxc_nand_platform_data *pdata = &host->pdata;
1264 const struct of_device_id *of_id =
1265 of_match_device(mxcnd_dt_ids, host->dev);
1266 int buswidth;
1267
1268 if (!np)
1269 return 1;
1270
1271 if (of_get_nand_ecc_mode(np) >= 0)
1272 pdata->hw_ecc = 1;
1273
1274 pdata->flash_bbt = of_get_nand_on_flash_bbt(np);
1275
1276 buswidth = of_get_nand_bus_width(np);
1277 if (buswidth < 0)
1278 return buswidth;
1279
1280 pdata->width = buswidth / 8;
1281
1282 host->devtype_data = of_id->data;
1283
1284 return 0;
1285}
1286#else
1287static int __init mxcnd_probe_dt(struct mxc_nand_host *host)
1288{
1289 return 1;
1290}
1291#endif
1292
1293static int __init mxcnd_probe_pdata(struct mxc_nand_host *host)
1294{
1295 struct mxc_nand_platform_data *pdata = host->dev->platform_data;
1296
1297 if (!pdata)
1298 return -ENODEV;
1299
1300 host->pdata = *pdata;
1301
1302 if (nfc_is_v1()) {
1303 if (cpu_is_mx21())
1304 host->devtype_data = &imx21_nand_devtype_data;
1305 else
1306 host->devtype_data = &imx27_nand_devtype_data;
1307 } else if (nfc_is_v21()) {
1308 host->devtype_data = &imx25_nand_devtype_data;
1309 } else if (nfc_is_v3_2()) {
1310 host->devtype_data = &imx51_nand_devtype_data;
1311 } else
1312 BUG();
1313
1314 return 0;
1315}
1316
1035static int __init mxcnd_probe(struct platform_device *pdev) 1317static int __init mxcnd_probe(struct platform_device *pdev)
1036{ 1318{
1037 struct nand_chip *this; 1319 struct nand_chip *this;
1038 struct mtd_info *mtd; 1320 struct mtd_info *mtd;
1039 struct mxc_nand_platform_data *pdata = pdev->dev.platform_data;
1040 struct mxc_nand_host *host; 1321 struct mxc_nand_host *host;
1041 struct resource *res; 1322 struct resource *res;
1042 int err = 0; 1323 int err = 0;
1043 struct nand_ecclayout *oob_smallpage, *oob_largepage;
1044 1324
1045 /* Allocate memory for MTD device structure and private data */ 1325 /* Allocate memory for MTD device structure and private data */
1046 host = kzalloc(sizeof(struct mxc_nand_host) + NAND_MAX_PAGESIZE + 1326 host = kzalloc(sizeof(struct mxc_nand_host) + NAND_MAX_PAGESIZE +
@@ -1065,7 +1345,6 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1065 this->priv = host; 1345 this->priv = host;
1066 this->dev_ready = mxc_nand_dev_ready; 1346 this->dev_ready = mxc_nand_dev_ready;
1067 this->cmdfunc = mxc_nand_command; 1347 this->cmdfunc = mxc_nand_command;
1068 this->select_chip = mxc_nand_select_chip;
1069 this->read_byte = mxc_nand_read_byte; 1348 this->read_byte = mxc_nand_read_byte;
1070 this->read_word = mxc_nand_read_word; 1349 this->read_word = mxc_nand_read_word;
1071 this->write_buf = mxc_nand_write_buf; 1350 this->write_buf = mxc_nand_write_buf;
@@ -1095,36 +1374,26 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1095 1374
1096 host->main_area0 = host->base; 1375 host->main_area0 = host->base;
1097 1376
1098 if (nfc_is_v1() || nfc_is_v21()) { 1377 err = mxcnd_probe_dt(host);
1099 host->preset = preset_v1_v2; 1378 if (err > 0)
1100 host->send_cmd = send_cmd_v1_v2; 1379 err = mxcnd_probe_pdata(host);
1101 host->send_addr = send_addr_v1_v2; 1380 if (err < 0)
1102 host->send_page = send_page_v1_v2; 1381 goto eirq;
1103 host->send_read_id = send_read_id_v1_v2;
1104 host->get_dev_status = get_dev_status_v1_v2;
1105 host->check_int = check_int_v1_v2;
1106 if (cpu_is_mx21())
1107 host->irq_control = irq_control_mx21;
1108 else
1109 host->irq_control = irq_control_v1_v2;
1110 }
1111 1382
1112 if (nfc_is_v21()) { 1383 if (host->devtype_data->regs_offset)
1113 host->regs = host->base + 0x1e00; 1384 host->regs = host->base + host->devtype_data->regs_offset;
1114 host->spare0 = host->base + 0x1000; 1385 host->spare0 = host->base + host->devtype_data->spare0_offset;
1115 host->spare_len = 64; 1386 if (host->devtype_data->axi_offset)
1116 oob_smallpage = &nandv2_hw_eccoob_smallpage; 1387 host->regs_axi = host->base + host->devtype_data->axi_offset;
1117 oob_largepage = &nandv2_hw_eccoob_largepage; 1388
1118 this->ecc.bytes = 9; 1389 this->ecc.bytes = host->devtype_data->eccbytes;
1119 } else if (nfc_is_v1()) { 1390 host->eccsize = host->devtype_data->eccsize;
1120 host->regs = host->base + 0xe00; 1391
1121 host->spare0 = host->base + 0x800; 1392 this->select_chip = host->devtype_data->select_chip;
1122 host->spare_len = 16; 1393 this->ecc.size = 512;
1123 oob_smallpage = &nandv1_hw_eccoob_smallpage; 1394 this->ecc.layout = host->devtype_data->ecclayout_512;
1124 oob_largepage = &nandv1_hw_eccoob_largepage; 1395
1125 this->ecc.bytes = 3; 1396 if (host->devtype_data->needs_ip) {
1126 host->eccsize = 1;
1127 } else if (nfc_is_v3_2()) {
1128 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 1397 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1129 if (!res) { 1398 if (!res) {
1130 err = -ENODEV; 1399 err = -ENODEV;
@@ -1135,42 +1404,22 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1135 err = -ENOMEM; 1404 err = -ENOMEM;
1136 goto eirq; 1405 goto eirq;
1137 } 1406 }
1138 host->regs_axi = host->base + 0x1e00; 1407 }
1139 host->spare0 = host->base + 0x1000;
1140 host->spare_len = 64;
1141 host->preset = preset_v3;
1142 host->send_cmd = send_cmd_v3;
1143 host->send_addr = send_addr_v3;
1144 host->send_page = send_page_v3;
1145 host->send_read_id = send_read_id_v3;
1146 host->check_int = check_int_v3;
1147 host->get_dev_status = get_dev_status_v3;
1148 host->irq_control = irq_control_v3;
1149 oob_smallpage = &nandv2_hw_eccoob_smallpage;
1150 oob_largepage = &nandv2_hw_eccoob_largepage;
1151 } else
1152 BUG();
1153
1154 this->ecc.size = 512;
1155 this->ecc.layout = oob_smallpage;
1156 1408
1157 if (pdata->hw_ecc) { 1409 if (host->pdata.hw_ecc) {
1158 this->ecc.calculate = mxc_nand_calculate_ecc; 1410 this->ecc.calculate = mxc_nand_calculate_ecc;
1159 this->ecc.hwctl = mxc_nand_enable_hwecc; 1411 this->ecc.hwctl = mxc_nand_enable_hwecc;
1160 if (nfc_is_v1()) 1412 this->ecc.correct = host->devtype_data->correct_data;
1161 this->ecc.correct = mxc_nand_correct_data_v1;
1162 else
1163 this->ecc.correct = mxc_nand_correct_data_v2_v3;
1164 this->ecc.mode = NAND_ECC_HW; 1413 this->ecc.mode = NAND_ECC_HW;
1165 } else { 1414 } else {
1166 this->ecc.mode = NAND_ECC_SOFT; 1415 this->ecc.mode = NAND_ECC_SOFT;
1167 } 1416 }
1168 1417
1169 /* NAND bus width determines access funtions used by upper layer */ 1418 /* NAND bus width determines access functions used by upper layer */
1170 if (pdata->width == 2) 1419 if (host->pdata.width == 2)
1171 this->options |= NAND_BUSWIDTH_16; 1420 this->options |= NAND_BUSWIDTH_16;
1172 1421
1173 if (pdata->flash_bbt) { 1422 if (host->pdata.flash_bbt) {
1174 this->bbt_td = &bbt_main_descr; 1423 this->bbt_td = &bbt_main_descr;
1175 this->bbt_md = &bbt_mirror_descr; 1424 this->bbt_md = &bbt_mirror_descr;
1176 /* update flash based bbt */ 1425 /* update flash based bbt */
@@ -1182,28 +1431,25 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1182 host->irq = platform_get_irq(pdev, 0); 1431 host->irq = platform_get_irq(pdev, 0);
1183 1432
1184 /* 1433 /*
1185 * mask the interrupt. For i.MX21 explicitely call 1434 * Use host->devtype_data->irq_control() here instead of irq_control()
1186 * irq_control_v1_v2 to use the mask bit. We can't call 1435 * because we must not disable_irq_nosync without having requested the
1187 * disable_irq_nosync() for an interrupt we do not own yet. 1436 * irq.
1188 */ 1437 */
1189 if (cpu_is_mx21()) 1438 host->devtype_data->irq_control(host, 0);
1190 irq_control_v1_v2(host, 0);
1191 else
1192 host->irq_control(host, 0);
1193 1439
1194 err = request_irq(host->irq, mxc_nfc_irq, IRQF_DISABLED, DRIVER_NAME, host); 1440 err = request_irq(host->irq, mxc_nfc_irq, IRQF_DISABLED, DRIVER_NAME, host);
1195 if (err) 1441 if (err)
1196 goto eirq; 1442 goto eirq;
1197 1443
1198 host->irq_control(host, 0);
1199
1200 /* 1444 /*
1201 * Now that the interrupt is disabled make sure the interrupt 1445 * Now that we "own" the interrupt make sure the interrupt mask bit is
1202 * mask bit is cleared on i.MX21. Otherwise we can't read 1446 * cleared on i.MX21. Otherwise we can't read the interrupt status bit
1203 * the interrupt status bit on this machine. 1447 * on this machine.
1204 */ 1448 */
1205 if (cpu_is_mx21()) 1449 if (host->devtype_data->irqpending_quirk) {
1206 irq_control_v1_v2(host, 1); 1450 disable_irq_nosync(host->irq);
1451 host->devtype_data->irq_control(host, 1);
1452 }
1207 1453
1208 /* first scan to find the device and get the page size */ 1454 /* first scan to find the device and get the page size */
1209 if (nand_scan_ident(mtd, nfc_is_v21() ? 4 : 1, NULL)) { 1455 if (nand_scan_ident(mtd, nfc_is_v21() ? 4 : 1, NULL)) {
@@ -1212,18 +1458,12 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1212 } 1458 }
1213 1459
1214 /* Call preset again, with correct writesize this time */ 1460 /* Call preset again, with correct writesize this time */
1215 host->preset(mtd); 1461 host->devtype_data->preset(mtd);
1216 1462
1217 if (mtd->writesize == 2048) 1463 if (mtd->writesize == 2048)
1218 this->ecc.layout = oob_largepage; 1464 this->ecc.layout = host->devtype_data->ecclayout_2k;
1219 if (nfc_is_v21() && mtd->writesize == 4096) 1465 else if (mtd->writesize == 4096)
1220 this->ecc.layout = &nandv2_hw_eccoob_4k; 1466 this->ecc.layout = host->devtype_data->ecclayout_4k;
1221
1222 /* second phase scan */
1223 if (nand_scan_tail(mtd)) {
1224 err = -ENXIO;
1225 goto escan;
1226 }
1227 1467
1228 if (this->ecc.mode == NAND_ECC_HW) { 1468 if (this->ecc.mode == NAND_ECC_HW) {
1229 if (nfc_is_v1()) 1469 if (nfc_is_v1())
@@ -1232,9 +1472,19 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1232 this->ecc.strength = (host->eccsize == 4) ? 4 : 8; 1472 this->ecc.strength = (host->eccsize == 4) ? 4 : 8;
1233 } 1473 }
1234 1474
1475 /* second phase scan */
1476 if (nand_scan_tail(mtd)) {
1477 err = -ENXIO;
1478 goto escan;
1479 }
1480
1235 /* Register the partitions */ 1481 /* Register the partitions */
1236 mtd_device_parse_register(mtd, part_probes, NULL, pdata->parts, 1482 mtd_device_parse_register(mtd, part_probes,
1237 pdata->nr_parts); 1483 &(struct mtd_part_parser_data){
1484 .of_node = pdev->dev.of_node,
1485 },
1486 host->pdata.parts,
1487 host->pdata.nr_parts);
1238 1488
1239 platform_set_drvdata(pdev, host); 1489 platform_set_drvdata(pdev, host);
1240 1490
@@ -1275,6 +1525,8 @@ static int __devexit mxcnd_remove(struct platform_device *pdev)
1275static struct platform_driver mxcnd_driver = { 1525static struct platform_driver mxcnd_driver = {
1276 .driver = { 1526 .driver = {
1277 .name = DRIVER_NAME, 1527 .name = DRIVER_NAME,
1528 .owner = THIS_MODULE,
1529 .of_match_table = of_match_ptr(mxcnd_dt_ids),
1278 }, 1530 },
1279 .remove = __devexit_p(mxcnd_remove), 1531 .remove = __devexit_p(mxcnd_remove),
1280}; 1532};
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 47b19c0bb070..d47586cf64ce 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1066,15 +1066,17 @@ EXPORT_SYMBOL(nand_lock);
1066 * @mtd: mtd info structure 1066 * @mtd: mtd info structure
1067 * @chip: nand chip info structure 1067 * @chip: nand chip info structure
1068 * @buf: buffer to store read data 1068 * @buf: buffer to store read data
1069 * @oob_required: caller requires OOB data read to chip->oob_poi
1069 * @page: page number to read 1070 * @page: page number to read
1070 * 1071 *
1071 * Not for syndrome calculating ECC controllers, which use a special oob layout. 1072 * Not for syndrome calculating ECC controllers, which use a special oob layout.
1072 */ 1073 */
1073static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 1074static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1074 uint8_t *buf, int page) 1075 uint8_t *buf, int oob_required, int page)
1075{ 1076{
1076 chip->read_buf(mtd, buf, mtd->writesize); 1077 chip->read_buf(mtd, buf, mtd->writesize);
1077 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); 1078 if (oob_required)
1079 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
1078 return 0; 1080 return 0;
1079} 1081}
1080 1082
@@ -1083,13 +1085,14 @@ static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1083 * @mtd: mtd info structure 1085 * @mtd: mtd info structure
1084 * @chip: nand chip info structure 1086 * @chip: nand chip info structure
1085 * @buf: buffer to store read data 1087 * @buf: buffer to store read data
1088 * @oob_required: caller requires OOB data read to chip->oob_poi
1086 * @page: page number to read 1089 * @page: page number to read
1087 * 1090 *
1088 * We need a special oob layout and handling even when OOB isn't used. 1091 * We need a special oob layout and handling even when OOB isn't used.
1089 */ 1092 */
1090static int nand_read_page_raw_syndrome(struct mtd_info *mtd, 1093static int nand_read_page_raw_syndrome(struct mtd_info *mtd,
1091 struct nand_chip *chip, 1094 struct nand_chip *chip, uint8_t *buf,
1092 uint8_t *buf, int page) 1095 int oob_required, int page)
1093{ 1096{
1094 int eccsize = chip->ecc.size; 1097 int eccsize = chip->ecc.size;
1095 int eccbytes = chip->ecc.bytes; 1098 int eccbytes = chip->ecc.bytes;
@@ -1126,10 +1129,11 @@ static int nand_read_page_raw_syndrome(struct mtd_info *mtd,
1126 * @mtd: mtd info structure 1129 * @mtd: mtd info structure
1127 * @chip: nand chip info structure 1130 * @chip: nand chip info structure
1128 * @buf: buffer to store read data 1131 * @buf: buffer to store read data
1132 * @oob_required: caller requires OOB data read to chip->oob_poi
1129 * @page: page number to read 1133 * @page: page number to read
1130 */ 1134 */
1131static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, 1135static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1132 uint8_t *buf, int page) 1136 uint8_t *buf, int oob_required, int page)
1133{ 1137{
1134 int i, eccsize = chip->ecc.size; 1138 int i, eccsize = chip->ecc.size;
1135 int eccbytes = chip->ecc.bytes; 1139 int eccbytes = chip->ecc.bytes;
@@ -1138,8 +1142,9 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1138 uint8_t *ecc_calc = chip->buffers->ecccalc; 1142 uint8_t *ecc_calc = chip->buffers->ecccalc;
1139 uint8_t *ecc_code = chip->buffers->ecccode; 1143 uint8_t *ecc_code = chip->buffers->ecccode;
1140 uint32_t *eccpos = chip->ecc.layout->eccpos; 1144 uint32_t *eccpos = chip->ecc.layout->eccpos;
1145 unsigned int max_bitflips = 0;
1141 1146
1142 chip->ecc.read_page_raw(mtd, chip, buf, page); 1147 chip->ecc.read_page_raw(mtd, chip, buf, 1, page);
1143 1148
1144 for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) 1149 for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize)
1145 chip->ecc.calculate(mtd, p, &ecc_calc[i]); 1150 chip->ecc.calculate(mtd, p, &ecc_calc[i]);
@@ -1154,12 +1159,14 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1154 int stat; 1159 int stat;
1155 1160
1156 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); 1161 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
1157 if (stat < 0) 1162 if (stat < 0) {
1158 mtd->ecc_stats.failed++; 1163 mtd->ecc_stats.failed++;
1159 else 1164 } else {
1160 mtd->ecc_stats.corrected += stat; 1165 mtd->ecc_stats.corrected += stat;
1166 max_bitflips = max_t(unsigned int, max_bitflips, stat);
1167 }
1161 } 1168 }
1162 return 0; 1169 return max_bitflips;
1163} 1170}
1164 1171
1165/** 1172/**
@@ -1180,6 +1187,7 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
1180 int datafrag_len, eccfrag_len, aligned_len, aligned_pos; 1187 int datafrag_len, eccfrag_len, aligned_len, aligned_pos;
1181 int busw = (chip->options & NAND_BUSWIDTH_16) ? 2 : 1; 1188 int busw = (chip->options & NAND_BUSWIDTH_16) ? 2 : 1;
1182 int index = 0; 1189 int index = 0;
1190 unsigned int max_bitflips = 0;
1183 1191
1184 /* Column address within the page aligned to ECC size (256bytes) */ 1192 /* Column address within the page aligned to ECC size (256bytes) */
1185 start_step = data_offs / chip->ecc.size; 1193 start_step = data_offs / chip->ecc.size;
@@ -1244,12 +1252,14 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
1244 1252
1245 stat = chip->ecc.correct(mtd, p, 1253 stat = chip->ecc.correct(mtd, p,
1246 &chip->buffers->ecccode[i], &chip->buffers->ecccalc[i]); 1254 &chip->buffers->ecccode[i], &chip->buffers->ecccalc[i]);
1247 if (stat < 0) 1255 if (stat < 0) {
1248 mtd->ecc_stats.failed++; 1256 mtd->ecc_stats.failed++;
1249 else 1257 } else {
1250 mtd->ecc_stats.corrected += stat; 1258 mtd->ecc_stats.corrected += stat;
1259 max_bitflips = max_t(unsigned int, max_bitflips, stat);
1260 }
1251 } 1261 }
1252 return 0; 1262 return max_bitflips;
1253} 1263}
1254 1264
1255/** 1265/**
@@ -1257,12 +1267,13 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
1257 * @mtd: mtd info structure 1267 * @mtd: mtd info structure
1258 * @chip: nand chip info structure 1268 * @chip: nand chip info structure
1259 * @buf: buffer to store read data 1269 * @buf: buffer to store read data
1270 * @oob_required: caller requires OOB data read to chip->oob_poi
1260 * @page: page number to read 1271 * @page: page number to read
1261 * 1272 *
1262 * Not for syndrome calculating ECC controllers which need a special oob layout. 1273 * Not for syndrome calculating ECC controllers which need a special oob layout.
1263 */ 1274 */
1264static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, 1275static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1265 uint8_t *buf, int page) 1276 uint8_t *buf, int oob_required, int page)
1266{ 1277{
1267 int i, eccsize = chip->ecc.size; 1278 int i, eccsize = chip->ecc.size;
1268 int eccbytes = chip->ecc.bytes; 1279 int eccbytes = chip->ecc.bytes;
@@ -1271,6 +1282,7 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1271 uint8_t *ecc_calc = chip->buffers->ecccalc; 1282 uint8_t *ecc_calc = chip->buffers->ecccalc;
1272 uint8_t *ecc_code = chip->buffers->ecccode; 1283 uint8_t *ecc_code = chip->buffers->ecccode;
1273 uint32_t *eccpos = chip->ecc.layout->eccpos; 1284 uint32_t *eccpos = chip->ecc.layout->eccpos;
1285 unsigned int max_bitflips = 0;
1274 1286
1275 for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { 1287 for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
1276 chip->ecc.hwctl(mtd, NAND_ECC_READ); 1288 chip->ecc.hwctl(mtd, NAND_ECC_READ);
@@ -1289,12 +1301,14 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1289 int stat; 1301 int stat;
1290 1302
1291 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); 1303 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
1292 if (stat < 0) 1304 if (stat < 0) {
1293 mtd->ecc_stats.failed++; 1305 mtd->ecc_stats.failed++;
1294 else 1306 } else {
1295 mtd->ecc_stats.corrected += stat; 1307 mtd->ecc_stats.corrected += stat;
1308 max_bitflips = max_t(unsigned int, max_bitflips, stat);
1309 }
1296 } 1310 }
1297 return 0; 1311 return max_bitflips;
1298} 1312}
1299 1313
1300/** 1314/**
@@ -1302,6 +1316,7 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1302 * @mtd: mtd info structure 1316 * @mtd: mtd info structure
1303 * @chip: nand chip info structure 1317 * @chip: nand chip info structure
1304 * @buf: buffer to store read data 1318 * @buf: buffer to store read data
1319 * @oob_required: caller requires OOB data read to chip->oob_poi
1305 * @page: page number to read 1320 * @page: page number to read
1306 * 1321 *
1307 * Hardware ECC for large page chips, require OOB to be read first. For this 1322 * Hardware ECC for large page chips, require OOB to be read first. For this
@@ -1311,7 +1326,7 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1311 * the data area, by overwriting the NAND manufacturer bad block markings. 1326 * the data area, by overwriting the NAND manufacturer bad block markings.
1312 */ 1327 */
1313static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd, 1328static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
1314 struct nand_chip *chip, uint8_t *buf, int page) 1329 struct nand_chip *chip, uint8_t *buf, int oob_required, int page)
1315{ 1330{
1316 int i, eccsize = chip->ecc.size; 1331 int i, eccsize = chip->ecc.size;
1317 int eccbytes = chip->ecc.bytes; 1332 int eccbytes = chip->ecc.bytes;
@@ -1320,6 +1335,7 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
1320 uint8_t *ecc_code = chip->buffers->ecccode; 1335 uint8_t *ecc_code = chip->buffers->ecccode;
1321 uint32_t *eccpos = chip->ecc.layout->eccpos; 1336 uint32_t *eccpos = chip->ecc.layout->eccpos;
1322 uint8_t *ecc_calc = chip->buffers->ecccalc; 1337 uint8_t *ecc_calc = chip->buffers->ecccalc;
1338 unsigned int max_bitflips = 0;
1323 1339
1324 /* Read the OOB area first */ 1340 /* Read the OOB area first */
1325 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page); 1341 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
@@ -1337,12 +1353,14 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
1337 chip->ecc.calculate(mtd, p, &ecc_calc[i]); 1353 chip->ecc.calculate(mtd, p, &ecc_calc[i]);
1338 1354
1339 stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL); 1355 stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL);
1340 if (stat < 0) 1356 if (stat < 0) {
1341 mtd->ecc_stats.failed++; 1357 mtd->ecc_stats.failed++;
1342 else 1358 } else {
1343 mtd->ecc_stats.corrected += stat; 1359 mtd->ecc_stats.corrected += stat;
1360 max_bitflips = max_t(unsigned int, max_bitflips, stat);
1361 }
1344 } 1362 }
1345 return 0; 1363 return max_bitflips;
1346} 1364}
1347 1365
1348/** 1366/**
@@ -1350,19 +1368,21 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
1350 * @mtd: mtd info structure 1368 * @mtd: mtd info structure
1351 * @chip: nand chip info structure 1369 * @chip: nand chip info structure
1352 * @buf: buffer to store read data 1370 * @buf: buffer to store read data
1371 * @oob_required: caller requires OOB data read to chip->oob_poi
1353 * @page: page number to read 1372 * @page: page number to read
1354 * 1373 *
1355 * The hw generator calculates the error syndrome automatically. Therefore we 1374 * The hw generator calculates the error syndrome automatically. Therefore we
1356 * need a special oob layout and handling. 1375 * need a special oob layout and handling.
1357 */ 1376 */
1358static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip, 1377static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
1359 uint8_t *buf, int page) 1378 uint8_t *buf, int oob_required, int page)
1360{ 1379{
1361 int i, eccsize = chip->ecc.size; 1380 int i, eccsize = chip->ecc.size;
1362 int eccbytes = chip->ecc.bytes; 1381 int eccbytes = chip->ecc.bytes;
1363 int eccsteps = chip->ecc.steps; 1382 int eccsteps = chip->ecc.steps;
1364 uint8_t *p = buf; 1383 uint8_t *p = buf;
1365 uint8_t *oob = chip->oob_poi; 1384 uint8_t *oob = chip->oob_poi;
1385 unsigned int max_bitflips = 0;
1366 1386
1367 for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { 1387 for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
1368 int stat; 1388 int stat;
@@ -1379,10 +1399,12 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
1379 chip->read_buf(mtd, oob, eccbytes); 1399 chip->read_buf(mtd, oob, eccbytes);
1380 stat = chip->ecc.correct(mtd, p, oob, NULL); 1400 stat = chip->ecc.correct(mtd, p, oob, NULL);
1381 1401
1382 if (stat < 0) 1402 if (stat < 0) {
1383 mtd->ecc_stats.failed++; 1403 mtd->ecc_stats.failed++;
1384 else 1404 } else {
1385 mtd->ecc_stats.corrected += stat; 1405 mtd->ecc_stats.corrected += stat;
1406 max_bitflips = max_t(unsigned int, max_bitflips, stat);
1407 }
1386 1408
1387 oob += eccbytes; 1409 oob += eccbytes;
1388 1410
@@ -1397,7 +1419,7 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
1397 if (i) 1419 if (i)
1398 chip->read_buf(mtd, oob, i); 1420 chip->read_buf(mtd, oob, i);
1399 1421
1400 return 0; 1422 return max_bitflips;
1401} 1423}
1402 1424
1403/** 1425/**
@@ -1459,11 +1481,9 @@ static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob,
1459static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, 1481static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1460 struct mtd_oob_ops *ops) 1482 struct mtd_oob_ops *ops)
1461{ 1483{
1462 int chipnr, page, realpage, col, bytes, aligned; 1484 int chipnr, page, realpage, col, bytes, aligned, oob_required;
1463 struct nand_chip *chip = mtd->priv; 1485 struct nand_chip *chip = mtd->priv;
1464 struct mtd_ecc_stats stats; 1486 struct mtd_ecc_stats stats;
1465 int blkcheck = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1;
1466 int sndcmd = 1;
1467 int ret = 0; 1487 int ret = 0;
1468 uint32_t readlen = ops->len; 1488 uint32_t readlen = ops->len;
1469 uint32_t oobreadlen = ops->ooblen; 1489 uint32_t oobreadlen = ops->ooblen;
@@ -1471,6 +1491,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1471 mtd->oobavail : mtd->oobsize; 1491 mtd->oobavail : mtd->oobsize;
1472 1492
1473 uint8_t *bufpoi, *oob, *buf; 1493 uint8_t *bufpoi, *oob, *buf;
1494 unsigned int max_bitflips = 0;
1474 1495
1475 stats = mtd->ecc_stats; 1496 stats = mtd->ecc_stats;
1476 1497
@@ -1484,6 +1505,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1484 1505
1485 buf = ops->datbuf; 1506 buf = ops->datbuf;
1486 oob = ops->oobbuf; 1507 oob = ops->oobbuf;
1508 oob_required = oob ? 1 : 0;
1487 1509
1488 while (1) { 1510 while (1) {
1489 bytes = min(mtd->writesize - col, readlen); 1511 bytes = min(mtd->writesize - col, readlen);
@@ -1493,21 +1515,22 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1493 if (realpage != chip->pagebuf || oob) { 1515 if (realpage != chip->pagebuf || oob) {
1494 bufpoi = aligned ? buf : chip->buffers->databuf; 1516 bufpoi = aligned ? buf : chip->buffers->databuf;
1495 1517
1496 if (likely(sndcmd)) { 1518 chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
1497 chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
1498 sndcmd = 0;
1499 }
1500 1519
1501 /* Now read the page into the buffer */ 1520 /*
1521 * Now read the page into the buffer. Absent an error,
1522 * the read methods return max bitflips per ecc step.
1523 */
1502 if (unlikely(ops->mode == MTD_OPS_RAW)) 1524 if (unlikely(ops->mode == MTD_OPS_RAW))
1503 ret = chip->ecc.read_page_raw(mtd, chip, 1525 ret = chip->ecc.read_page_raw(mtd, chip, bufpoi,
1504 bufpoi, page); 1526 oob_required,
1527 page);
1505 else if (!aligned && NAND_SUBPAGE_READ(chip) && !oob) 1528 else if (!aligned && NAND_SUBPAGE_READ(chip) && !oob)
1506 ret = chip->ecc.read_subpage(mtd, chip, 1529 ret = chip->ecc.read_subpage(mtd, chip,
1507 col, bytes, bufpoi); 1530 col, bytes, bufpoi);
1508 else 1531 else
1509 ret = chip->ecc.read_page(mtd, chip, bufpoi, 1532 ret = chip->ecc.read_page(mtd, chip, bufpoi,
1510 page); 1533 oob_required, page);
1511 if (ret < 0) { 1534 if (ret < 0) {
1512 if (!aligned) 1535 if (!aligned)
1513 /* Invalidate page cache */ 1536 /* Invalidate page cache */
@@ -1515,22 +1538,25 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1515 break; 1538 break;
1516 } 1539 }
1517 1540
1541 max_bitflips = max_t(unsigned int, max_bitflips, ret);
1542
1518 /* Transfer not aligned data */ 1543 /* Transfer not aligned data */
1519 if (!aligned) { 1544 if (!aligned) {
1520 if (!NAND_SUBPAGE_READ(chip) && !oob && 1545 if (!NAND_SUBPAGE_READ(chip) && !oob &&
1521 !(mtd->ecc_stats.failed - stats.failed) && 1546 !(mtd->ecc_stats.failed - stats.failed) &&
1522 (ops->mode != MTD_OPS_RAW)) 1547 (ops->mode != MTD_OPS_RAW)) {
1523 chip->pagebuf = realpage; 1548 chip->pagebuf = realpage;
1524 else 1549 chip->pagebuf_bitflips = ret;
1550 } else {
1525 /* Invalidate page cache */ 1551 /* Invalidate page cache */
1526 chip->pagebuf = -1; 1552 chip->pagebuf = -1;
1553 }
1527 memcpy(buf, chip->buffers->databuf + col, bytes); 1554 memcpy(buf, chip->buffers->databuf + col, bytes);
1528 } 1555 }
1529 1556
1530 buf += bytes; 1557 buf += bytes;
1531 1558
1532 if (unlikely(oob)) { 1559 if (unlikely(oob)) {
1533
1534 int toread = min(oobreadlen, max_oobsize); 1560 int toread = min(oobreadlen, max_oobsize);
1535 1561
1536 if (toread) { 1562 if (toread) {
@@ -1541,13 +1567,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1541 } 1567 }
1542 1568
1543 if (!(chip->options & NAND_NO_READRDY)) { 1569 if (!(chip->options & NAND_NO_READRDY)) {
1544 /* 1570 /* Apply delay or wait for ready/busy pin */
1545 * Apply delay or wait for ready/busy pin. Do
1546 * this before the AUTOINCR check, so no
1547 * problems arise if a chip which does auto
1548 * increment is marked as NOAUTOINCR by the
1549 * board driver.
1550 */
1551 if (!chip->dev_ready) 1571 if (!chip->dev_ready)
1552 udelay(chip->chip_delay); 1572 udelay(chip->chip_delay);
1553 else 1573 else
@@ -1556,6 +1576,8 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1556 } else { 1576 } else {
1557 memcpy(buf, chip->buffers->databuf + col, bytes); 1577 memcpy(buf, chip->buffers->databuf + col, bytes);
1558 buf += bytes; 1578 buf += bytes;
1579 max_bitflips = max_t(unsigned int, max_bitflips,
1580 chip->pagebuf_bitflips);
1559 } 1581 }
1560 1582
1561 readlen -= bytes; 1583 readlen -= bytes;
@@ -1575,26 +1597,19 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1575 chip->select_chip(mtd, -1); 1597 chip->select_chip(mtd, -1);
1576 chip->select_chip(mtd, chipnr); 1598 chip->select_chip(mtd, chipnr);
1577 } 1599 }
1578
1579 /*
1580 * Check, if the chip supports auto page increment or if we
1581 * have hit a block boundary.
1582 */
1583 if (!NAND_CANAUTOINCR(chip) || !(page & blkcheck))
1584 sndcmd = 1;
1585 } 1600 }
1586 1601
1587 ops->retlen = ops->len - (size_t) readlen; 1602 ops->retlen = ops->len - (size_t) readlen;
1588 if (oob) 1603 if (oob)
1589 ops->oobretlen = ops->ooblen - oobreadlen; 1604 ops->oobretlen = ops->ooblen - oobreadlen;
1590 1605
1591 if (ret) 1606 if (ret < 0)
1592 return ret; 1607 return ret;
1593 1608
1594 if (mtd->ecc_stats.failed - stats.failed) 1609 if (mtd->ecc_stats.failed - stats.failed)
1595 return -EBADMSG; 1610 return -EBADMSG;
1596 1611
1597 return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0; 1612 return max_bitflips;
1598} 1613}
1599 1614
1600/** 1615/**
@@ -1630,17 +1645,13 @@ static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
1630 * @mtd: mtd info structure 1645 * @mtd: mtd info structure
1631 * @chip: nand chip info structure 1646 * @chip: nand chip info structure
1632 * @page: page number to read 1647 * @page: page number to read
1633 * @sndcmd: flag whether to issue read command or not
1634 */ 1648 */
1635static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, 1649static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
1636 int page, int sndcmd) 1650 int page)
1637{ 1651{
1638 if (sndcmd) { 1652 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
1639 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
1640 sndcmd = 0;
1641 }
1642 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); 1653 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
1643 return sndcmd; 1654 return 0;
1644} 1655}
1645 1656
1646/** 1657/**
@@ -1649,10 +1660,9 @@ static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
1649 * @mtd: mtd info structure 1660 * @mtd: mtd info structure
1650 * @chip: nand chip info structure 1661 * @chip: nand chip info structure
1651 * @page: page number to read 1662 * @page: page number to read
1652 * @sndcmd: flag whether to issue read command or not
1653 */ 1663 */
1654static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip, 1664static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
1655 int page, int sndcmd) 1665 int page)
1656{ 1666{
1657 uint8_t *buf = chip->oob_poi; 1667 uint8_t *buf = chip->oob_poi;
1658 int length = mtd->oobsize; 1668 int length = mtd->oobsize;
@@ -1679,7 +1689,7 @@ static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
1679 if (length > 0) 1689 if (length > 0)
1680 chip->read_buf(mtd, bufpoi, length); 1690 chip->read_buf(mtd, bufpoi, length);
1681 1691
1682 return 1; 1692 return 0;
1683} 1693}
1684 1694
1685/** 1695/**
@@ -1775,13 +1785,13 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd,
1775static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, 1785static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1776 struct mtd_oob_ops *ops) 1786 struct mtd_oob_ops *ops)
1777{ 1787{
1778 int page, realpage, chipnr, sndcmd = 1; 1788 int page, realpage, chipnr;
1779 struct nand_chip *chip = mtd->priv; 1789 struct nand_chip *chip = mtd->priv;
1780 struct mtd_ecc_stats stats; 1790 struct mtd_ecc_stats stats;
1781 int blkcheck = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1;
1782 int readlen = ops->ooblen; 1791 int readlen = ops->ooblen;
1783 int len; 1792 int len;
1784 uint8_t *buf = ops->oobbuf; 1793 uint8_t *buf = ops->oobbuf;
1794 int ret = 0;
1785 1795
1786 pr_debug("%s: from = 0x%08Lx, len = %i\n", 1796 pr_debug("%s: from = 0x%08Lx, len = %i\n",
1787 __func__, (unsigned long long)from, readlen); 1797 __func__, (unsigned long long)from, readlen);
@@ -1817,20 +1827,18 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1817 1827
1818 while (1) { 1828 while (1) {
1819 if (ops->mode == MTD_OPS_RAW) 1829 if (ops->mode == MTD_OPS_RAW)
1820 sndcmd = chip->ecc.read_oob_raw(mtd, chip, page, sndcmd); 1830 ret = chip->ecc.read_oob_raw(mtd, chip, page);
1821 else 1831 else
1822 sndcmd = chip->ecc.read_oob(mtd, chip, page, sndcmd); 1832 ret = chip->ecc.read_oob(mtd, chip, page);
1833
1834 if (ret < 0)
1835 break;
1823 1836
1824 len = min(len, readlen); 1837 len = min(len, readlen);
1825 buf = nand_transfer_oob(chip, buf, ops, len); 1838 buf = nand_transfer_oob(chip, buf, ops, len);
1826 1839
1827 if (!(chip->options & NAND_NO_READRDY)) { 1840 if (!(chip->options & NAND_NO_READRDY)) {
1828 /* 1841 /* Apply delay or wait for ready/busy pin */
1829 * Apply delay or wait for ready/busy pin. Do this
1830 * before the AUTOINCR check, so no problems arise if a
1831 * chip which does auto increment is marked as
1832 * NOAUTOINCR by the board driver.
1833 */
1834 if (!chip->dev_ready) 1842 if (!chip->dev_ready)
1835 udelay(chip->chip_delay); 1843 udelay(chip->chip_delay);
1836 else 1844 else
@@ -1851,16 +1859,12 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1851 chip->select_chip(mtd, -1); 1859 chip->select_chip(mtd, -1);
1852 chip->select_chip(mtd, chipnr); 1860 chip->select_chip(mtd, chipnr);
1853 } 1861 }
1854
1855 /*
1856 * Check, if the chip supports auto page increment or if we
1857 * have hit a block boundary.
1858 */
1859 if (!NAND_CANAUTOINCR(chip) || !(page & blkcheck))
1860 sndcmd = 1;
1861 } 1862 }
1862 1863
1863 ops->oobretlen = ops->ooblen; 1864 ops->oobretlen = ops->ooblen - readlen;
1865
1866 if (ret < 0)
1867 return ret;
1864 1868
1865 if (mtd->ecc_stats.failed - stats.failed) 1869 if (mtd->ecc_stats.failed - stats.failed)
1866 return -EBADMSG; 1870 return -EBADMSG;
@@ -1919,14 +1923,16 @@ out:
1919 * @mtd: mtd info structure 1923 * @mtd: mtd info structure
1920 * @chip: nand chip info structure 1924 * @chip: nand chip info structure
1921 * @buf: data buffer 1925 * @buf: data buffer
1926 * @oob_required: must write chip->oob_poi to OOB
1922 * 1927 *
1923 * Not for syndrome calculating ECC controllers, which use a special oob layout. 1928 * Not for syndrome calculating ECC controllers, which use a special oob layout.
1924 */ 1929 */
1925static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 1930static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1926 const uint8_t *buf) 1931 const uint8_t *buf, int oob_required)
1927{ 1932{
1928 chip->write_buf(mtd, buf, mtd->writesize); 1933 chip->write_buf(mtd, buf, mtd->writesize);
1929 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize); 1934 if (oob_required)
1935 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
1930} 1936}
1931 1937
1932/** 1938/**
@@ -1934,12 +1940,13 @@ static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1934 * @mtd: mtd info structure 1940 * @mtd: mtd info structure
1935 * @chip: nand chip info structure 1941 * @chip: nand chip info structure
1936 * @buf: data buffer 1942 * @buf: data buffer
1943 * @oob_required: must write chip->oob_poi to OOB
1937 * 1944 *
1938 * We need a special oob layout and handling even when ECC isn't checked. 1945 * We need a special oob layout and handling even when ECC isn't checked.
1939 */ 1946 */
1940static void nand_write_page_raw_syndrome(struct mtd_info *mtd, 1947static void nand_write_page_raw_syndrome(struct mtd_info *mtd,
1941 struct nand_chip *chip, 1948 struct nand_chip *chip,
1942 const uint8_t *buf) 1949 const uint8_t *buf, int oob_required)
1943{ 1950{
1944 int eccsize = chip->ecc.size; 1951 int eccsize = chip->ecc.size;
1945 int eccbytes = chip->ecc.bytes; 1952 int eccbytes = chip->ecc.bytes;
@@ -1973,9 +1980,10 @@ static void nand_write_page_raw_syndrome(struct mtd_info *mtd,
1973 * @mtd: mtd info structure 1980 * @mtd: mtd info structure
1974 * @chip: nand chip info structure 1981 * @chip: nand chip info structure
1975 * @buf: data buffer 1982 * @buf: data buffer
1983 * @oob_required: must write chip->oob_poi to OOB
1976 */ 1984 */
1977static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, 1985static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1978 const uint8_t *buf) 1986 const uint8_t *buf, int oob_required)
1979{ 1987{
1980 int i, eccsize = chip->ecc.size; 1988 int i, eccsize = chip->ecc.size;
1981 int eccbytes = chip->ecc.bytes; 1989 int eccbytes = chip->ecc.bytes;
@@ -1991,7 +1999,7 @@ static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1991 for (i = 0; i < chip->ecc.total; i++) 1999 for (i = 0; i < chip->ecc.total; i++)
1992 chip->oob_poi[eccpos[i]] = ecc_calc[i]; 2000 chip->oob_poi[eccpos[i]] = ecc_calc[i];
1993 2001
1994 chip->ecc.write_page_raw(mtd, chip, buf); 2002 chip->ecc.write_page_raw(mtd, chip, buf, 1);
1995} 2003}
1996 2004
1997/** 2005/**
@@ -1999,9 +2007,10 @@ static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1999 * @mtd: mtd info structure 2007 * @mtd: mtd info structure
2000 * @chip: nand chip info structure 2008 * @chip: nand chip info structure
2001 * @buf: data buffer 2009 * @buf: data buffer
2010 * @oob_required: must write chip->oob_poi to OOB
2002 */ 2011 */
2003static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, 2012static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
2004 const uint8_t *buf) 2013 const uint8_t *buf, int oob_required)
2005{ 2014{
2006 int i, eccsize = chip->ecc.size; 2015 int i, eccsize = chip->ecc.size;
2007 int eccbytes = chip->ecc.bytes; 2016 int eccbytes = chip->ecc.bytes;
@@ -2027,12 +2036,14 @@ static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
2027 * @mtd: mtd info structure 2036 * @mtd: mtd info structure
2028 * @chip: nand chip info structure 2037 * @chip: nand chip info structure
2029 * @buf: data buffer 2038 * @buf: data buffer
2039 * @oob_required: must write chip->oob_poi to OOB
2030 * 2040 *
2031 * The hw generator calculates the error syndrome automatically. Therefore we 2041 * The hw generator calculates the error syndrome automatically. Therefore we
2032 * need a special oob layout and handling. 2042 * need a special oob layout and handling.
2033 */ 2043 */
2034static void nand_write_page_syndrome(struct mtd_info *mtd, 2044static void nand_write_page_syndrome(struct mtd_info *mtd,
2035 struct nand_chip *chip, const uint8_t *buf) 2045 struct nand_chip *chip,
2046 const uint8_t *buf, int oob_required)
2036{ 2047{
2037 int i, eccsize = chip->ecc.size; 2048 int i, eccsize = chip->ecc.size;
2038 int eccbytes = chip->ecc.bytes; 2049 int eccbytes = chip->ecc.bytes;
@@ -2071,21 +2082,23 @@ static void nand_write_page_syndrome(struct mtd_info *mtd,
2071 * @mtd: MTD device structure 2082 * @mtd: MTD device structure
2072 * @chip: NAND chip descriptor 2083 * @chip: NAND chip descriptor
2073 * @buf: the data to write 2084 * @buf: the data to write
2085 * @oob_required: must write chip->oob_poi to OOB
2074 * @page: page number to write 2086 * @page: page number to write
2075 * @cached: cached programming 2087 * @cached: cached programming
2076 * @raw: use _raw version of write_page 2088 * @raw: use _raw version of write_page
2077 */ 2089 */
2078static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, 2090static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
2079 const uint8_t *buf, int page, int cached, int raw) 2091 const uint8_t *buf, int oob_required, int page,
2092 int cached, int raw)
2080{ 2093{
2081 int status; 2094 int status;
2082 2095
2083 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); 2096 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
2084 2097
2085 if (unlikely(raw)) 2098 if (unlikely(raw))
2086 chip->ecc.write_page_raw(mtd, chip, buf); 2099 chip->ecc.write_page_raw(mtd, chip, buf, oob_required);
2087 else 2100 else
2088 chip->ecc.write_page(mtd, chip, buf); 2101 chip->ecc.write_page(mtd, chip, buf, oob_required);
2089 2102
2090 /* 2103 /*
2091 * Cached progamming disabled for now. Not sure if it's worth the 2104 * Cached progamming disabled for now. Not sure if it's worth the
@@ -2118,6 +2131,9 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
2118 2131
2119 if (chip->verify_buf(mtd, buf, mtd->writesize)) 2132 if (chip->verify_buf(mtd, buf, mtd->writesize))
2120 return -EIO; 2133 return -EIO;
2134
2135 /* Make sure the next page prog is preceded by a status read */
2136 chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
2121#endif 2137#endif
2122 return 0; 2138 return 0;
2123} 2139}
@@ -2202,6 +2218,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2202 uint8_t *oob = ops->oobbuf; 2218 uint8_t *oob = ops->oobbuf;
2203 uint8_t *buf = ops->datbuf; 2219 uint8_t *buf = ops->datbuf;
2204 int ret, subpage; 2220 int ret, subpage;
2221 int oob_required = oob ? 1 : 0;
2205 2222
2206 ops->retlen = 0; 2223 ops->retlen = 0;
2207 if (!writelen) 2224 if (!writelen)
@@ -2264,8 +2281,8 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
2264 memset(chip->oob_poi, 0xff, mtd->oobsize); 2281 memset(chip->oob_poi, 0xff, mtd->oobsize);
2265 } 2282 }
2266 2283
2267 ret = chip->write_page(mtd, chip, wbuf, page, cached, 2284 ret = chip->write_page(mtd, chip, wbuf, oob_required, page,
2268 (ops->mode == MTD_OPS_RAW)); 2285 cached, (ops->mode == MTD_OPS_RAW));
2269 if (ret) 2286 if (ret)
2270 break; 2287 break;
2271 2288
@@ -2898,8 +2915,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
2898 *busw = NAND_BUSWIDTH_16; 2915 *busw = NAND_BUSWIDTH_16;
2899 2916
2900 chip->options &= ~NAND_CHIPOPTIONS_MSK; 2917 chip->options &= ~NAND_CHIPOPTIONS_MSK;
2901 chip->options |= (NAND_NO_READRDY | 2918 chip->options |= NAND_NO_READRDY & NAND_CHIPOPTIONS_MSK;
2902 NAND_NO_AUTOINCR) & NAND_CHIPOPTIONS_MSK;
2903 2919
2904 pr_info("ONFI flash detected\n"); 2920 pr_info("ONFI flash detected\n");
2905 return 1; 2921 return 1;
@@ -3076,11 +3092,6 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
3076 chip->options &= ~NAND_SAMSUNG_LP_OPTIONS; 3092 chip->options &= ~NAND_SAMSUNG_LP_OPTIONS;
3077ident_done: 3093ident_done:
3078 3094
3079 /*
3080 * Set chip as a default. Board drivers can override it, if necessary.
3081 */
3082 chip->options |= NAND_NO_AUTOINCR;
3083
3084 /* Try to identify manufacturer */ 3095 /* Try to identify manufacturer */
3085 for (maf_idx = 0; nand_manuf_ids[maf_idx].id != 0x0; maf_idx++) { 3096 for (maf_idx = 0; nand_manuf_ids[maf_idx].id != 0x0; maf_idx++) {
3086 if (nand_manuf_ids[maf_idx].id == *maf_id) 3097 if (nand_manuf_ids[maf_idx].id == *maf_id)
@@ -3154,10 +3165,11 @@ ident_done:
3154 if (mtd->writesize > 512 && chip->cmdfunc == nand_command) 3165 if (mtd->writesize > 512 && chip->cmdfunc == nand_command)
3155 chip->cmdfunc = nand_command_lp; 3166 chip->cmdfunc = nand_command_lp;
3156 3167
3157 pr_info("NAND device: Manufacturer ID:" 3168 pr_info("NAND device: Manufacturer ID: 0x%02x, Chip ID: 0x%02x (%s %s),"
3158 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", *maf_id, *dev_id, 3169 " page size: %d, OOB size: %d\n",
3159 nand_manuf_ids[maf_idx].name, 3170 *maf_id, *dev_id, nand_manuf_ids[maf_idx].name,
3160 chip->onfi_version ? chip->onfi_params.model : type->name); 3171 chip->onfi_version ? chip->onfi_params.model : type->name,
3172 mtd->writesize, mtd->oobsize);
3161 3173
3162 return type; 3174 return type;
3163} 3175}
@@ -3329,8 +3341,13 @@ int nand_scan_tail(struct mtd_info *mtd)
3329 if (!chip->ecc.write_oob) 3341 if (!chip->ecc.write_oob)
3330 chip->ecc.write_oob = nand_write_oob_syndrome; 3342 chip->ecc.write_oob = nand_write_oob_syndrome;
3331 3343
3332 if (mtd->writesize >= chip->ecc.size) 3344 if (mtd->writesize >= chip->ecc.size) {
3345 if (!chip->ecc.strength) {
3346 pr_warn("Driver must set ecc.strength when using hardware ECC\n");
3347 BUG();
3348 }
3333 break; 3349 break;
3350 }
3334 pr_warn("%d byte HW ECC not possible on " 3351 pr_warn("%d byte HW ECC not possible on "
3335 "%d byte page size, fallback to SW ECC\n", 3352 "%d byte page size, fallback to SW ECC\n",
3336 chip->ecc.size, mtd->writesize); 3353 chip->ecc.size, mtd->writesize);
@@ -3385,7 +3402,7 @@ int nand_scan_tail(struct mtd_info *mtd)
3385 BUG(); 3402 BUG();
3386 } 3403 }
3387 chip->ecc.strength = 3404 chip->ecc.strength =
3388 chip->ecc.bytes*8 / fls(8*chip->ecc.size); 3405 chip->ecc.bytes * 8 / fls(8 * chip->ecc.size);
3389 break; 3406 break;
3390 3407
3391 case NAND_ECC_NONE: 3408 case NAND_ECC_NONE:
@@ -3483,7 +3500,7 @@ int nand_scan_tail(struct mtd_info *mtd)
3483 3500
3484 /* propagate ecc info to mtd_info */ 3501 /* propagate ecc info to mtd_info */
3485 mtd->ecclayout = chip->ecc.layout; 3502 mtd->ecclayout = chip->ecc.layout;
3486 mtd->ecc_strength = chip->ecc.strength * chip->ecc.steps; 3503 mtd->ecc_strength = chip->ecc.strength;
3487 3504
3488 /* Check, if we should skip the bad block table scan */ 3505 /* Check, if we should skip the bad block table scan */
3489 if (chip->options & NAND_SKIP_BBTSCAN) 3506 if (chip->options & NAND_SKIP_BBTSCAN)
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index 20a112f591fe..30d1319ff065 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -324,6 +324,7 @@ static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs,
324 324
325 buf += mtd->oobsize + mtd->writesize; 325 buf += mtd->oobsize + mtd->writesize;
326 len -= mtd->writesize; 326 len -= mtd->writesize;
327 offs += mtd->writesize;
327 } 328 }
328 return 0; 329 return 0;
329} 330}
diff --git a/drivers/mtd/nand/nand_ids.c b/drivers/mtd/nand/nand_ids.c
index af4fe8ca7b5e..621b70b7a159 100644
--- a/drivers/mtd/nand/nand_ids.c
+++ b/drivers/mtd/nand/nand_ids.c
@@ -70,7 +70,7 @@ struct nand_flash_dev nand_flash_ids[] = {
70 * These are the new chips with large page size. The pagesize and the 70 * These are the new chips with large page size. The pagesize and the
71 * erasesize is determined from the extended id bytes 71 * erasesize is determined from the extended id bytes
72 */ 72 */
73#define LP_OPTIONS (NAND_SAMSUNG_LP_OPTIONS | NAND_NO_READRDY | NAND_NO_AUTOINCR) 73#define LP_OPTIONS (NAND_SAMSUNG_LP_OPTIONS | NAND_NO_READRDY)
74#define LP_OPTIONS16 (LP_OPTIONS | NAND_BUSWIDTH_16) 74#define LP_OPTIONS16 (LP_OPTIONS | NAND_BUSWIDTH_16)
75 75
76 /* 512 Megabit */ 76 /* 512 Megabit */
@@ -157,9 +157,7 @@ struct nand_flash_dev nand_flash_ids[] = {
157 * writes possible, but not implemented now 157 * writes possible, but not implemented now
158 */ 158 */
159 {"AND 128MiB 3,3V 8-bit", 0x01, 2048, 128, 0x4000, 159 {"AND 128MiB 3,3V 8-bit", 0x01, 2048, 128, 0x4000,
160 NAND_IS_AND | NAND_NO_AUTOINCR |NAND_NO_READRDY | NAND_4PAGE_ARRAY | 160 NAND_IS_AND | NAND_NO_READRDY | NAND_4PAGE_ARRAY | BBT_AUTO_REFRESH},
161 BBT_AUTO_REFRESH
162 },
163 161
164 {NULL,} 162 {NULL,}
165}; 163};
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 261f478f8cc3..6cc8fbfabb8e 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -268,7 +268,6 @@ MODULE_PARM_DESC(bch, "Enable BCH ecc and set how many bits should "
268#define OPT_PAGE512 0x00000002 /* 512-byte page chips */ 268#define OPT_PAGE512 0x00000002 /* 512-byte page chips */
269#define OPT_PAGE2048 0x00000008 /* 2048-byte page chips */ 269#define OPT_PAGE2048 0x00000008 /* 2048-byte page chips */
270#define OPT_SMARTMEDIA 0x00000010 /* SmartMedia technology chips */ 270#define OPT_SMARTMEDIA 0x00000010 /* SmartMedia technology chips */
271#define OPT_AUTOINCR 0x00000020 /* page number auto incrementation is possible */
272#define OPT_PAGE512_8BIT 0x00000040 /* 512-byte page chips with 8-bit bus width */ 271#define OPT_PAGE512_8BIT 0x00000040 /* 512-byte page chips with 8-bit bus width */
273#define OPT_PAGE4096 0x00000080 /* 4096-byte page chips */ 272#define OPT_PAGE4096 0x00000080 /* 4096-byte page chips */
274#define OPT_LARGEPAGE (OPT_PAGE2048 | OPT_PAGE4096) /* 2048 & 4096-byte page chips */ 273#define OPT_LARGEPAGE (OPT_PAGE2048 | OPT_PAGE4096) /* 2048 & 4096-byte page chips */
@@ -594,7 +593,7 @@ static int init_nandsim(struct mtd_info *mtd)
594 ns->options |= OPT_PAGE256; 593 ns->options |= OPT_PAGE256;
595 } 594 }
596 else if (ns->geom.pgsz == 512) { 595 else if (ns->geom.pgsz == 512) {
597 ns->options |= (OPT_PAGE512 | OPT_AUTOINCR); 596 ns->options |= OPT_PAGE512;
598 if (ns->busw == 8) 597 if (ns->busw == 8)
599 ns->options |= OPT_PAGE512_8BIT; 598 ns->options |= OPT_PAGE512_8BIT;
600 } else if (ns->geom.pgsz == 2048) { 599 } else if (ns->geom.pgsz == 2048) {
@@ -663,8 +662,6 @@ static int init_nandsim(struct mtd_info *mtd)
663 for (i = 0; nand_flash_ids[i].name != NULL; i++) { 662 for (i = 0; nand_flash_ids[i].name != NULL; i++) {
664 if (second_id_byte != nand_flash_ids[i].id) 663 if (second_id_byte != nand_flash_ids[i].id)
665 continue; 664 continue;
666 if (!(nand_flash_ids[i].options & NAND_NO_AUTOINCR))
667 ns->options |= OPT_AUTOINCR;
668 } 665 }
669 666
670 if (ns->busw == 16) 667 if (ns->busw == 16)
@@ -1936,20 +1933,8 @@ static u_char ns_nand_read_byte(struct mtd_info *mtd)
1936 if (ns->regs.count == ns->regs.num) { 1933 if (ns->regs.count == ns->regs.num) {
1937 NS_DBG("read_byte: all bytes were read\n"); 1934 NS_DBG("read_byte: all bytes were read\n");
1938 1935
1939 /* 1936 if (NS_STATE(ns->nxstate) == STATE_READY)
1940 * The OPT_AUTOINCR allows to read next consecutive pages without
1941 * new read operation cycle.
1942 */
1943 if ((ns->options & OPT_AUTOINCR) && NS_STATE(ns->state) == STATE_DATAOUT) {
1944 ns->regs.count = 0;
1945 if (ns->regs.row + 1 < ns->geom.pgnum)
1946 ns->regs.row += 1;
1947 NS_DBG("read_byte: switch to the next page (%#x)\n", ns->regs.row);
1948 do_state_action(ns, ACTION_CPY);
1949 }
1950 else if (NS_STATE(ns->nxstate) == STATE_READY)
1951 switch_state(ns); 1937 switch_state(ns);
1952
1953 } 1938 }
1954 1939
1955 return outb; 1940 return outb;
@@ -2203,14 +2188,7 @@ static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
2203 ns->regs.count += len; 2188 ns->regs.count += len;
2204 2189
2205 if (ns->regs.count == ns->regs.num) { 2190 if (ns->regs.count == ns->regs.num) {
2206 if ((ns->options & OPT_AUTOINCR) && NS_STATE(ns->state) == STATE_DATAOUT) { 2191 if (NS_STATE(ns->nxstate) == STATE_READY)
2207 ns->regs.count = 0;
2208 if (ns->regs.row + 1 < ns->geom.pgnum)
2209 ns->regs.row += 1;
2210 NS_DBG("read_buf: switch to the next page (%#x)\n", ns->regs.row);
2211 do_state_action(ns, ACTION_CPY);
2212 }
2213 else if (NS_STATE(ns->nxstate) == STATE_READY)
2214 switch_state(ns); 2192 switch_state(ns);
2215 } 2193 }
2216 2194
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index c2b0bba9d8b3..d7f681d0c9b9 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -21,6 +21,10 @@
21#include <linux/io.h> 21#include <linux/io.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23 23
24#ifdef CONFIG_MTD_NAND_OMAP_BCH
25#include <linux/bch.h>
26#endif
27
24#include <plat/dma.h> 28#include <plat/dma.h>
25#include <plat/gpmc.h> 29#include <plat/gpmc.h>
26#include <plat/nand.h> 30#include <plat/nand.h>
@@ -127,6 +131,11 @@ struct omap_nand_info {
127 } iomode; 131 } iomode;
128 u_char *buf; 132 u_char *buf;
129 int buf_len; 133 int buf_len;
134
135#ifdef CONFIG_MTD_NAND_OMAP_BCH
136 struct bch_control *bch;
137 struct nand_ecclayout ecclayout;
138#endif
130}; 139};
131 140
132/** 141/**
@@ -402,7 +411,7 @@ static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr,
402 PREFETCH_FIFOTHRESHOLD_MAX, 0x1, len, is_write); 411 PREFETCH_FIFOTHRESHOLD_MAX, 0x1, len, is_write);
403 if (ret) 412 if (ret)
404 /* PFPW engine is busy, use cpu copy method */ 413 /* PFPW engine is busy, use cpu copy method */
405 goto out_copy; 414 goto out_copy_unmap;
406 415
407 init_completion(&info->comp); 416 init_completion(&info->comp);
408 417
@@ -421,6 +430,8 @@ static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr,
421 dma_unmap_single(&info->pdev->dev, dma_addr, len, dir); 430 dma_unmap_single(&info->pdev->dev, dma_addr, len, dir);
422 return 0; 431 return 0;
423 432
433out_copy_unmap:
434 dma_unmap_single(&info->pdev->dev, dma_addr, len, dir);
424out_copy: 435out_copy:
425 if (info->nand.options & NAND_BUSWIDTH_16) 436 if (info->nand.options & NAND_BUSWIDTH_16)
426 is_write == 0 ? omap_read_buf16(mtd, (u_char *) addr, len) 437 is_write == 0 ? omap_read_buf16(mtd, (u_char *) addr, len)
@@ -879,7 +890,7 @@ static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
879 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 890 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
880 mtd); 891 mtd);
881 unsigned long timeo = jiffies; 892 unsigned long timeo = jiffies;
882 int status = NAND_STATUS_FAIL, state = this->state; 893 int status, state = this->state;
883 894
884 if (state == FL_ERASING) 895 if (state == FL_ERASING)
885 timeo += (HZ * 400) / 1000; 896 timeo += (HZ * 400) / 1000;
@@ -894,6 +905,8 @@ static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
894 break; 905 break;
895 cond_resched(); 906 cond_resched();
896 } 907 }
908
909 status = gpmc_nand_read(info->gpmc_cs, GPMC_NAND_DATA);
897 return status; 910 return status;
898} 911}
899 912
@@ -925,6 +938,226 @@ static int omap_dev_ready(struct mtd_info *mtd)
925 return 1; 938 return 1;
926} 939}
927 940
941#ifdef CONFIG_MTD_NAND_OMAP_BCH
942
943/**
944 * omap3_enable_hwecc_bch - Program OMAP3 GPMC to perform BCH ECC correction
945 * @mtd: MTD device structure
946 * @mode: Read/Write mode
947 */
948static void omap3_enable_hwecc_bch(struct mtd_info *mtd, int mode)
949{
950 int nerrors;
951 unsigned int dev_width;
952 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
953 mtd);
954 struct nand_chip *chip = mtd->priv;
955
956 nerrors = (info->nand.ecc.bytes == 13) ? 8 : 4;
957 dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
958 /*
959 * Program GPMC to perform correction on one 512-byte sector at a time.
960 * Using 4 sectors at a time (i.e. ecc.size = 2048) is also possible and
961 * gives a slight (5%) performance gain (but requires additional code).
962 */
963 (void)gpmc_enable_hwecc_bch(info->gpmc_cs, mode, dev_width, 1, nerrors);
964}
965
966/**
967 * omap3_calculate_ecc_bch4 - Generate 7 bytes of ECC bytes
968 * @mtd: MTD device structure
969 * @dat: The pointer to data on which ecc is computed
970 * @ecc_code: The ecc_code buffer
971 */
972static int omap3_calculate_ecc_bch4(struct mtd_info *mtd, const u_char *dat,
973 u_char *ecc_code)
974{
975 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
976 mtd);
977 return gpmc_calculate_ecc_bch4(info->gpmc_cs, dat, ecc_code);
978}
979
980/**
981 * omap3_calculate_ecc_bch8 - Generate 13 bytes of ECC bytes
982 * @mtd: MTD device structure
983 * @dat: The pointer to data on which ecc is computed
984 * @ecc_code: The ecc_code buffer
985 */
986static int omap3_calculate_ecc_bch8(struct mtd_info *mtd, const u_char *dat,
987 u_char *ecc_code)
988{
989 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
990 mtd);
991 return gpmc_calculate_ecc_bch8(info->gpmc_cs, dat, ecc_code);
992}
993
994/**
995 * omap3_correct_data_bch - Decode received data and correct errors
996 * @mtd: MTD device structure
997 * @data: page data
998 * @read_ecc: ecc read from nand flash
999 * @calc_ecc: ecc read from HW ECC registers
1000 */
1001static int omap3_correct_data_bch(struct mtd_info *mtd, u_char *data,
1002 u_char *read_ecc, u_char *calc_ecc)
1003{
1004 int i, count;
1005 /* cannot correct more than 8 errors */
1006 unsigned int errloc[8];
1007 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1008 mtd);
1009
1010 count = decode_bch(info->bch, NULL, 512, read_ecc, calc_ecc, NULL,
1011 errloc);
1012 if (count > 0) {
1013 /* correct errors */
1014 for (i = 0; i < count; i++) {
1015 /* correct data only, not ecc bytes */
1016 if (errloc[i] < 8*512)
1017 data[errloc[i]/8] ^= 1 << (errloc[i] & 7);
1018 pr_debug("corrected bitflip %u\n", errloc[i]);
1019 }
1020 } else if (count < 0) {
1021 pr_err("ecc unrecoverable error\n");
1022 }
1023 return count;
1024}
1025
1026/**
1027 * omap3_free_bch - Release BCH ecc resources
1028 * @mtd: MTD device structure
1029 */
1030static void omap3_free_bch(struct mtd_info *mtd)
1031{
1032 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1033 mtd);
1034 if (info->bch) {
1035 free_bch(info->bch);
1036 info->bch = NULL;
1037 }
1038}
1039
1040/**
1041 * omap3_init_bch - Initialize BCH ECC
1042 * @mtd: MTD device structure
1043 * @ecc_opt: OMAP ECC mode (OMAP_ECC_BCH4_CODE_HW or OMAP_ECC_BCH8_CODE_HW)
1044 */
1045static int omap3_init_bch(struct mtd_info *mtd, int ecc_opt)
1046{
1047 int ret, max_errors;
1048 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1049 mtd);
1050#ifdef CONFIG_MTD_NAND_OMAP_BCH8
1051 const int hw_errors = 8;
1052#else
1053 const int hw_errors = 4;
1054#endif
1055 info->bch = NULL;
1056
1057 max_errors = (ecc_opt == OMAP_ECC_BCH8_CODE_HW) ? 8 : 4;
1058 if (max_errors != hw_errors) {
1059 pr_err("cannot configure %d-bit BCH ecc, only %d-bit supported",
1060 max_errors, hw_errors);
1061 goto fail;
1062 }
1063
1064 /* initialize GPMC BCH engine */
1065 ret = gpmc_init_hwecc_bch(info->gpmc_cs, 1, max_errors);
1066 if (ret)
1067 goto fail;
1068
1069 /* software bch library is only used to detect and locate errors */
1070 info->bch = init_bch(13, max_errors, 0x201b /* hw polynomial */);
1071 if (!info->bch)
1072 goto fail;
1073
1074 info->nand.ecc.size = 512;
1075 info->nand.ecc.hwctl = omap3_enable_hwecc_bch;
1076 info->nand.ecc.correct = omap3_correct_data_bch;
1077 info->nand.ecc.mode = NAND_ECC_HW;
1078
1079 /*
1080 * The number of corrected errors in an ecc block that will trigger
1081 * block scrubbing defaults to the ecc strength (4 or 8).
1082 * Set mtd->bitflip_threshold here to define a custom threshold.
1083 */
1084
1085 if (max_errors == 8) {
1086 info->nand.ecc.strength = 8;
1087 info->nand.ecc.bytes = 13;
1088 info->nand.ecc.calculate = omap3_calculate_ecc_bch8;
1089 } else {
1090 info->nand.ecc.strength = 4;
1091 info->nand.ecc.bytes = 7;
1092 info->nand.ecc.calculate = omap3_calculate_ecc_bch4;
1093 }
1094
1095 pr_info("enabling NAND BCH ecc with %d-bit correction\n", max_errors);
1096 return 0;
1097fail:
1098 omap3_free_bch(mtd);
1099 return -1;
1100}
1101
1102/**
1103 * omap3_init_bch_tail - Build an oob layout for BCH ECC correction.
1104 * @mtd: MTD device structure
1105 */
1106static int omap3_init_bch_tail(struct mtd_info *mtd)
1107{
1108 int i, steps;
1109 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1110 mtd);
1111 struct nand_ecclayout *layout = &info->ecclayout;
1112
1113 /* build oob layout */
1114 steps = mtd->writesize/info->nand.ecc.size;
1115 layout->eccbytes = steps*info->nand.ecc.bytes;
1116
1117 /* do not bother creating special oob layouts for small page devices */
1118 if (mtd->oobsize < 64) {
1119 pr_err("BCH ecc is not supported on small page devices\n");
1120 goto fail;
1121 }
1122
1123 /* reserve 2 bytes for bad block marker */
1124 if (layout->eccbytes+2 > mtd->oobsize) {
1125 pr_err("no oob layout available for oobsize %d eccbytes %u\n",
1126 mtd->oobsize, layout->eccbytes);
1127 goto fail;
1128 }
1129
1130 /* put ecc bytes at oob tail */
1131 for (i = 0; i < layout->eccbytes; i++)
1132 layout->eccpos[i] = mtd->oobsize-layout->eccbytes+i;
1133
1134 layout->oobfree[0].offset = 2;
1135 layout->oobfree[0].length = mtd->oobsize-2-layout->eccbytes;
1136 info->nand.ecc.layout = layout;
1137
1138 if (!(info->nand.options & NAND_BUSWIDTH_16))
1139 info->nand.badblock_pattern = &bb_descrip_flashbased;
1140 return 0;
1141fail:
1142 omap3_free_bch(mtd);
1143 return -1;
1144}
1145
1146#else
1147static int omap3_init_bch(struct mtd_info *mtd, int ecc_opt)
1148{
1149 pr_err("CONFIG_MTD_NAND_OMAP_BCH is not enabled\n");
1150 return -1;
1151}
1152static int omap3_init_bch_tail(struct mtd_info *mtd)
1153{
1154 return -1;
1155}
1156static void omap3_free_bch(struct mtd_info *mtd)
1157{
1158}
1159#endif /* CONFIG_MTD_NAND_OMAP_BCH */
1160
928static int __devinit omap_nand_probe(struct platform_device *pdev) 1161static int __devinit omap_nand_probe(struct platform_device *pdev)
929{ 1162{
930 struct omap_nand_info *info; 1163 struct omap_nand_info *info;
@@ -1063,6 +1296,13 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
1063 info->nand.ecc.hwctl = omap_enable_hwecc; 1296 info->nand.ecc.hwctl = omap_enable_hwecc;
1064 info->nand.ecc.correct = omap_correct_data; 1297 info->nand.ecc.correct = omap_correct_data;
1065 info->nand.ecc.mode = NAND_ECC_HW; 1298 info->nand.ecc.mode = NAND_ECC_HW;
1299 } else if ((pdata->ecc_opt == OMAP_ECC_BCH4_CODE_HW) ||
1300 (pdata->ecc_opt == OMAP_ECC_BCH8_CODE_HW)) {
1301 err = omap3_init_bch(&info->mtd, pdata->ecc_opt);
1302 if (err) {
1303 err = -EINVAL;
1304 goto out_release_mem_region;
1305 }
1066 } 1306 }
1067 1307
1068 /* DIP switches on some boards change between 8 and 16 bit 1308 /* DIP switches on some boards change between 8 and 16 bit
@@ -1094,6 +1334,14 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
1094 (offset + omap_oobinfo.eccbytes); 1334 (offset + omap_oobinfo.eccbytes);
1095 1335
1096 info->nand.ecc.layout = &omap_oobinfo; 1336 info->nand.ecc.layout = &omap_oobinfo;
1337 } else if ((pdata->ecc_opt == OMAP_ECC_BCH4_CODE_HW) ||
1338 (pdata->ecc_opt == OMAP_ECC_BCH8_CODE_HW)) {
1339 /* build OOB layout for BCH ECC correction */
1340 err = omap3_init_bch_tail(&info->mtd);
1341 if (err) {
1342 err = -EINVAL;
1343 goto out_release_mem_region;
1344 }
1097 } 1345 }
1098 1346
1099 /* second phase scan */ 1347 /* second phase scan */
@@ -1122,6 +1370,7 @@ static int omap_nand_remove(struct platform_device *pdev)
1122 struct mtd_info *mtd = platform_get_drvdata(pdev); 1370 struct mtd_info *mtd = platform_get_drvdata(pdev);
1123 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info, 1371 struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
1124 mtd); 1372 mtd);
1373 omap3_free_bch(&info->mtd);
1125 1374
1126 platform_set_drvdata(pdev, NULL); 1375 platform_set_drvdata(pdev, NULL);
1127 if (info->dma_ch != -1) 1376 if (info->dma_ch != -1)
diff --git a/drivers/mtd/nand/pasemi_nand.c b/drivers/mtd/nand/pasemi_nand.c
index 974dbf8251c9..1440e51cedcc 100644
--- a/drivers/mtd/nand/pasemi_nand.c
+++ b/drivers/mtd/nand/pasemi_nand.c
@@ -155,7 +155,6 @@ static int __devinit pasemi_nand_probe(struct platform_device *ofdev)
155 chip->ecc.mode = NAND_ECC_SOFT; 155 chip->ecc.mode = NAND_ECC_SOFT;
156 156
157 /* Enable the following for a flash based bad block table */ 157 /* Enable the following for a flash based bad block table */
158 chip->options = NAND_NO_AUTOINCR;
159 chip->bbt_options = NAND_BBT_USE_FLASH; 158 chip->bbt_options = NAND_BBT_USE_FLASH;
160 159
161 /* Scan to find existence of the device */ 160 /* Scan to find existence of the device */
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index 6404e6e81b10..1bcb52040422 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -23,14 +23,18 @@ struct plat_nand_data {
23 void __iomem *io_base; 23 void __iomem *io_base;
24}; 24};
25 25
26static const char *part_probe_types[] = { "cmdlinepart", NULL };
27
26/* 28/*
27 * Probe for the NAND device. 29 * Probe for the NAND device.
28 */ 30 */
29static int __devinit plat_nand_probe(struct platform_device *pdev) 31static int __devinit plat_nand_probe(struct platform_device *pdev)
30{ 32{
31 struct platform_nand_data *pdata = pdev->dev.platform_data; 33 struct platform_nand_data *pdata = pdev->dev.platform_data;
34 struct mtd_part_parser_data ppdata;
32 struct plat_nand_data *data; 35 struct plat_nand_data *data;
33 struct resource *res; 36 struct resource *res;
37 const char **part_types;
34 int err = 0; 38 int err = 0;
35 39
36 if (pdata->chip.nr_chips < 1) { 40 if (pdata->chip.nr_chips < 1) {
@@ -75,6 +79,7 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
75 data->chip.select_chip = pdata->ctrl.select_chip; 79 data->chip.select_chip = pdata->ctrl.select_chip;
76 data->chip.write_buf = pdata->ctrl.write_buf; 80 data->chip.write_buf = pdata->ctrl.write_buf;
77 data->chip.read_buf = pdata->ctrl.read_buf; 81 data->chip.read_buf = pdata->ctrl.read_buf;
82 data->chip.read_byte = pdata->ctrl.read_byte;
78 data->chip.chip_delay = pdata->chip.chip_delay; 83 data->chip.chip_delay = pdata->chip.chip_delay;
79 data->chip.options |= pdata->chip.options; 84 data->chip.options |= pdata->chip.options;
80 data->chip.bbt_options |= pdata->chip.bbt_options; 85 data->chip.bbt_options |= pdata->chip.bbt_options;
@@ -98,8 +103,10 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
98 goto out; 103 goto out;
99 } 104 }
100 105
101 err = mtd_device_parse_register(&data->mtd, 106 part_types = pdata->chip.part_probe_types ? : part_probe_types;
102 pdata->chip.part_probe_types, NULL, 107
108 ppdata.of_node = pdev->dev.of_node;
109 err = mtd_device_parse_register(&data->mtd, part_types, &ppdata,
103 pdata->chip.partitions, 110 pdata->chip.partitions,
104 pdata->chip.nr_partitions); 111 pdata->chip.nr_partitions);
105 112
@@ -140,12 +147,19 @@ static int __devexit plat_nand_remove(struct platform_device *pdev)
140 return 0; 147 return 0;
141} 148}
142 149
150static const struct of_device_id plat_nand_match[] = {
151 { .compatible = "gen_nand" },
152 {},
153};
154MODULE_DEVICE_TABLE(of, plat_nand_match);
155
143static struct platform_driver plat_nand_driver = { 156static struct platform_driver plat_nand_driver = {
144 .probe = plat_nand_probe, 157 .probe = plat_nand_probe,
145 .remove = __devexit_p(plat_nand_remove), 158 .remove = __devexit_p(plat_nand_remove),
146 .driver = { 159 .driver = {
147 .name = "gen_nand", 160 .name = "gen_nand",
148 .owner = THIS_MODULE, 161 .owner = THIS_MODULE,
162 .of_match_table = plat_nand_match,
149 }, 163 },
150}; 164};
151 165
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index def50caa6f84..252aaefcacfa 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -682,14 +682,15 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
682} 682}
683 683
684static void pxa3xx_nand_write_page_hwecc(struct mtd_info *mtd, 684static void pxa3xx_nand_write_page_hwecc(struct mtd_info *mtd,
685 struct nand_chip *chip, const uint8_t *buf) 685 struct nand_chip *chip, const uint8_t *buf, int oob_required)
686{ 686{
687 chip->write_buf(mtd, buf, mtd->writesize); 687 chip->write_buf(mtd, buf, mtd->writesize);
688 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize); 688 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
689} 689}
690 690
691static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd, 691static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd,
692 struct nand_chip *chip, uint8_t *buf, int page) 692 struct nand_chip *chip, uint8_t *buf, int oob_required,
693 int page)
693{ 694{
694 struct pxa3xx_nand_host *host = mtd->priv; 695 struct pxa3xx_nand_host *host = mtd->priv;
695 struct pxa3xx_nand_info *info = host->info_data; 696 struct pxa3xx_nand_info *info = host->info_data;
@@ -1004,7 +1005,6 @@ KEEP_CONFIG:
1004 chip->ecc.size = host->page_size; 1005 chip->ecc.size = host->page_size;
1005 chip->ecc.strength = 1; 1006 chip->ecc.strength = 1;
1006 1007
1007 chip->options = NAND_NO_AUTOINCR;
1008 chip->options |= NAND_NO_READRDY; 1008 chip->options |= NAND_NO_READRDY;
1009 if (host->reg_ndcr & NDCR_DWIDTH_M) 1009 if (host->reg_ndcr & NDCR_DWIDTH_M)
1010 chip->options |= NAND_BUSWIDTH_16; 1010 chip->options |= NAND_BUSWIDTH_16;
diff --git a/drivers/mtd/nand/r852.c b/drivers/mtd/nand/r852.c
index c2040187c813..8cb627751c9c 100644
--- a/drivers/mtd/nand/r852.c
+++ b/drivers/mtd/nand/r852.c
@@ -539,14 +539,11 @@ exit:
539 * nand_read_oob_syndrome assumes we can send column address - we can't 539 * nand_read_oob_syndrome assumes we can send column address - we can't
540 */ 540 */
541static int r852_read_oob(struct mtd_info *mtd, struct nand_chip *chip, 541static int r852_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
542 int page, int sndcmd) 542 int page)
543{ 543{
544 if (sndcmd) { 544 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
545 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
546 sndcmd = 0;
547 }
548 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); 545 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
549 return sndcmd; 546 return 0;
550} 547}
551 548
552/* 549/*
@@ -1104,18 +1101,7 @@ static struct pci_driver r852_pci_driver = {
1104 .driver.pm = &r852_pm_ops, 1101 .driver.pm = &r852_pm_ops,
1105}; 1102};
1106 1103
1107static __init int r852_module_init(void) 1104module_pci_driver(r852_pci_driver);
1108{
1109 return pci_register_driver(&r852_pci_driver);
1110}
1111
1112static void __exit r852_module_exit(void)
1113{
1114 pci_unregister_driver(&r852_pci_driver);
1115}
1116
1117module_init(r852_module_init);
1118module_exit(r852_module_exit);
1119 1105
1120MODULE_LICENSE("GPL"); 1106MODULE_LICENSE("GPL");
1121MODULE_AUTHOR("Maxim Levitsky <maximlevitsky@gmail.com>"); 1107MODULE_AUTHOR("Maxim Levitsky <maximlevitsky@gmail.com>");
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c
index e9b2b260de3a..aa9b8a5e0b8f 100644
--- a/drivers/mtd/nand/sh_flctl.c
+++ b/drivers/mtd/nand/sh_flctl.c
@@ -344,7 +344,7 @@ static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_va
344} 344}
345 345
346static int flctl_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, 346static int flctl_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
347 uint8_t *buf, int page) 347 uint8_t *buf, int oob_required, int page)
348{ 348{
349 int i, eccsize = chip->ecc.size; 349 int i, eccsize = chip->ecc.size;
350 int eccbytes = chip->ecc.bytes; 350 int eccbytes = chip->ecc.bytes;
@@ -359,14 +359,14 @@ static int flctl_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
359 if (flctl->hwecc_cant_correct[i]) 359 if (flctl->hwecc_cant_correct[i])
360 mtd->ecc_stats.failed++; 360 mtd->ecc_stats.failed++;
361 else 361 else
362 mtd->ecc_stats.corrected += 0; 362 mtd->ecc_stats.corrected += 0; /* FIXME */
363 } 363 }
364 364
365 return 0; 365 return 0;
366} 366}
367 367
368static void flctl_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, 368static void flctl_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
369 const uint8_t *buf) 369 const uint8_t *buf, int oob_required)
370{ 370{
371 int i, eccsize = chip->ecc.size; 371 int i, eccsize = chip->ecc.size;
372 int eccbytes = chip->ecc.bytes; 372 int eccbytes = chip->ecc.bytes;
@@ -881,8 +881,6 @@ static int __devinit flctl_probe(struct platform_device *pdev)
881 flctl->hwecc = pdata->has_hwecc; 881 flctl->hwecc = pdata->has_hwecc;
882 flctl->holden = pdata->use_holden; 882 flctl->holden = pdata->use_holden;
883 883
884 nand->options = NAND_NO_AUTOINCR;
885
886 /* Set address of hardware control function */ 884 /* Set address of hardware control function */
887 /* 20 us command delay time */ 885 /* 20 us command delay time */
888 nand->chip_delay = 20; 886 nand->chip_delay = 20;
diff --git a/drivers/mtd/nand/sm_common.c b/drivers/mtd/nand/sm_common.c
index 774c3c266713..082bcdcd6bcf 100644
--- a/drivers/mtd/nand/sm_common.c
+++ b/drivers/mtd/nand/sm_common.c
@@ -94,17 +94,16 @@ static struct nand_flash_dev nand_smartmedia_flash_ids[] = {
94 {NULL,} 94 {NULL,}
95}; 95};
96 96
97#define XD_TYPEM (NAND_NO_AUTOINCR | NAND_BROKEN_XD)
98static struct nand_flash_dev nand_xd_flash_ids[] = { 97static struct nand_flash_dev nand_xd_flash_ids[] = {
99 98
100 {"xD 16MiB 3,3V", 0x73, 512, 16, 0x4000, 0}, 99 {"xD 16MiB 3,3V", 0x73, 512, 16, 0x4000, 0},
101 {"xD 32MiB 3,3V", 0x75, 512, 32, 0x4000, 0}, 100 {"xD 32MiB 3,3V", 0x75, 512, 32, 0x4000, 0},
102 {"xD 64MiB 3,3V", 0x76, 512, 64, 0x4000, 0}, 101 {"xD 64MiB 3,3V", 0x76, 512, 64, 0x4000, 0},
103 {"xD 128MiB 3,3V", 0x79, 512, 128, 0x4000, 0}, 102 {"xD 128MiB 3,3V", 0x79, 512, 128, 0x4000, 0},
104 {"xD 256MiB 3,3V", 0x71, 512, 256, 0x4000, XD_TYPEM}, 103 {"xD 256MiB 3,3V", 0x71, 512, 256, 0x4000, NAND_BROKEN_XD},
105 {"xD 512MiB 3,3V", 0xdc, 512, 512, 0x4000, XD_TYPEM}, 104 {"xD 512MiB 3,3V", 0xdc, 512, 512, 0x4000, NAND_BROKEN_XD},
106 {"xD 1GiB 3,3V", 0xd3, 512, 1024, 0x4000, XD_TYPEM}, 105 {"xD 1GiB 3,3V", 0xd3, 512, 1024, 0x4000, NAND_BROKEN_XD},
107 {"xD 2GiB 3,3V", 0xd5, 512, 2048, 0x4000, XD_TYPEM}, 106 {"xD 2GiB 3,3V", 0xd5, 512, 2048, 0x4000, NAND_BROKEN_XD},
108 {NULL,} 107 {NULL,}
109}; 108};
110 109
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index b3ce12ef359e..7153e0d27101 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -1201,7 +1201,8 @@ static int onenand_mlc_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1201 if (mtd->ecc_stats.failed - stats.failed) 1201 if (mtd->ecc_stats.failed - stats.failed)
1202 return -EBADMSG; 1202 return -EBADMSG;
1203 1203
1204 return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0; 1204 /* return max bitflips per ecc step; ONENANDs correct 1 bit only */
1205 return mtd->ecc_stats.corrected != stats.corrected ? 1 : 0;
1205} 1206}
1206 1207
1207/** 1208/**
@@ -1333,7 +1334,8 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from,
1333 if (mtd->ecc_stats.failed - stats.failed) 1334 if (mtd->ecc_stats.failed - stats.failed)
1334 return -EBADMSG; 1335 return -EBADMSG;
1335 1336
1336 return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0; 1337 /* return max bitflips per ecc step; ONENANDs correct 1 bit only */
1338 return mtd->ecc_stats.corrected != stats.corrected ? 1 : 0;
1337} 1339}
1338 1340
1339/** 1341/**
diff --git a/drivers/pinctrl/pinctrl-nomadik.c b/drivers/pinctrl/pinctrl-nomadik.c
index b8e01c3eaa95..b26395d16347 100644
--- a/drivers/pinctrl/pinctrl-nomadik.c
+++ b/drivers/pinctrl/pinctrl-nomadik.c
@@ -24,6 +24,7 @@
24#include <linux/irq.h> 24#include <linux/irq.h>
25#include <linux/irqdomain.h> 25#include <linux/irqdomain.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/of_device.h>
27#include <linux/pinctrl/pinctrl.h> 28#include <linux/pinctrl/pinctrl.h>
28#include <linux/pinctrl/pinmux.h> 29#include <linux/pinctrl/pinmux.h>
29#include <linux/pinctrl/pinconf.h> 30#include <linux/pinctrl/pinconf.h>
@@ -1688,18 +1689,34 @@ static struct pinctrl_desc nmk_pinctrl_desc = {
1688 .owner = THIS_MODULE, 1689 .owner = THIS_MODULE,
1689}; 1690};
1690 1691
1692static const struct of_device_id nmk_pinctrl_match[] = {
1693 {
1694 .compatible = "stericsson,nmk_pinctrl",
1695 .data = (void *)PINCTRL_NMK_DB8500,
1696 },
1697 {},
1698};
1699
1691static int __devinit nmk_pinctrl_probe(struct platform_device *pdev) 1700static int __devinit nmk_pinctrl_probe(struct platform_device *pdev)
1692{ 1701{
1693 const struct platform_device_id *platid = platform_get_device_id(pdev); 1702 const struct platform_device_id *platid = platform_get_device_id(pdev);
1703 struct device_node *np = pdev->dev.of_node;
1694 struct nmk_pinctrl *npct; 1704 struct nmk_pinctrl *npct;
1705 unsigned int version = 0;
1695 int i; 1706 int i;
1696 1707
1697 npct = devm_kzalloc(&pdev->dev, sizeof(*npct), GFP_KERNEL); 1708 npct = devm_kzalloc(&pdev->dev, sizeof(*npct), GFP_KERNEL);
1698 if (!npct) 1709 if (!npct)
1699 return -ENOMEM; 1710 return -ENOMEM;
1700 1711
1712 if (platid)
1713 version = platid->driver_data;
1714 else if (np)
1715 version = (unsigned int)
1716 of_match_device(nmk_pinctrl_match, &pdev->dev)->data;
1717
1701 /* Poke in other ASIC variants here */ 1718 /* Poke in other ASIC variants here */
1702 if (platid->driver_data == PINCTRL_NMK_DB8500) 1719 if (version == PINCTRL_NMK_DB8500)
1703 nmk_pinctrl_db8500_init(&npct->soc); 1720 nmk_pinctrl_db8500_init(&npct->soc);
1704 1721
1705 /* 1722 /*
@@ -1758,6 +1775,7 @@ static struct platform_driver nmk_pinctrl_driver = {
1758 .driver = { 1775 .driver = {
1759 .owner = THIS_MODULE, 1776 .owner = THIS_MODULE,
1760 .name = "pinctrl-nomadik", 1777 .name = "pinctrl-nomadik",
1778 .of_match_table = nmk_pinctrl_match,
1761 }, 1779 },
1762 .probe = nmk_pinctrl_probe, 1780 .probe = nmk_pinctrl_probe,
1763 .id_table = nmk_pinctrl_id, 1781 .id_table = nmk_pinctrl_id,
diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
index c1a3fd8e1243..ce875dc365e5 100644
--- a/drivers/platform/x86/acer-wmi.c
+++ b/drivers/platform/x86/acer-wmi.c
@@ -523,6 +523,30 @@ static const struct dmi_system_id video_vendor_dmi_table[] = {
523 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"), 523 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
524 }, 524 },
525 }, 525 },
526 {
527 .callback = video_set_backlight_video_vendor,
528 .ident = "Acer Extensa 5235",
529 .matches = {
530 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
531 DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
532 },
533 },
534 {
535 .callback = video_set_backlight_video_vendor,
536 .ident = "Acer TravelMate 5760",
537 .matches = {
538 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
539 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
540 },
541 },
542 {
543 .callback = video_set_backlight_video_vendor,
544 .ident = "Acer Aspire 5750",
545 .matches = {
546 DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
547 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
548 },
549 },
526 {} 550 {}
527}; 551};
528 552
diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c
index 8a582bdfdc76..694a15a56230 100644
--- a/drivers/platform/x86/apple-gmux.c
+++ b/drivers/platform/x86/apple-gmux.c
@@ -87,6 +87,9 @@ static int gmux_update_status(struct backlight_device *bd)
87 struct apple_gmux_data *gmux_data = bl_get_data(bd); 87 struct apple_gmux_data *gmux_data = bl_get_data(bd);
88 u32 brightness = bd->props.brightness; 88 u32 brightness = bd->props.brightness;
89 89
90 if (bd->props.state & BL_CORE_SUSPENDED)
91 return 0;
92
90 /* 93 /*
91 * Older gmux versions require writing out lower bytes first then 94 * Older gmux versions require writing out lower bytes first then
92 * setting the upper byte to 0 to flush the values. Newer versions 95 * setting the upper byte to 0 to flush the values. Newer versions
@@ -102,6 +105,7 @@ static int gmux_update_status(struct backlight_device *bd)
102} 105}
103 106
104static const struct backlight_ops gmux_bl_ops = { 107static const struct backlight_ops gmux_bl_ops = {
108 .options = BL_CORE_SUSPENDRESUME,
105 .get_brightness = gmux_get_brightness, 109 .get_brightness = gmux_get_brightness,
106 .update_status = gmux_update_status, 110 .update_status = gmux_update_status,
107}; 111};
diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
index e6c08ee8d46c..5f78aac9b163 100644
--- a/drivers/platform/x86/dell-laptop.c
+++ b/drivers/platform/x86/dell-laptop.c
@@ -21,7 +21,6 @@
21#include <linux/err.h> 21#include <linux/err.h>
22#include <linux/dmi.h> 22#include <linux/dmi.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/rfkill.h>
25#include <linux/power_supply.h> 24#include <linux/power_supply.h>
26#include <linux/acpi.h> 25#include <linux/acpi.h>
27#include <linux/mm.h> 26#include <linux/mm.h>
@@ -90,11 +89,8 @@ static struct platform_driver platform_driver = {
90 89
91static struct platform_device *platform_device; 90static struct platform_device *platform_device;
92static struct backlight_device *dell_backlight_device; 91static struct backlight_device *dell_backlight_device;
93static struct rfkill *wifi_rfkill;
94static struct rfkill *bluetooth_rfkill;
95static struct rfkill *wwan_rfkill;
96 92
97static const struct dmi_system_id __initdata dell_device_table[] = { 93static const struct dmi_system_id dell_device_table[] __initconst = {
98 { 94 {
99 .ident = "Dell laptop", 95 .ident = "Dell laptop",
100 .matches = { 96 .matches = {
@@ -119,96 +115,94 @@ static const struct dmi_system_id __initdata dell_device_table[] = {
119}; 115};
120MODULE_DEVICE_TABLE(dmi, dell_device_table); 116MODULE_DEVICE_TABLE(dmi, dell_device_table);
121 117
122static struct dmi_system_id __devinitdata dell_blacklist[] = { 118static struct dmi_system_id __devinitdata dell_quirks[] = {
123 /* Supported by compal-laptop */
124 {
125 .ident = "Dell Mini 9",
126 .matches = {
127 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
128 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
129 },
130 },
131 { 119 {
132 .ident = "Dell Mini 10", 120 .callback = dmi_matched,
121 .ident = "Dell Vostro V130",
133 .matches = { 122 .matches = {
134 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 123 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
135 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"), 124 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V130"),
136 }, 125 },
126 .driver_data = &quirk_dell_vostro_v130,
137 }, 127 },
138 { 128 {
139 .ident = "Dell Mini 10v", 129 .callback = dmi_matched,
130 .ident = "Dell Vostro V131",
140 .matches = { 131 .matches = {
141 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 132 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
142 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"), 133 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
143 }, 134 },
135 .driver_data = &quirk_dell_vostro_v130,
144 }, 136 },
145 { 137 {
146 .ident = "Dell Mini 1012", 138 .callback = dmi_matched,
139 .ident = "Dell Vostro 3350",
147 .matches = { 140 .matches = {
148 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 141 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
149 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1012"), 142 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3350"),
150 }, 143 },
144 .driver_data = &quirk_dell_vostro_v130,
151 }, 145 },
152 { 146 {
153 .ident = "Dell Inspiron 11z", 147 .callback = dmi_matched,
148 .ident = "Dell Vostro 3555",
154 .matches = { 149 .matches = {
155 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 150 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
156 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"), 151 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3555"),
157 }, 152 },
153 .driver_data = &quirk_dell_vostro_v130,
158 }, 154 },
159 { 155 {
160 .ident = "Dell Mini 12", 156 .callback = dmi_matched,
157 .ident = "Dell Inspiron N311z",
161 .matches = { 158 .matches = {
162 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 159 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
163 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"), 160 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N311z"),
164 }, 161 },
162 .driver_data = &quirk_dell_vostro_v130,
165 }, 163 },
166 {}
167};
168
169static struct dmi_system_id __devinitdata dell_quirks[] = {
170 { 164 {
171 .callback = dmi_matched, 165 .callback = dmi_matched,
172 .ident = "Dell Vostro V130", 166 .ident = "Dell Inspiron M5110",
173 .matches = { 167 .matches = {
174 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 168 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
175 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V130"), 169 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"),
176 }, 170 },
177 .driver_data = &quirk_dell_vostro_v130, 171 .driver_data = &quirk_dell_vostro_v130,
178 }, 172 },
179 { 173 {
180 .callback = dmi_matched, 174 .callback = dmi_matched,
181 .ident = "Dell Vostro V131", 175 .ident = "Dell Vostro 3360",
182 .matches = { 176 .matches = {
183 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 177 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
184 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"), 178 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
185 }, 179 },
186 .driver_data = &quirk_dell_vostro_v130, 180 .driver_data = &quirk_dell_vostro_v130,
187 }, 181 },
188 { 182 {
189 .callback = dmi_matched, 183 .callback = dmi_matched,
190 .ident = "Dell Vostro 3555", 184 .ident = "Dell Vostro 3460",
191 .matches = { 185 .matches = {
192 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 186 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
193 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3555"), 187 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3460"),
194 }, 188 },
195 .driver_data = &quirk_dell_vostro_v130, 189 .driver_data = &quirk_dell_vostro_v130,
196 }, 190 },
197 { 191 {
198 .callback = dmi_matched, 192 .callback = dmi_matched,
199 .ident = "Dell Inspiron N311z", 193 .ident = "Dell Vostro 3560",
200 .matches = { 194 .matches = {
201 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 195 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
202 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N311z"), 196 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3560"),
203 }, 197 },
204 .driver_data = &quirk_dell_vostro_v130, 198 .driver_data = &quirk_dell_vostro_v130,
205 }, 199 },
206 { 200 {
207 .callback = dmi_matched, 201 .callback = dmi_matched,
208 .ident = "Dell Inspiron M5110", 202 .ident = "Dell Vostro 3450",
209 .matches = { 203 .matches = {
210 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 204 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
211 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"), 205 DMI_MATCH(DMI_PRODUCT_NAME, "Dell System Vostro 3450"),
212 }, 206 },
213 .driver_data = &quirk_dell_vostro_v130, 207 .driver_data = &quirk_dell_vostro_v130,
214 }, 208 },
@@ -305,94 +299,6 @@ dell_send_request(struct calling_interface_buffer *buffer, int class,
305 return buffer; 299 return buffer;
306} 300}
307 301
308/* Derived from information in DellWirelessCtl.cpp:
309 Class 17, select 11 is radio control. It returns an array of 32-bit values.
310
311 Input byte 0 = 0: Wireless information
312
313 result[0]: return code
314 result[1]:
315 Bit 0: Hardware switch supported
316 Bit 1: Wifi locator supported
317 Bit 2: Wifi is supported
318 Bit 3: Bluetooth is supported
319 Bit 4: WWAN is supported
320 Bit 5: Wireless keyboard supported
321 Bits 6-7: Reserved
322 Bit 8: Wifi is installed
323 Bit 9: Bluetooth is installed
324 Bit 10: WWAN is installed
325 Bits 11-15: Reserved
326 Bit 16: Hardware switch is on
327 Bit 17: Wifi is blocked
328 Bit 18: Bluetooth is blocked
329 Bit 19: WWAN is blocked
330 Bits 20-31: Reserved
331 result[2]: NVRAM size in bytes
332 result[3]: NVRAM format version number
333
334 Input byte 0 = 2: Wireless switch configuration
335 result[0]: return code
336 result[1]:
337 Bit 0: Wifi controlled by switch
338 Bit 1: Bluetooth controlled by switch
339 Bit 2: WWAN controlled by switch
340 Bits 3-6: Reserved
341 Bit 7: Wireless switch config locked
342 Bit 8: Wifi locator enabled
343 Bits 9-14: Reserved
344 Bit 15: Wifi locator setting locked
345 Bits 16-31: Reserved
346*/
347
348static int dell_rfkill_set(void *data, bool blocked)
349{
350 int disable = blocked ? 1 : 0;
351 unsigned long radio = (unsigned long)data;
352 int hwswitch_bit = (unsigned long)data - 1;
353 int ret = 0;
354
355 get_buffer();
356 dell_send_request(buffer, 17, 11);
357
358 /* If the hardware switch controls this radio, and the hardware
359 switch is disabled, don't allow changing the software state */
360 if ((hwswitch_state & BIT(hwswitch_bit)) &&
361 !(buffer->output[1] & BIT(16))) {
362 ret = -EINVAL;
363 goto out;
364 }
365
366 buffer->input[0] = (1 | (radio<<8) | (disable << 16));
367 dell_send_request(buffer, 17, 11);
368
369out:
370 release_buffer();
371 return ret;
372}
373
374static void dell_rfkill_query(struct rfkill *rfkill, void *data)
375{
376 int status;
377 int bit = (unsigned long)data + 16;
378 int hwswitch_bit = (unsigned long)data - 1;
379
380 get_buffer();
381 dell_send_request(buffer, 17, 11);
382 status = buffer->output[1];
383 release_buffer();
384
385 rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
386
387 if (hwswitch_state & (BIT(hwswitch_bit)))
388 rfkill_set_hw_state(rfkill, !(status & BIT(16)));
389}
390
391static const struct rfkill_ops dell_rfkill_ops = {
392 .set_block = dell_rfkill_set,
393 .query = dell_rfkill_query,
394};
395
396static struct dentry *dell_laptop_dir; 302static struct dentry *dell_laptop_dir;
397 303
398static int dell_debugfs_show(struct seq_file *s, void *data) 304static int dell_debugfs_show(struct seq_file *s, void *data)
@@ -462,108 +368,6 @@ static const struct file_operations dell_debugfs_fops = {
462 .release = single_release, 368 .release = single_release,
463}; 369};
464 370
465static void dell_update_rfkill(struct work_struct *ignored)
466{
467 if (wifi_rfkill)
468 dell_rfkill_query(wifi_rfkill, (void *)1);
469 if (bluetooth_rfkill)
470 dell_rfkill_query(bluetooth_rfkill, (void *)2);
471 if (wwan_rfkill)
472 dell_rfkill_query(wwan_rfkill, (void *)3);
473}
474static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
475
476
477static int __init dell_setup_rfkill(void)
478{
479 int status;
480 int ret;
481
482 if (dmi_check_system(dell_blacklist)) {
483 pr_info("Blacklisted hardware detected - not enabling rfkill\n");
484 return 0;
485 }
486
487 get_buffer();
488 dell_send_request(buffer, 17, 11);
489 status = buffer->output[1];
490 buffer->input[0] = 0x2;
491 dell_send_request(buffer, 17, 11);
492 hwswitch_state = buffer->output[1];
493 release_buffer();
494
495 if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {
496 wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev,
497 RFKILL_TYPE_WLAN,
498 &dell_rfkill_ops, (void *) 1);
499 if (!wifi_rfkill) {
500 ret = -ENOMEM;
501 goto err_wifi;
502 }
503 ret = rfkill_register(wifi_rfkill);
504 if (ret)
505 goto err_wifi;
506 }
507
508 if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) {
509 bluetooth_rfkill = rfkill_alloc("dell-bluetooth",
510 &platform_device->dev,
511 RFKILL_TYPE_BLUETOOTH,
512 &dell_rfkill_ops, (void *) 2);
513 if (!bluetooth_rfkill) {
514 ret = -ENOMEM;
515 goto err_bluetooth;
516 }
517 ret = rfkill_register(bluetooth_rfkill);
518 if (ret)
519 goto err_bluetooth;
520 }
521
522 if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) {
523 wwan_rfkill = rfkill_alloc("dell-wwan",
524 &platform_device->dev,
525 RFKILL_TYPE_WWAN,
526 &dell_rfkill_ops, (void *) 3);
527 if (!wwan_rfkill) {
528 ret = -ENOMEM;
529 goto err_wwan;
530 }
531 ret = rfkill_register(wwan_rfkill);
532 if (ret)
533 goto err_wwan;
534 }
535
536 return 0;
537err_wwan:
538 rfkill_destroy(wwan_rfkill);
539 if (bluetooth_rfkill)
540 rfkill_unregister(bluetooth_rfkill);
541err_bluetooth:
542 rfkill_destroy(bluetooth_rfkill);
543 if (wifi_rfkill)
544 rfkill_unregister(wifi_rfkill);
545err_wifi:
546 rfkill_destroy(wifi_rfkill);
547
548 return ret;
549}
550
551static void dell_cleanup_rfkill(void)
552{
553 if (wifi_rfkill) {
554 rfkill_unregister(wifi_rfkill);
555 rfkill_destroy(wifi_rfkill);
556 }
557 if (bluetooth_rfkill) {
558 rfkill_unregister(bluetooth_rfkill);
559 rfkill_destroy(bluetooth_rfkill);
560 }
561 if (wwan_rfkill) {
562 rfkill_unregister(wwan_rfkill);
563 rfkill_destroy(wwan_rfkill);
564 }
565}
566
567static int dell_send_intensity(struct backlight_device *bd) 371static int dell_send_intensity(struct backlight_device *bd)
568{ 372{
569 int ret = 0; 373 int ret = 0;
@@ -655,30 +459,6 @@ static void touchpad_led_exit(void)
655 led_classdev_unregister(&touchpad_led); 459 led_classdev_unregister(&touchpad_led);
656} 460}
657 461
658static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
659 struct serio *port)
660{
661 static bool extended;
662
663 if (str & 0x20)
664 return false;
665
666 if (unlikely(data == 0xe0)) {
667 extended = true;
668 return false;
669 } else if (unlikely(extended)) {
670 switch (data) {
671 case 0x8:
672 schedule_delayed_work(&dell_rfkill_work,
673 round_jiffies_relative(HZ));
674 break;
675 }
676 extended = false;
677 }
678
679 return false;
680}
681
682static int __init dell_init(void) 462static int __init dell_init(void)
683{ 463{
684 int max_intensity = 0; 464 int max_intensity = 0;
@@ -720,26 +500,10 @@ static int __init dell_init(void)
720 goto fail_buffer; 500 goto fail_buffer;
721 buffer = page_address(bufferpage); 501 buffer = page_address(bufferpage);
722 502
723 ret = dell_setup_rfkill();
724
725 if (ret) {
726 pr_warn("Unable to setup rfkill\n");
727 goto fail_rfkill;
728 }
729
730 ret = i8042_install_filter(dell_laptop_i8042_filter);
731 if (ret) {
732 pr_warn("Unable to install key filter\n");
733 goto fail_filter;
734 }
735
736 if (quirks && quirks->touchpad_led) 503 if (quirks && quirks->touchpad_led)
737 touchpad_led_init(&platform_device->dev); 504 touchpad_led_init(&platform_device->dev);
738 505
739 dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL); 506 dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL);
740 if (dell_laptop_dir != NULL)
741 debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL,
742 &dell_debugfs_fops);
743 507
744#ifdef CONFIG_ACPI 508#ifdef CONFIG_ACPI
745 /* In the event of an ACPI backlight being available, don't 509 /* In the event of an ACPI backlight being available, don't
@@ -782,11 +546,6 @@ static int __init dell_init(void)
782 return 0; 546 return 0;
783 547
784fail_backlight: 548fail_backlight:
785 i8042_remove_filter(dell_laptop_i8042_filter);
786 cancel_delayed_work_sync(&dell_rfkill_work);
787fail_filter:
788 dell_cleanup_rfkill();
789fail_rfkill:
790 free_page((unsigned long)bufferpage); 549 free_page((unsigned long)bufferpage);
791fail_buffer: 550fail_buffer:
792 platform_device_del(platform_device); 551 platform_device_del(platform_device);
@@ -804,10 +563,7 @@ static void __exit dell_exit(void)
804 debugfs_remove_recursive(dell_laptop_dir); 563 debugfs_remove_recursive(dell_laptop_dir);
805 if (quirks && quirks->touchpad_led) 564 if (quirks && quirks->touchpad_led)
806 touchpad_led_exit(); 565 touchpad_led_exit();
807 i8042_remove_filter(dell_laptop_i8042_filter);
808 cancel_delayed_work_sync(&dell_rfkill_work);
809 backlight_device_unregister(dell_backlight_device); 566 backlight_device_unregister(dell_backlight_device);
810 dell_cleanup_rfkill();
811 if (platform_device) { 567 if (platform_device) {
812 platform_device_unregister(platform_device); 568 platform_device_unregister(platform_device);
813 platform_driver_unregister(&platform_driver); 569 platform_driver_unregister(&platform_driver);
diff --git a/drivers/platform/x86/fujitsu-tablet.c b/drivers/platform/x86/fujitsu-tablet.c
index 580d80a73c3a..da267eae8ba8 100644
--- a/drivers/platform/x86/fujitsu-tablet.c
+++ b/drivers/platform/x86/fujitsu-tablet.c
@@ -16,6 +16,8 @@
16 * 59 Temple Place Suite 330, Boston, MA 02111-1307, USA. 16 * 59 Temple Place Suite 330, Boston, MA 02111-1307, USA.
17 */ 17 */
18 18
19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
19#include <linux/kernel.h> 21#include <linux/kernel.h>
20#include <linux/module.h> 22#include <linux/module.h>
21#include <linux/init.h> 23#include <linux/init.h>
@@ -34,7 +36,8 @@
34#define ACPI_FUJITSU_CLASS "fujitsu" 36#define ACPI_FUJITSU_CLASS "fujitsu"
35 37
36#define INVERT_TABLET_MODE_BIT 0x01 38#define INVERT_TABLET_MODE_BIT 0x01
37#define FORCE_TABLET_MODE_IF_UNDOCK 0x02 39#define INVERT_DOCK_STATE_BIT 0x02
40#define FORCE_TABLET_MODE_IF_UNDOCK 0x04
38 41
39#define KEYMAP_LEN 16 42#define KEYMAP_LEN 16
40 43
@@ -161,6 +164,8 @@ static void fujitsu_send_state(void)
161 state = fujitsu_read_register(0xdd); 164 state = fujitsu_read_register(0xdd);
162 165
163 dock = state & 0x02; 166 dock = state & 0x02;
167 if (fujitsu.config.quirks & INVERT_DOCK_STATE_BIT)
168 dock = !dock;
164 169
165 if ((fujitsu.config.quirks & FORCE_TABLET_MODE_IF_UNDOCK) && (!dock)) { 170 if ((fujitsu.config.quirks & FORCE_TABLET_MODE_IF_UNDOCK) && (!dock)) {
166 tablet_mode = 1; 171 tablet_mode = 1;
@@ -221,9 +226,6 @@ static int __devinit input_fujitsu_setup(struct device *parent,
221 input_set_capability(idev, EV_SW, SW_DOCK); 226 input_set_capability(idev, EV_SW, SW_DOCK);
222 input_set_capability(idev, EV_SW, SW_TABLET_MODE); 227 input_set_capability(idev, EV_SW, SW_TABLET_MODE);
223 228
224 input_set_capability(idev, EV_SW, SW_DOCK);
225 input_set_capability(idev, EV_SW, SW_TABLET_MODE);
226
227 error = input_register_device(idev); 229 error = input_register_device(idev);
228 if (error) { 230 if (error) {
229 input_free_device(idev); 231 input_free_device(idev);
@@ -275,25 +277,31 @@ static irqreturn_t fujitsu_interrupt(int irq, void *dev_id)
275 return IRQ_HANDLED; 277 return IRQ_HANDLED;
276} 278}
277 279
278static int __devinit fujitsu_dmi_default(const struct dmi_system_id *dmi) 280static void __devinit fujitsu_dmi_common(const struct dmi_system_id *dmi)
279{ 281{
280 printk(KERN_INFO MODULENAME ": %s\n", dmi->ident); 282 pr_info("%s\n", dmi->ident);
281 memcpy(fujitsu.config.keymap, dmi->driver_data, 283 memcpy(fujitsu.config.keymap, dmi->driver_data,
282 sizeof(fujitsu.config.keymap)); 284 sizeof(fujitsu.config.keymap));
285}
286
287static int __devinit fujitsu_dmi_lifebook(const struct dmi_system_id *dmi)
288{
289 fujitsu_dmi_common(dmi);
290 fujitsu.config.quirks |= INVERT_TABLET_MODE_BIT;
283 return 1; 291 return 1;
284} 292}
285 293
286static int __devinit fujitsu_dmi_stylistic(const struct dmi_system_id *dmi) 294static int __devinit fujitsu_dmi_stylistic(const struct dmi_system_id *dmi)
287{ 295{
288 fujitsu_dmi_default(dmi); 296 fujitsu_dmi_common(dmi);
289 fujitsu.config.quirks |= FORCE_TABLET_MODE_IF_UNDOCK; 297 fujitsu.config.quirks |= FORCE_TABLET_MODE_IF_UNDOCK;
290 fujitsu.config.quirks |= INVERT_TABLET_MODE_BIT; 298 fujitsu.config.quirks |= INVERT_DOCK_STATE_BIT;
291 return 1; 299 return 1;
292} 300}
293 301
294static struct dmi_system_id dmi_ids[] __initconst = { 302static struct dmi_system_id dmi_ids[] __initconst = {
295 { 303 {
296 .callback = fujitsu_dmi_default, 304 .callback = fujitsu_dmi_lifebook,
297 .ident = "Fujitsu Siemens P/T Series", 305 .ident = "Fujitsu Siemens P/T Series",
298 .matches = { 306 .matches = {
299 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), 307 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
@@ -302,7 +310,7 @@ static struct dmi_system_id dmi_ids[] __initconst = {
302 .driver_data = keymap_Lifebook_Tseries 310 .driver_data = keymap_Lifebook_Tseries
303 }, 311 },
304 { 312 {
305 .callback = fujitsu_dmi_default, 313 .callback = fujitsu_dmi_lifebook,
306 .ident = "Fujitsu Lifebook T Series", 314 .ident = "Fujitsu Lifebook T Series",
307 .matches = { 315 .matches = {
308 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), 316 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
@@ -320,7 +328,7 @@ static struct dmi_system_id dmi_ids[] __initconst = {
320 .driver_data = keymap_Stylistic_Tseries 328 .driver_data = keymap_Stylistic_Tseries
321 }, 329 },
322 { 330 {
323 .callback = fujitsu_dmi_default, 331 .callback = fujitsu_dmi_lifebook,
324 .ident = "Fujitsu LifeBook U810", 332 .ident = "Fujitsu LifeBook U810",
325 .matches = { 333 .matches = {
326 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), 334 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
@@ -347,7 +355,7 @@ static struct dmi_system_id dmi_ids[] __initconst = {
347 .driver_data = keymap_Stylistic_ST5xxx 355 .driver_data = keymap_Stylistic_ST5xxx
348 }, 356 },
349 { 357 {
350 .callback = fujitsu_dmi_default, 358 .callback = fujitsu_dmi_lifebook,
351 .ident = "Unknown (using defaults)", 359 .ident = "Unknown (using defaults)",
352 .matches = { 360 .matches = {
353 DMI_MATCH(DMI_SYS_VENDOR, ""), 361 DMI_MATCH(DMI_SYS_VENDOR, ""),
@@ -473,6 +481,6 @@ module_exit(fujitsu_module_exit);
473MODULE_AUTHOR("Robert Gerlach <khnz@gmx.de>"); 481MODULE_AUTHOR("Robert Gerlach <khnz@gmx.de>");
474MODULE_DESCRIPTION("Fujitsu tablet pc extras driver"); 482MODULE_DESCRIPTION("Fujitsu tablet pc extras driver");
475MODULE_LICENSE("GPL"); 483MODULE_LICENSE("GPL");
476MODULE_VERSION("2.4"); 484MODULE_VERSION("2.5");
477 485
478MODULE_DEVICE_TABLE(acpi, fujitsu_ids); 486MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
diff --git a/drivers/platform/x86/hdaps.c b/drivers/platform/x86/hdaps.c
index 7387f97a2941..24a3ae065f1b 100644
--- a/drivers/platform/x86/hdaps.c
+++ b/drivers/platform/x86/hdaps.c
@@ -2,7 +2,7 @@
2 * hdaps.c - driver for IBM's Hard Drive Active Protection System 2 * hdaps.c - driver for IBM's Hard Drive Active Protection System
3 * 3 *
4 * Copyright (C) 2005 Robert Love <rml@novell.com> 4 * Copyright (C) 2005 Robert Love <rml@novell.com>
5 * Copyright (C) 2005 Jesper Juhl <jesper.juhl@gmail.com> 5 * Copyright (C) 2005 Jesper Juhl <jj@chaosbits.net>
6 * 6 *
7 * The HardDisk Active Protection System (hdaps) is present in IBM ThinkPads 7 * The HardDisk Active Protection System (hdaps) is present in IBM ThinkPads
8 * starting with the R40, T41, and X40. It provides a basic two-axis 8 * starting with the R40, T41, and X40. It provides a basic two-axis
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index e2faa3cbb792..387183a2d6dd 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -634,6 +634,8 @@ static int __devinit hp_wmi_rfkill_setup(struct platform_device *device)
634 RFKILL_TYPE_WLAN, 634 RFKILL_TYPE_WLAN,
635 &hp_wmi_rfkill_ops, 635 &hp_wmi_rfkill_ops,
636 (void *) HPWMI_WIFI); 636 (void *) HPWMI_WIFI);
637 if (!wifi_rfkill)
638 return -ENOMEM;
637 rfkill_init_sw_state(wifi_rfkill, 639 rfkill_init_sw_state(wifi_rfkill,
638 hp_wmi_get_sw_state(HPWMI_WIFI)); 640 hp_wmi_get_sw_state(HPWMI_WIFI));
639 rfkill_set_hw_state(wifi_rfkill, 641 rfkill_set_hw_state(wifi_rfkill,
@@ -648,6 +650,10 @@ static int __devinit hp_wmi_rfkill_setup(struct platform_device *device)
648 RFKILL_TYPE_BLUETOOTH, 650 RFKILL_TYPE_BLUETOOTH,
649 &hp_wmi_rfkill_ops, 651 &hp_wmi_rfkill_ops,
650 (void *) HPWMI_BLUETOOTH); 652 (void *) HPWMI_BLUETOOTH);
653 if (!bluetooth_rfkill) {
654 err = -ENOMEM;
655 goto register_wifi_error;
656 }
651 rfkill_init_sw_state(bluetooth_rfkill, 657 rfkill_init_sw_state(bluetooth_rfkill,
652 hp_wmi_get_sw_state(HPWMI_BLUETOOTH)); 658 hp_wmi_get_sw_state(HPWMI_BLUETOOTH));
653 rfkill_set_hw_state(bluetooth_rfkill, 659 rfkill_set_hw_state(bluetooth_rfkill,
@@ -662,6 +668,10 @@ static int __devinit hp_wmi_rfkill_setup(struct platform_device *device)
662 RFKILL_TYPE_WWAN, 668 RFKILL_TYPE_WWAN,
663 &hp_wmi_rfkill_ops, 669 &hp_wmi_rfkill_ops,
664 (void *) HPWMI_WWAN); 670 (void *) HPWMI_WWAN);
671 if (!wwan_rfkill) {
672 err = -ENOMEM;
673 goto register_bluetooth_error;
674 }
665 rfkill_init_sw_state(wwan_rfkill, 675 rfkill_init_sw_state(wwan_rfkill,
666 hp_wmi_get_sw_state(HPWMI_WWAN)); 676 hp_wmi_get_sw_state(HPWMI_WWAN));
667 rfkill_set_hw_state(wwan_rfkill, 677 rfkill_set_hw_state(wwan_rfkill,
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index ac902f7a9baa..4f20f8dd3d7c 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -194,7 +194,6 @@ static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data)
194/* 194/*
195 * debugfs 195 * debugfs
196 */ 196 */
197#define DEBUGFS_EVENT_LEN (4096)
198static int debugfs_status_show(struct seq_file *s, void *data) 197static int debugfs_status_show(struct seq_file *s, void *data)
199{ 198{
200 unsigned long value; 199 unsigned long value;
@@ -315,7 +314,7 @@ static int __devinit ideapad_debugfs_init(struct ideapad_private *priv)
315 node = debugfs_create_file("status", S_IRUGO, priv->debug, NULL, 314 node = debugfs_create_file("status", S_IRUGO, priv->debug, NULL,
316 &debugfs_status_fops); 315 &debugfs_status_fops);
317 if (!node) { 316 if (!node) {
318 pr_err("failed to create event in debugfs"); 317 pr_err("failed to create status in debugfs");
319 goto errout; 318 goto errout;
320 } 319 }
321 320
@@ -785,6 +784,10 @@ static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event)
785 case 9: 784 case 9:
786 ideapad_sync_rfk_state(priv); 785 ideapad_sync_rfk_state(priv);
787 break; 786 break;
787 case 13:
788 case 6:
789 ideapad_input_report(priv, vpc_bit);
790 break;
788 case 4: 791 case 4:
789 ideapad_backlight_notify_brightness(priv); 792 ideapad_backlight_notify_brightness(priv);
790 break; 793 break;
@@ -795,7 +798,7 @@ static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event)
795 ideapad_backlight_notify_power(priv); 798 ideapad_backlight_notify_power(priv);
796 break; 799 break;
797 default: 800 default:
798 ideapad_input_report(priv, vpc_bit); 801 pr_info("Unknown event: %lu\n", vpc_bit);
799 } 802 }
800 } 803 }
801 } 804 }
diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index 8a51795aa02a..210d4ae547c2 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -141,6 +141,27 @@ MODULE_PARM_DESC(kbd_backlight_timeout,
141 "(default: 0)"); 141 "(default: 0)");
142 142
143static void sony_nc_kbd_backlight_resume(void); 143static void sony_nc_kbd_backlight_resume(void);
144static int sony_nc_kbd_backlight_setup(struct platform_device *pd,
145 unsigned int handle);
146static void sony_nc_kbd_backlight_cleanup(struct platform_device *pd);
147
148static int sony_nc_battery_care_setup(struct platform_device *pd,
149 unsigned int handle);
150static void sony_nc_battery_care_cleanup(struct platform_device *pd);
151
152static int sony_nc_thermal_setup(struct platform_device *pd);
153static void sony_nc_thermal_cleanup(struct platform_device *pd);
154static void sony_nc_thermal_resume(void);
155
156static int sony_nc_lid_resume_setup(struct platform_device *pd);
157static void sony_nc_lid_resume_cleanup(struct platform_device *pd);
158
159static int sony_nc_highspeed_charging_setup(struct platform_device *pd);
160static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd);
161
162static int sony_nc_touchpad_setup(struct platform_device *pd,
163 unsigned int handle);
164static void sony_nc_touchpad_cleanup(struct platform_device *pd);
144 165
145enum sony_nc_rfkill { 166enum sony_nc_rfkill {
146 SONY_WIFI, 167 SONY_WIFI,
@@ -153,6 +174,9 @@ enum sony_nc_rfkill {
153static int sony_rfkill_handle; 174static int sony_rfkill_handle;
154static struct rfkill *sony_rfkill_devices[N_SONY_RFKILL]; 175static struct rfkill *sony_rfkill_devices[N_SONY_RFKILL];
155static int sony_rfkill_address[N_SONY_RFKILL] = {0x300, 0x500, 0x700, 0x900}; 176static int sony_rfkill_address[N_SONY_RFKILL] = {0x300, 0x500, 0x700, 0x900};
177static int sony_nc_rfkill_setup(struct acpi_device *device,
178 unsigned int handle);
179static void sony_nc_rfkill_cleanup(void);
156static void sony_nc_rfkill_update(void); 180static void sony_nc_rfkill_update(void);
157 181
158/*********** Input Devices ***********/ 182/*********** Input Devices ***********/
@@ -691,59 +715,97 @@ static struct acpi_device *sony_nc_acpi_device = NULL;
691 715
692/* 716/*
693 * acpi_evaluate_object wrappers 717 * acpi_evaluate_object wrappers
718 * all useful calls into SNC methods take one or zero parameters and return
719 * integers or arrays.
694 */ 720 */
695static int acpi_callgetfunc(acpi_handle handle, char *name, int *result) 721static union acpi_object *__call_snc_method(acpi_handle handle, char *method,
722 u64 *value)
696{ 723{
697 struct acpi_buffer output; 724 union acpi_object *result = NULL;
698 union acpi_object out_obj; 725 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
699 acpi_status status; 726 acpi_status status;
700 727
701 output.length = sizeof(out_obj); 728 if (value) {
702 output.pointer = &out_obj; 729 struct acpi_object_list params;
730 union acpi_object in;
731 in.type = ACPI_TYPE_INTEGER;
732 in.integer.value = *value;
733 params.count = 1;
734 params.pointer = &in;
735 status = acpi_evaluate_object(handle, method, &params, &output);
736 dprintk("__call_snc_method: [%s:0x%.8x%.8x]\n", method,
737 (unsigned int)(*value >> 32),
738 (unsigned int)*value & 0xffffffff);
739 } else {
740 status = acpi_evaluate_object(handle, method, NULL, &output);
741 dprintk("__call_snc_method: [%s]\n", method);
742 }
703 743
704 status = acpi_evaluate_object(handle, name, NULL, &output); 744 if (ACPI_FAILURE(status)) {
705 if ((status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER)) { 745 pr_err("Failed to evaluate [%s]\n", method);
706 *result = out_obj.integer.value; 746 return NULL;
707 return 0;
708 } 747 }
709 748
710 pr_warn("acpi_callreadfunc failed\n"); 749 result = (union acpi_object *) output.pointer;
750 if (!result)
751 dprintk("No return object [%s]\n", method);
711 752
712 return -1; 753 return result;
713} 754}
714 755
715static int acpi_callsetfunc(acpi_handle handle, char *name, int value, 756static int sony_nc_int_call(acpi_handle handle, char *name, int *value,
716 int *result) 757 int *result)
717{ 758{
718 struct acpi_object_list params; 759 union acpi_object *object = NULL;
719 union acpi_object in_obj; 760 if (value) {
720 struct acpi_buffer output; 761 u64 v = *value;
721 union acpi_object out_obj; 762 object = __call_snc_method(handle, name, &v);
722 acpi_status status; 763 } else
723 764 object = __call_snc_method(handle, name, NULL);
724 params.count = 1;
725 params.pointer = &in_obj;
726 in_obj.type = ACPI_TYPE_INTEGER;
727 in_obj.integer.value = value;
728 765
729 output.length = sizeof(out_obj); 766 if (!object)
730 output.pointer = &out_obj; 767 return -EINVAL;
731 768
732 status = acpi_evaluate_object(handle, name, &params, &output); 769 if (object->type != ACPI_TYPE_INTEGER) {
733 if (status == AE_OK) { 770 pr_warn("Invalid acpi_object: expected 0x%x got 0x%x\n",
734 if (result != NULL) { 771 ACPI_TYPE_INTEGER, object->type);
735 if (out_obj.type != ACPI_TYPE_INTEGER) { 772 kfree(object);
736 pr_warn("acpi_evaluate_object bad return type\n"); 773 return -EINVAL;
737 return -1;
738 }
739 *result = out_obj.integer.value;
740 }
741 return 0;
742 } 774 }
743 775
744 pr_warn("acpi_evaluate_object failed\n"); 776 if (result)
777 *result = object->integer.value;
778
779 kfree(object);
780 return 0;
781}
782
783#define MIN(a, b) (a > b ? b : a)
784static int sony_nc_buffer_call(acpi_handle handle, char *name, u64 *value,
785 void *buffer, size_t buflen)
786{
787 size_t len = len;
788 union acpi_object *object = __call_snc_method(handle, name, value);
789
790 if (!object)
791 return -EINVAL;
792
793 if (object->type == ACPI_TYPE_BUFFER)
794 len = MIN(buflen, object->buffer.length);
795
796 else if (object->type == ACPI_TYPE_INTEGER)
797 len = MIN(buflen, sizeof(object->integer.value));
798
799 else {
800 pr_warn("Invalid acpi_object: expected 0x%x got 0x%x\n",
801 ACPI_TYPE_BUFFER, object->type);
802 kfree(object);
803 return -EINVAL;
804 }
745 805
746 return -1; 806 memcpy(buffer, object->buffer.pointer, len);
807 kfree(object);
808 return 0;
747} 809}
748 810
749struct sony_nc_handles { 811struct sony_nc_handles {
@@ -770,16 +832,17 @@ static ssize_t sony_nc_handles_show(struct device *dev,
770 832
771static int sony_nc_handles_setup(struct platform_device *pd) 833static int sony_nc_handles_setup(struct platform_device *pd)
772{ 834{
773 int i; 835 int i, r, result, arg;
774 int result;
775 836
776 handles = kzalloc(sizeof(*handles), GFP_KERNEL); 837 handles = kzalloc(sizeof(*handles), GFP_KERNEL);
777 if (!handles) 838 if (!handles)
778 return -ENOMEM; 839 return -ENOMEM;
779 840
780 for (i = 0; i < ARRAY_SIZE(handles->cap); i++) { 841 for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
781 if (!acpi_callsetfunc(sony_nc_acpi_handle, 842 arg = i + 0x20;
782 "SN00", i + 0x20, &result)) { 843 r = sony_nc_int_call(sony_nc_acpi_handle, "SN00", &arg,
844 &result);
845 if (!r) {
783 dprintk("caching handle 0x%.4x (offset: 0x%.2x)\n", 846 dprintk("caching handle 0x%.4x (offset: 0x%.2x)\n",
784 result, i); 847 result, i);
785 handles->cap[i] = result; 848 handles->cap[i] = result;
@@ -819,8 +882,8 @@ static int sony_find_snc_handle(int handle)
819 int i; 882 int i;
820 883
821 /* not initialized yet, return early */ 884 /* not initialized yet, return early */
822 if (!handles) 885 if (!handles || !handle)
823 return -1; 886 return -EINVAL;
824 887
825 for (i = 0; i < 0x10; i++) { 888 for (i = 0; i < 0x10; i++) {
826 if (handles->cap[i] == handle) { 889 if (handles->cap[i] == handle) {
@@ -830,21 +893,20 @@ static int sony_find_snc_handle(int handle)
830 } 893 }
831 } 894 }
832 dprintk("handle 0x%.4x not found\n", handle); 895 dprintk("handle 0x%.4x not found\n", handle);
833 return -1; 896 return -EINVAL;
834} 897}
835 898
836static int sony_call_snc_handle(int handle, int argument, int *result) 899static int sony_call_snc_handle(int handle, int argument, int *result)
837{ 900{
838 int ret = 0; 901 int arg, ret = 0;
839 int offset = sony_find_snc_handle(handle); 902 int offset = sony_find_snc_handle(handle);
840 903
841 if (offset < 0) 904 if (offset < 0)
842 return -1; 905 return offset;
843 906
844 ret = acpi_callsetfunc(sony_nc_acpi_handle, "SN07", offset | argument, 907 arg = offset | argument;
845 result); 908 ret = sony_nc_int_call(sony_nc_acpi_handle, "SN07", &arg, result);
846 dprintk("called SN07 with 0x%.4x (result: 0x%.4x)\n", offset | argument, 909 dprintk("called SN07 with 0x%.4x (result: 0x%.4x)\n", arg, *result);
847 *result);
848 return ret; 910 return ret;
849} 911}
850 912
@@ -889,14 +951,16 @@ static int boolean_validate(const int direction, const int value)
889static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr, 951static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr,
890 char *buffer) 952 char *buffer)
891{ 953{
892 int value; 954 int value, ret = 0;
893 struct sony_nc_value *item = 955 struct sony_nc_value *item =
894 container_of(attr, struct sony_nc_value, devattr); 956 container_of(attr, struct sony_nc_value, devattr);
895 957
896 if (!*item->acpiget) 958 if (!*item->acpiget)
897 return -EIO; 959 return -EIO;
898 960
899 if (acpi_callgetfunc(sony_nc_acpi_handle, *item->acpiget, &value) < 0) 961 ret = sony_nc_int_call(sony_nc_acpi_handle, *item->acpiget, NULL,
962 &value);
963 if (ret < 0)
900 return -EIO; 964 return -EIO;
901 965
902 if (item->validate) 966 if (item->validate)
@@ -909,7 +973,8 @@ static ssize_t sony_nc_sysfs_store(struct device *dev,
909 struct device_attribute *attr, 973 struct device_attribute *attr,
910 const char *buffer, size_t count) 974 const char *buffer, size_t count)
911{ 975{
912 int value; 976 unsigned long value = 0;
977 int ret = 0;
913 struct sony_nc_value *item = 978 struct sony_nc_value *item =
914 container_of(attr, struct sony_nc_value, devattr); 979 container_of(attr, struct sony_nc_value, devattr);
915 980
@@ -919,7 +984,8 @@ static ssize_t sony_nc_sysfs_store(struct device *dev,
919 if (count > 31) 984 if (count > 31)
920 return -EINVAL; 985 return -EINVAL;
921 986
922 value = simple_strtoul(buffer, NULL, 10); 987 if (kstrtoul(buffer, 10, &value))
988 return -EINVAL;
923 989
924 if (item->validate) 990 if (item->validate)
925 value = item->validate(SNC_VALIDATE_IN, value); 991 value = item->validate(SNC_VALIDATE_IN, value);
@@ -927,8 +993,11 @@ static ssize_t sony_nc_sysfs_store(struct device *dev,
927 if (value < 0) 993 if (value < 0)
928 return value; 994 return value;
929 995
930 if (acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, value, NULL) < 0) 996 ret = sony_nc_int_call(sony_nc_acpi_handle, *item->acpiset,
997 (int *)&value, NULL);
998 if (ret < 0)
931 return -EIO; 999 return -EIO;
1000
932 item->value = value; 1001 item->value = value;
933 item->valid = 1; 1002 item->valid = 1;
934 return count; 1003 return count;
@@ -948,15 +1017,15 @@ struct sony_backlight_props sony_bl_props;
948 1017
949static int sony_backlight_update_status(struct backlight_device *bd) 1018static int sony_backlight_update_status(struct backlight_device *bd)
950{ 1019{
951 return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT", 1020 int arg = bd->props.brightness + 1;
952 bd->props.brightness + 1, NULL); 1021 return sony_nc_int_call(sony_nc_acpi_handle, "SBRT", &arg, NULL);
953} 1022}
954 1023
955static int sony_backlight_get_brightness(struct backlight_device *bd) 1024static int sony_backlight_get_brightness(struct backlight_device *bd)
956{ 1025{
957 int value; 1026 int value;
958 1027
959 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) 1028 if (sony_nc_int_call(sony_nc_acpi_handle, "GBRT", NULL, &value))
960 return 0; 1029 return 0;
961 /* brightness levels are 1-based, while backlight ones are 0-based */ 1030 /* brightness levels are 1-based, while backlight ones are 0-based */
962 return value - 1; 1031 return value - 1;
@@ -1024,10 +1093,14 @@ static struct sony_nc_event sony_100_events[] = {
1024 { 0x06, SONYPI_EVENT_FNKEY_RELEASED }, 1093 { 0x06, SONYPI_EVENT_FNKEY_RELEASED },
1025 { 0x87, SONYPI_EVENT_FNKEY_F7 }, 1094 { 0x87, SONYPI_EVENT_FNKEY_F7 },
1026 { 0x07, SONYPI_EVENT_FNKEY_RELEASED }, 1095 { 0x07, SONYPI_EVENT_FNKEY_RELEASED },
1096 { 0x88, SONYPI_EVENT_FNKEY_F8 },
1097 { 0x08, SONYPI_EVENT_FNKEY_RELEASED },
1027 { 0x89, SONYPI_EVENT_FNKEY_F9 }, 1098 { 0x89, SONYPI_EVENT_FNKEY_F9 },
1028 { 0x09, SONYPI_EVENT_FNKEY_RELEASED }, 1099 { 0x09, SONYPI_EVENT_FNKEY_RELEASED },
1029 { 0x8A, SONYPI_EVENT_FNKEY_F10 }, 1100 { 0x8A, SONYPI_EVENT_FNKEY_F10 },
1030 { 0x0A, SONYPI_EVENT_FNKEY_RELEASED }, 1101 { 0x0A, SONYPI_EVENT_FNKEY_RELEASED },
1102 { 0x8B, SONYPI_EVENT_FNKEY_F11 },
1103 { 0x0B, SONYPI_EVENT_FNKEY_RELEASED },
1031 { 0x8C, SONYPI_EVENT_FNKEY_F12 }, 1104 { 0x8C, SONYPI_EVENT_FNKEY_F12 },
1032 { 0x0C, SONYPI_EVENT_FNKEY_RELEASED }, 1105 { 0x0C, SONYPI_EVENT_FNKEY_RELEASED },
1033 { 0x9d, SONYPI_EVENT_ZOOM_PRESSED }, 1106 { 0x9d, SONYPI_EVENT_ZOOM_PRESSED },
@@ -1063,63 +1136,116 @@ static struct sony_nc_event sony_127_events[] = {
1063 { 0, 0 }, 1136 { 0, 0 },
1064}; 1137};
1065 1138
1139static int sony_nc_hotkeys_decode(u32 event, unsigned int handle)
1140{
1141 int ret = -EINVAL;
1142 unsigned int result = 0;
1143 struct sony_nc_event *key_event;
1144
1145 if (sony_call_snc_handle(handle, 0x200, &result)) {
1146 dprintk("Unable to decode event 0x%.2x 0x%.2x\n", handle,
1147 event);
1148 return -EINVAL;
1149 }
1150
1151 result &= 0xFF;
1152
1153 if (handle == 0x0100)
1154 key_event = sony_100_events;
1155 else
1156 key_event = sony_127_events;
1157
1158 for (; key_event->data; key_event++) {
1159 if (key_event->data == result) {
1160 ret = key_event->event;
1161 break;
1162 }
1163 }
1164
1165 if (!key_event->data)
1166 pr_info("Unknown hotkey 0x%.2x/0x%.2x (handle 0x%.2x)\n",
1167 event, result, handle);
1168
1169 return ret;
1170}
1171
1066/* 1172/*
1067 * ACPI callbacks 1173 * ACPI callbacks
1068 */ 1174 */
1069static void sony_nc_notify(struct acpi_device *device, u32 event) 1175static void sony_nc_notify(struct acpi_device *device, u32 event)
1070{ 1176{
1071 u32 ev = event; 1177 u32 real_ev = event;
1178 u8 ev_type = 0;
1179 dprintk("sony_nc_notify, event: 0x%.2x\n", event);
1180
1181 if (event >= 0x90) {
1182 unsigned int result = 0;
1183 unsigned int arg = 0;
1184 unsigned int handle = 0;
1185 unsigned int offset = event - 0x90;
1186
1187 if (offset >= ARRAY_SIZE(handles->cap)) {
1188 pr_err("Event 0x%x outside of capabilities list\n",
1189 event);
1190 return;
1191 }
1192 handle = handles->cap[offset];
1193
1194 /* list of handles known for generating events */
1195 switch (handle) {
1196 /* hotkey event */
1197 case 0x0100:
1198 case 0x0127:
1199 ev_type = 1;
1200 real_ev = sony_nc_hotkeys_decode(event, handle);
1201
1202 if (real_ev > 0)
1203 sony_laptop_report_input_event(real_ev);
1204 else
1205 /* restore the original event for reporting */
1206 real_ev = event;
1072 1207
1073 if (ev >= 0x90) { 1208 break;
1074 /* New-style event */
1075 int result;
1076 int key_handle = 0;
1077 ev -= 0x90;
1078
1079 if (sony_find_snc_handle(0x100) == ev)
1080 key_handle = 0x100;
1081 if (sony_find_snc_handle(0x127) == ev)
1082 key_handle = 0x127;
1083
1084 if (key_handle) {
1085 struct sony_nc_event *key_event;
1086
1087 if (sony_call_snc_handle(key_handle, 0x200, &result)) {
1088 dprintk("sony_nc_notify, unable to decode"
1089 " event 0x%.2x 0x%.2x\n", key_handle,
1090 ev);
1091 /* restore the original event */
1092 ev = event;
1093 } else {
1094 ev = result & 0xFF;
1095
1096 if (key_handle == 0x100)
1097 key_event = sony_100_events;
1098 else
1099 key_event = sony_127_events;
1100
1101 for (; key_event->data; key_event++) {
1102 if (key_event->data == ev) {
1103 ev = key_event->event;
1104 break;
1105 }
1106 }
1107 1209
1108 if (!key_event->data) 1210 /* wlan switch */
1109 pr_info("Unknown event: 0x%x 0x%x\n", 1211 case 0x0124:
1110 key_handle, ev); 1212 case 0x0135:
1111 else 1213 /* events on this handle are reported when the
1112 sony_laptop_report_input_event(ev); 1214 * switch changes position or for battery
1113 } 1215 * events. We'll notify both of them but only
1114 } else if (sony_find_snc_handle(sony_rfkill_handle) == ev) { 1216 * update the rfkill device status when the
1115 sony_nc_rfkill_update(); 1217 * switch is moved.
1116 return; 1218 */
1219 ev_type = 2;
1220 sony_call_snc_handle(handle, 0x0100, &result);
1221 real_ev = result & 0x03;
1222
1223 /* hw switch event */
1224 if (real_ev == 1)
1225 sony_nc_rfkill_update();
1226
1227 break;
1228
1229 default:
1230 dprintk("Unknown event 0x%x for handle 0x%x\n",
1231 event, handle);
1232 break;
1117 } 1233 }
1118 } else
1119 sony_laptop_report_input_event(ev);
1120 1234
1121 dprintk("sony_nc_notify, event: 0x%.2x\n", ev); 1235 /* clear the event (and the event reason when present) */
1122 acpi_bus_generate_proc_event(sony_nc_acpi_device, 1, ev); 1236 arg = 1 << offset;
1237 sony_nc_int_call(sony_nc_acpi_handle, "SN05", &arg, &result);
1238
1239 } else {
1240 /* old style event */
1241 ev_type = 1;
1242 sony_laptop_report_input_event(real_ev);
1243 }
1244
1245 acpi_bus_generate_proc_event(sony_nc_acpi_device, ev_type, real_ev);
1246
1247 acpi_bus_generate_netlink_event(sony_nc_acpi_device->pnp.device_class,
1248 dev_name(&sony_nc_acpi_device->dev), ev_type, real_ev);
1123} 1249}
1124 1250
1125static acpi_status sony_walk_callback(acpi_handle handle, u32 level, 1251static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
@@ -1140,20 +1266,190 @@ static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
1140/* 1266/*
1141 * ACPI device 1267 * ACPI device
1142 */ 1268 */
1143static int sony_nc_function_setup(struct acpi_device *device) 1269static void sony_nc_function_setup(struct acpi_device *device,
1270 struct platform_device *pf_device)
1144{ 1271{
1145 int result; 1272 unsigned int i, result, bitmask, arg;
1273
1274 if (!handles)
1275 return;
1276
1277 /* setup found handles here */
1278 for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
1279 unsigned int handle = handles->cap[i];
1280
1281 if (!handle)
1282 continue;
1283
1284 dprintk("setting up handle 0x%.4x\n", handle);
1285
1286 switch (handle) {
1287 case 0x0100:
1288 case 0x0101:
1289 case 0x0127:
1290 /* setup hotkeys */
1291 sony_call_snc_handle(handle, 0, &result);
1292 break;
1293 case 0x0102:
1294 /* setup hotkeys */
1295 sony_call_snc_handle(handle, 0x100, &result);
1296 break;
1297 case 0x0105:
1298 case 0x0148:
1299 /* touchpad enable/disable */
1300 result = sony_nc_touchpad_setup(pf_device, handle);
1301 if (result)
1302 pr_err("couldn't set up touchpad control function (%d)\n",
1303 result);
1304 break;
1305 case 0x0115:
1306 case 0x0136:
1307 case 0x013f:
1308 result = sony_nc_battery_care_setup(pf_device, handle);
1309 if (result)
1310 pr_err("couldn't set up battery care function (%d)\n",
1311 result);
1312 break;
1313 case 0x0119:
1314 result = sony_nc_lid_resume_setup(pf_device);
1315 if (result)
1316 pr_err("couldn't set up lid resume function (%d)\n",
1317 result);
1318 break;
1319 case 0x0122:
1320 result = sony_nc_thermal_setup(pf_device);
1321 if (result)
1322 pr_err("couldn't set up thermal profile function (%d)\n",
1323 result);
1324 break;
1325 case 0x0131:
1326 result = sony_nc_highspeed_charging_setup(pf_device);
1327 if (result)
1328 pr_err("couldn't set up high speed charging function (%d)\n",
1329 result);
1330 break;
1331 case 0x0124:
1332 case 0x0135:
1333 result = sony_nc_rfkill_setup(device, handle);
1334 if (result)
1335 pr_err("couldn't set up rfkill support (%d)\n",
1336 result);
1337 break;
1338 case 0x0137:
1339 case 0x0143:
1340 result = sony_nc_kbd_backlight_setup(pf_device, handle);
1341 if (result)
1342 pr_err("couldn't set up keyboard backlight function (%d)\n",
1343 result);
1344 break;
1345 default:
1346 continue;
1347 }
1348 }
1146 1349
1147 /* Enable all events */ 1350 /* Enable all events */
1148 acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0xffff, &result); 1351 arg = 0x10;
1352 if (!sony_nc_int_call(sony_nc_acpi_handle, "SN00", &arg, &bitmask))
1353 sony_nc_int_call(sony_nc_acpi_handle, "SN02", &bitmask,
1354 &result);
1355}
1356
1357static void sony_nc_function_cleanup(struct platform_device *pd)
1358{
1359 unsigned int i, result, bitmask, handle;
1149 1360
1150 /* Setup hotkeys */ 1361 /* get enabled events and disable them */
1151 sony_call_snc_handle(0x0100, 0, &result); 1362 sony_nc_int_call(sony_nc_acpi_handle, "SN01", NULL, &bitmask);
1152 sony_call_snc_handle(0x0101, 0, &result); 1363 sony_nc_int_call(sony_nc_acpi_handle, "SN03", &bitmask, &result);
1153 sony_call_snc_handle(0x0102, 0x100, &result);
1154 sony_call_snc_handle(0x0127, 0, &result);
1155 1364
1156 return 0; 1365 /* cleanup handles here */
1366 for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
1367
1368 handle = handles->cap[i];
1369
1370 if (!handle)
1371 continue;
1372
1373 switch (handle) {
1374 case 0x0105:
1375 case 0x0148:
1376 sony_nc_touchpad_cleanup(pd);
1377 break;
1378 case 0x0115:
1379 case 0x0136:
1380 case 0x013f:
1381 sony_nc_battery_care_cleanup(pd);
1382 break;
1383 case 0x0119:
1384 sony_nc_lid_resume_cleanup(pd);
1385 break;
1386 case 0x0122:
1387 sony_nc_thermal_cleanup(pd);
1388 break;
1389 case 0x0131:
1390 sony_nc_highspeed_charging_cleanup(pd);
1391 break;
1392 case 0x0124:
1393 case 0x0135:
1394 sony_nc_rfkill_cleanup();
1395 break;
1396 case 0x0137:
1397 case 0x0143:
1398 sony_nc_kbd_backlight_cleanup(pd);
1399 break;
1400 default:
1401 continue;
1402 }
1403 }
1404
1405 /* finally cleanup the handles list */
1406 sony_nc_handles_cleanup(pd);
1407}
1408
1409static void sony_nc_function_resume(void)
1410{
1411 unsigned int i, result, bitmask, arg;
1412
1413 dprintk("Resuming SNC device\n");
1414
1415 for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
1416 unsigned int handle = handles->cap[i];
1417
1418 if (!handle)
1419 continue;
1420
1421 switch (handle) {
1422 case 0x0100:
1423 case 0x0101:
1424 case 0x0127:
1425 /* re-enable hotkeys */
1426 sony_call_snc_handle(handle, 0, &result);
1427 break;
1428 case 0x0102:
1429 /* re-enable hotkeys */
1430 sony_call_snc_handle(handle, 0x100, &result);
1431 break;
1432 case 0x0122:
1433 sony_nc_thermal_resume();
1434 break;
1435 case 0x0124:
1436 case 0x0135:
1437 sony_nc_rfkill_update();
1438 break;
1439 case 0x0137:
1440 case 0x0143:
1441 sony_nc_kbd_backlight_resume();
1442 break;
1443 default:
1444 continue;
1445 }
1446 }
1447
1448 /* Enable all events */
1449 arg = 0x10;
1450 if (!sony_nc_int_call(sony_nc_acpi_handle, "SN00", &arg, &bitmask))
1451 sony_nc_int_call(sony_nc_acpi_handle, "SN02", &bitmask,
1452 &result);
1157} 1453}
1158 1454
1159static int sony_nc_resume(struct acpi_device *device) 1455static int sony_nc_resume(struct acpi_device *device)
@@ -1166,8 +1462,8 @@ static int sony_nc_resume(struct acpi_device *device)
1166 1462
1167 if (!item->valid) 1463 if (!item->valid)
1168 continue; 1464 continue;
1169 ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, 1465 ret = sony_nc_int_call(sony_nc_acpi_handle, *item->acpiset,
1170 item->value, NULL); 1466 &item->value, NULL);
1171 if (ret < 0) { 1467 if (ret < 0) {
1172 pr_err("%s: %d\n", __func__, ret); 1468 pr_err("%s: %d\n", __func__, ret);
1173 break; 1469 break;
@@ -1176,21 +1472,14 @@ static int sony_nc_resume(struct acpi_device *device)
1176 1472
1177 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON", 1473 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON",
1178 &handle))) { 1474 &handle))) {
1179 if (acpi_callsetfunc(sony_nc_acpi_handle, "ECON", 1, NULL)) 1475 int arg = 1;
1476 if (sony_nc_int_call(sony_nc_acpi_handle, "ECON", &arg, NULL))
1180 dprintk("ECON Method failed\n"); 1477 dprintk("ECON Method failed\n");
1181 } 1478 }
1182 1479
1183 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00", 1480 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00",
1184 &handle))) { 1481 &handle)))
1185 dprintk("Doing SNC setup\n"); 1482 sony_nc_function_resume();
1186 sony_nc_function_setup(device);
1187 }
1188
1189 /* re-read rfkill state */
1190 sony_nc_rfkill_update();
1191
1192 /* restore kbd backlight states */
1193 sony_nc_kbd_backlight_resume();
1194 1483
1195 return 0; 1484 return 0;
1196} 1485}
@@ -1213,7 +1502,7 @@ static int sony_nc_rfkill_set(void *data, bool blocked)
1213 int argument = sony_rfkill_address[(long) data] + 0x100; 1502 int argument = sony_rfkill_address[(long) data] + 0x100;
1214 1503
1215 if (!blocked) 1504 if (!blocked)
1216 argument |= 0xff0000; 1505 argument |= 0x030000;
1217 1506
1218 return sony_call_snc_handle(sony_rfkill_handle, argument, &result); 1507 return sony_call_snc_handle(sony_rfkill_handle, argument, &result);
1219} 1508}
@@ -1230,7 +1519,7 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
1230 enum rfkill_type type; 1519 enum rfkill_type type;
1231 const char *name; 1520 const char *name;
1232 int result; 1521 int result;
1233 bool hwblock; 1522 bool hwblock, swblock;
1234 1523
1235 switch (nc_type) { 1524 switch (nc_type) {
1236 case SONY_WIFI: 1525 case SONY_WIFI:
@@ -1258,8 +1547,21 @@ static int sony_nc_setup_rfkill(struct acpi_device *device,
1258 if (!rfk) 1547 if (!rfk)
1259 return -ENOMEM; 1548 return -ENOMEM;
1260 1549
1261 sony_call_snc_handle(sony_rfkill_handle, 0x200, &result); 1550 if (sony_call_snc_handle(sony_rfkill_handle, 0x200, &result) < 0) {
1551 rfkill_destroy(rfk);
1552 return -1;
1553 }
1262 hwblock = !(result & 0x1); 1554 hwblock = !(result & 0x1);
1555
1556 if (sony_call_snc_handle(sony_rfkill_handle,
1557 sony_rfkill_address[nc_type],
1558 &result) < 0) {
1559 rfkill_destroy(rfk);
1560 return -1;
1561 }
1562 swblock = !(result & 0x2);
1563
1564 rfkill_init_sw_state(rfk, swblock);
1263 rfkill_set_hw_state(rfk, hwblock); 1565 rfkill_set_hw_state(rfk, hwblock);
1264 1566
1265 err = rfkill_register(rfk); 1567 err = rfkill_register(rfk);
@@ -1295,101 +1597,79 @@ static void sony_nc_rfkill_update(void)
1295 1597
1296 sony_call_snc_handle(sony_rfkill_handle, argument, &result); 1598 sony_call_snc_handle(sony_rfkill_handle, argument, &result);
1297 rfkill_set_states(sony_rfkill_devices[i], 1599 rfkill_set_states(sony_rfkill_devices[i],
1298 !(result & 0xf), false); 1600 !(result & 0x2), false);
1299 } 1601 }
1300} 1602}
1301 1603
1302static void sony_nc_rfkill_setup(struct acpi_device *device) 1604static int sony_nc_rfkill_setup(struct acpi_device *device,
1605 unsigned int handle)
1303{ 1606{
1304 int offset; 1607 u64 offset;
1305 u8 dev_code, i; 1608 int i;
1306 acpi_status status; 1609 unsigned char buffer[32] = { 0 };
1307 struct acpi_object_list params;
1308 union acpi_object in_obj;
1309 union acpi_object *device_enum;
1310 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1311
1312 offset = sony_find_snc_handle(0x124);
1313 if (offset == -1) {
1314 offset = sony_find_snc_handle(0x135);
1315 if (offset == -1)
1316 return;
1317 else
1318 sony_rfkill_handle = 0x135;
1319 } else
1320 sony_rfkill_handle = 0x124;
1321 dprintk("Found rkfill handle: 0x%.4x\n", sony_rfkill_handle);
1322
1323 /* need to read the whole buffer returned by the acpi call to SN06
1324 * here otherwise we may miss some features
1325 */
1326 params.count = 1;
1327 params.pointer = &in_obj;
1328 in_obj.type = ACPI_TYPE_INTEGER;
1329 in_obj.integer.value = offset;
1330 status = acpi_evaluate_object(sony_nc_acpi_handle, "SN06", &params,
1331 &buffer);
1332 if (ACPI_FAILURE(status)) {
1333 dprintk("Radio device enumeration failed\n");
1334 return;
1335 }
1336
1337 device_enum = (union acpi_object *) buffer.pointer;
1338 if (!device_enum) {
1339 pr_err("No SN06 return object\n");
1340 goto out_no_enum;
1341 }
1342 if (device_enum->type != ACPI_TYPE_BUFFER) {
1343 pr_err("Invalid SN06 return object 0x%.2x\n",
1344 device_enum->type);
1345 goto out_no_enum;
1346 }
1347 1610
1348 /* the buffer is filled with magic numbers describing the devices 1611 offset = sony_find_snc_handle(handle);
1349 * available, 0xff terminates the enumeration 1612 sony_rfkill_handle = handle;
1613
1614 i = sony_nc_buffer_call(sony_nc_acpi_handle, "SN06", &offset, buffer,
1615 32);
1616 if (i < 0)
1617 return i;
1618
1619 /* The buffer is filled with magic numbers describing the devices
1620 * available, 0xff terminates the enumeration.
1621 * Known codes:
1622 * 0x00 WLAN
1623 * 0x10 BLUETOOTH
1624 * 0x20 WWAN GPRS-EDGE
1625 * 0x21 WWAN HSDPA
1626 * 0x22 WWAN EV-DO
1627 * 0x23 WWAN GPS
1628 * 0x25 Gobi WWAN no GPS
1629 * 0x26 Gobi WWAN + GPS
1630 * 0x28 Gobi WWAN no GPS
1631 * 0x29 Gobi WWAN + GPS
1632 * 0x30 WIMAX
1633 * 0x50 Gobi WWAN no GPS
1634 * 0x51 Gobi WWAN + GPS
1635 * 0x70 no SIM card slot
1636 * 0x71 SIM card slot
1350 */ 1637 */
1351 for (i = 0; i < device_enum->buffer.length; i++) { 1638 for (i = 0; i < ARRAY_SIZE(buffer); i++) {
1352 1639
1353 dev_code = *(device_enum->buffer.pointer + i); 1640 if (buffer[i] == 0xff)
1354 if (dev_code == 0xff)
1355 break; 1641 break;
1356 1642
1357 dprintk("Radio devices, looking at 0x%.2x\n", dev_code); 1643 dprintk("Radio devices, found 0x%.2x\n", buffer[i]);
1358 1644
1359 if (dev_code == 0 && !sony_rfkill_devices[SONY_WIFI]) 1645 if (buffer[i] == 0 && !sony_rfkill_devices[SONY_WIFI])
1360 sony_nc_setup_rfkill(device, SONY_WIFI); 1646 sony_nc_setup_rfkill(device, SONY_WIFI);
1361 1647
1362 if (dev_code == 0x10 && !sony_rfkill_devices[SONY_BLUETOOTH]) 1648 if (buffer[i] == 0x10 && !sony_rfkill_devices[SONY_BLUETOOTH])
1363 sony_nc_setup_rfkill(device, SONY_BLUETOOTH); 1649 sony_nc_setup_rfkill(device, SONY_BLUETOOTH);
1364 1650
1365 if ((0xf0 & dev_code) == 0x20 && 1651 if (((0xf0 & buffer[i]) == 0x20 ||
1652 (0xf0 & buffer[i]) == 0x50) &&
1366 !sony_rfkill_devices[SONY_WWAN]) 1653 !sony_rfkill_devices[SONY_WWAN])
1367 sony_nc_setup_rfkill(device, SONY_WWAN); 1654 sony_nc_setup_rfkill(device, SONY_WWAN);
1368 1655
1369 if (dev_code == 0x30 && !sony_rfkill_devices[SONY_WIMAX]) 1656 if (buffer[i] == 0x30 && !sony_rfkill_devices[SONY_WIMAX])
1370 sony_nc_setup_rfkill(device, SONY_WIMAX); 1657 sony_nc_setup_rfkill(device, SONY_WIMAX);
1371 } 1658 }
1372 1659 return 0;
1373out_no_enum:
1374 kfree(buffer.pointer);
1375 return;
1376} 1660}
1377 1661
1378/* Keyboard backlight feature */ 1662/* Keyboard backlight feature */
1379#define KBDBL_HANDLER 0x137
1380#define KBDBL_PRESENT 0xB00
1381#define SET_MODE 0xC00
1382#define SET_STATE 0xD00
1383#define SET_TIMEOUT 0xE00
1384
1385struct kbd_backlight { 1663struct kbd_backlight {
1386 int mode; 1664 unsigned int handle;
1387 int timeout; 1665 unsigned int base;
1666 unsigned int mode;
1667 unsigned int timeout;
1388 struct device_attribute mode_attr; 1668 struct device_attribute mode_attr;
1389 struct device_attribute timeout_attr; 1669 struct device_attribute timeout_attr;
1390}; 1670};
1391 1671
1392static struct kbd_backlight *kbdbl_handle; 1672static struct kbd_backlight *kbdbl_ctl;
1393 1673
1394static ssize_t __sony_nc_kbd_backlight_mode_set(u8 value) 1674static ssize_t __sony_nc_kbd_backlight_mode_set(u8 value)
1395{ 1675{
@@ -1398,15 +1678,15 @@ static ssize_t __sony_nc_kbd_backlight_mode_set(u8 value)
1398 if (value > 1) 1678 if (value > 1)
1399 return -EINVAL; 1679 return -EINVAL;
1400 1680
1401 if (sony_call_snc_handle(KBDBL_HANDLER, 1681 if (sony_call_snc_handle(kbdbl_ctl->handle,
1402 (value << 0x10) | SET_MODE, &result)) 1682 (value << 0x10) | (kbdbl_ctl->base), &result))
1403 return -EIO; 1683 return -EIO;
1404 1684
1405 /* Try to turn the light on/off immediately */ 1685 /* Try to turn the light on/off immediately */
1406 sony_call_snc_handle(KBDBL_HANDLER, (value << 0x10) | SET_STATE, 1686 sony_call_snc_handle(kbdbl_ctl->handle,
1407 &result); 1687 (value << 0x10) | (kbdbl_ctl->base + 0x100), &result);
1408 1688
1409 kbdbl_handle->mode = value; 1689 kbdbl_ctl->mode = value;
1410 1690
1411 return 0; 1691 return 0;
1412} 1692}
@@ -1421,7 +1701,7 @@ static ssize_t sony_nc_kbd_backlight_mode_store(struct device *dev,
1421 if (count > 31) 1701 if (count > 31)
1422 return -EINVAL; 1702 return -EINVAL;
1423 1703
1424 if (strict_strtoul(buffer, 10, &value)) 1704 if (kstrtoul(buffer, 10, &value))
1425 return -EINVAL; 1705 return -EINVAL;
1426 1706
1427 ret = __sony_nc_kbd_backlight_mode_set(value); 1707 ret = __sony_nc_kbd_backlight_mode_set(value);
@@ -1435,7 +1715,7 @@ static ssize_t sony_nc_kbd_backlight_mode_show(struct device *dev,
1435 struct device_attribute *attr, char *buffer) 1715 struct device_attribute *attr, char *buffer)
1436{ 1716{
1437 ssize_t count = 0; 1717 ssize_t count = 0;
1438 count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_handle->mode); 1718 count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_ctl->mode);
1439 return count; 1719 return count;
1440} 1720}
1441 1721
@@ -1446,11 +1726,11 @@ static int __sony_nc_kbd_backlight_timeout_set(u8 value)
1446 if (value > 3) 1726 if (value > 3)
1447 return -EINVAL; 1727 return -EINVAL;
1448 1728
1449 if (sony_call_snc_handle(KBDBL_HANDLER, 1729 if (sony_call_snc_handle(kbdbl_ctl->handle, (value << 0x10) |
1450 (value << 0x10) | SET_TIMEOUT, &result)) 1730 (kbdbl_ctl->base + 0x200), &result))
1451 return -EIO; 1731 return -EIO;
1452 1732
1453 kbdbl_handle->timeout = value; 1733 kbdbl_ctl->timeout = value;
1454 1734
1455 return 0; 1735 return 0;
1456} 1736}
@@ -1465,7 +1745,7 @@ static ssize_t sony_nc_kbd_backlight_timeout_store(struct device *dev,
1465 if (count > 31) 1745 if (count > 31)
1466 return -EINVAL; 1746 return -EINVAL;
1467 1747
1468 if (strict_strtoul(buffer, 10, &value)) 1748 if (kstrtoul(buffer, 10, &value))
1469 return -EINVAL; 1749 return -EINVAL;
1470 1750
1471 ret = __sony_nc_kbd_backlight_timeout_set(value); 1751 ret = __sony_nc_kbd_backlight_timeout_set(value);
@@ -1479,39 +1759,58 @@ static ssize_t sony_nc_kbd_backlight_timeout_show(struct device *dev,
1479 struct device_attribute *attr, char *buffer) 1759 struct device_attribute *attr, char *buffer)
1480{ 1760{
1481 ssize_t count = 0; 1761 ssize_t count = 0;
1482 count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_handle->timeout); 1762 count = snprintf(buffer, PAGE_SIZE, "%d\n", kbdbl_ctl->timeout);
1483 return count; 1763 return count;
1484} 1764}
1485 1765
1486static int sony_nc_kbd_backlight_setup(struct platform_device *pd) 1766static int sony_nc_kbd_backlight_setup(struct platform_device *pd,
1767 unsigned int handle)
1487{ 1768{
1488 int result; 1769 int result;
1770 int ret = 0;
1489 1771
1490 if (sony_call_snc_handle(KBDBL_HANDLER, KBDBL_PRESENT, &result)) 1772 /* verify the kbd backlight presence, these handles are not used for
1491 return 0; 1773 * keyboard backlight only
1492 if (!(result & 0x02)) 1774 */
1775 ret = sony_call_snc_handle(handle, handle == 0x0137 ? 0x0B00 : 0x0100,
1776 &result);
1777 if (ret)
1778 return ret;
1779
1780 if ((handle == 0x0137 && !(result & 0x02)) ||
1781 !(result & 0x01)) {
1782 dprintk("no backlight keyboard found\n");
1493 return 0; 1783 return 0;
1784 }
1494 1785
1495 kbdbl_handle = kzalloc(sizeof(*kbdbl_handle), GFP_KERNEL); 1786 kbdbl_ctl = kzalloc(sizeof(*kbdbl_ctl), GFP_KERNEL);
1496 if (!kbdbl_handle) 1787 if (!kbdbl_ctl)
1497 return -ENOMEM; 1788 return -ENOMEM;
1498 1789
1499 sysfs_attr_init(&kbdbl_handle->mode_attr.attr); 1790 kbdbl_ctl->handle = handle;
1500 kbdbl_handle->mode_attr.attr.name = "kbd_backlight"; 1791 if (handle == 0x0137)
1501 kbdbl_handle->mode_attr.attr.mode = S_IRUGO | S_IWUSR; 1792 kbdbl_ctl->base = 0x0C00;
1502 kbdbl_handle->mode_attr.show = sony_nc_kbd_backlight_mode_show; 1793 else
1503 kbdbl_handle->mode_attr.store = sony_nc_kbd_backlight_mode_store; 1794 kbdbl_ctl->base = 0x4000;
1795
1796 sysfs_attr_init(&kbdbl_ctl->mode_attr.attr);
1797 kbdbl_ctl->mode_attr.attr.name = "kbd_backlight";
1798 kbdbl_ctl->mode_attr.attr.mode = S_IRUGO | S_IWUSR;
1799 kbdbl_ctl->mode_attr.show = sony_nc_kbd_backlight_mode_show;
1800 kbdbl_ctl->mode_attr.store = sony_nc_kbd_backlight_mode_store;
1504 1801
1505 sysfs_attr_init(&kbdbl_handle->timeout_attr.attr); 1802 sysfs_attr_init(&kbdbl_ctl->timeout_attr.attr);
1506 kbdbl_handle->timeout_attr.attr.name = "kbd_backlight_timeout"; 1803 kbdbl_ctl->timeout_attr.attr.name = "kbd_backlight_timeout";
1507 kbdbl_handle->timeout_attr.attr.mode = S_IRUGO | S_IWUSR; 1804 kbdbl_ctl->timeout_attr.attr.mode = S_IRUGO | S_IWUSR;
1508 kbdbl_handle->timeout_attr.show = sony_nc_kbd_backlight_timeout_show; 1805 kbdbl_ctl->timeout_attr.show = sony_nc_kbd_backlight_timeout_show;
1509 kbdbl_handle->timeout_attr.store = sony_nc_kbd_backlight_timeout_store; 1806 kbdbl_ctl->timeout_attr.store = sony_nc_kbd_backlight_timeout_store;
1510 1807
1511 if (device_create_file(&pd->dev, &kbdbl_handle->mode_attr)) 1808 ret = device_create_file(&pd->dev, &kbdbl_ctl->mode_attr);
1809 if (ret)
1512 goto outkzalloc; 1810 goto outkzalloc;
1513 1811
1514 if (device_create_file(&pd->dev, &kbdbl_handle->timeout_attr)) 1812 ret = device_create_file(&pd->dev, &kbdbl_ctl->timeout_attr);
1813 if (ret)
1515 goto outmode; 1814 goto outmode;
1516 1815
1517 __sony_nc_kbd_backlight_mode_set(kbd_backlight); 1816 __sony_nc_kbd_backlight_mode_set(kbd_backlight);
@@ -1520,57 +1819,661 @@ static int sony_nc_kbd_backlight_setup(struct platform_device *pd)
1520 return 0; 1819 return 0;
1521 1820
1522outmode: 1821outmode:
1523 device_remove_file(&pd->dev, &kbdbl_handle->mode_attr); 1822 device_remove_file(&pd->dev, &kbdbl_ctl->mode_attr);
1524outkzalloc: 1823outkzalloc:
1525 kfree(kbdbl_handle); 1824 kfree(kbdbl_ctl);
1526 kbdbl_handle = NULL; 1825 kbdbl_ctl = NULL;
1527 return -1; 1826 return ret;
1528} 1827}
1529 1828
1530static int sony_nc_kbd_backlight_cleanup(struct platform_device *pd) 1829static void sony_nc_kbd_backlight_cleanup(struct platform_device *pd)
1531{ 1830{
1532 if (kbdbl_handle) { 1831 if (kbdbl_ctl) {
1533 int result; 1832 int result;
1534 1833
1535 device_remove_file(&pd->dev, &kbdbl_handle->mode_attr); 1834 device_remove_file(&pd->dev, &kbdbl_ctl->mode_attr);
1536 device_remove_file(&pd->dev, &kbdbl_handle->timeout_attr); 1835 device_remove_file(&pd->dev, &kbdbl_ctl->timeout_attr);
1537 1836
1538 /* restore the default hw behaviour */ 1837 /* restore the default hw behaviour */
1539 sony_call_snc_handle(KBDBL_HANDLER, 0x1000 | SET_MODE, &result); 1838 sony_call_snc_handle(kbdbl_ctl->handle,
1540 sony_call_snc_handle(KBDBL_HANDLER, SET_TIMEOUT, &result); 1839 kbdbl_ctl->base | 0x10000, &result);
1840 sony_call_snc_handle(kbdbl_ctl->handle,
1841 kbdbl_ctl->base + 0x200, &result);
1541 1842
1542 kfree(kbdbl_handle); 1843 kfree(kbdbl_ctl);
1844 kbdbl_ctl = NULL;
1543 } 1845 }
1544 return 0;
1545} 1846}
1546 1847
1547static void sony_nc_kbd_backlight_resume(void) 1848static void sony_nc_kbd_backlight_resume(void)
1548{ 1849{
1549 int ignore = 0; 1850 int ignore = 0;
1550 1851
1551 if (!kbdbl_handle) 1852 if (!kbdbl_ctl)
1552 return; 1853 return;
1553 1854
1554 if (kbdbl_handle->mode == 0) 1855 if (kbdbl_ctl->mode == 0)
1555 sony_call_snc_handle(KBDBL_HANDLER, SET_MODE, &ignore); 1856 sony_call_snc_handle(kbdbl_ctl->handle, kbdbl_ctl->base,
1556
1557 if (kbdbl_handle->timeout != 0)
1558 sony_call_snc_handle(KBDBL_HANDLER,
1559 (kbdbl_handle->timeout << 0x10) | SET_TIMEOUT,
1560 &ignore); 1857 &ignore);
1858
1859 if (kbdbl_ctl->timeout != 0)
1860 sony_call_snc_handle(kbdbl_ctl->handle,
1861 (kbdbl_ctl->base + 0x200) |
1862 (kbdbl_ctl->timeout << 0x10), &ignore);
1863}
1864
1865struct battery_care_control {
1866 struct device_attribute attrs[2];
1867 unsigned int handle;
1868};
1869static struct battery_care_control *bcare_ctl;
1870
1871static ssize_t sony_nc_battery_care_limit_store(struct device *dev,
1872 struct device_attribute *attr,
1873 const char *buffer, size_t count)
1874{
1875 unsigned int result, cmd;
1876 unsigned long value;
1877
1878 if (count > 31)
1879 return -EINVAL;
1880
1881 if (kstrtoul(buffer, 10, &value))
1882 return -EINVAL;
1883
1884 /* limit values (2 bits):
1885 * 00 - none
1886 * 01 - 80%
1887 * 10 - 50%
1888 * 11 - 100%
1889 *
1890 * bit 0: 0 disable BCL, 1 enable BCL
1891 * bit 1: 1 tell to store the battery limit (see bits 6,7) too
1892 * bits 2,3: reserved
1893 * bits 4,5: store the limit into the EC
1894 * bits 6,7: store the limit into the battery
1895 */
1896
1897 /*
1898 * handle 0x0115 should allow storing on battery too;
1899 * handle 0x0136 same as 0x0115 + health status;
1900 * handle 0x013f, same as 0x0136 but no storing on the battery
1901 *
1902 * Store only inside the EC for now, regardless the handle number
1903 */
1904 if (value == 0)
1905 /* disable limits */
1906 cmd = 0x0;
1907
1908 else if (value <= 50)
1909 cmd = 0x21;
1910
1911 else if (value <= 80)
1912 cmd = 0x11;
1913
1914 else if (value <= 100)
1915 cmd = 0x31;
1916
1917 else
1918 return -EINVAL;
1919
1920 if (sony_call_snc_handle(bcare_ctl->handle, (cmd << 0x10) | 0x0100,
1921 &result))
1922 return -EIO;
1923
1924 return count;
1925}
1926
1927static ssize_t sony_nc_battery_care_limit_show(struct device *dev,
1928 struct device_attribute *attr, char *buffer)
1929{
1930 unsigned int result, status;
1931
1932 if (sony_call_snc_handle(bcare_ctl->handle, 0x0000, &result))
1933 return -EIO;
1934
1935 status = (result & 0x01) ? ((result & 0x30) >> 0x04) : 0;
1936 switch (status) {
1937 case 1:
1938 status = 80;
1939 break;
1940 case 2:
1941 status = 50;
1942 break;
1943 case 3:
1944 status = 100;
1945 break;
1946 default:
1947 status = 0;
1948 break;
1949 }
1950
1951 return snprintf(buffer, PAGE_SIZE, "%d\n", status);
1952}
1953
1954static ssize_t sony_nc_battery_care_health_show(struct device *dev,
1955 struct device_attribute *attr, char *buffer)
1956{
1957 ssize_t count = 0;
1958 unsigned int health;
1959
1960 if (sony_call_snc_handle(bcare_ctl->handle, 0x0200, &health))
1961 return -EIO;
1962
1963 count = snprintf(buffer, PAGE_SIZE, "%d\n", health & 0xff);
1964
1965 return count;
1966}
1967
1968static int sony_nc_battery_care_setup(struct platform_device *pd,
1969 unsigned int handle)
1970{
1971 int ret = 0;
1972
1973 bcare_ctl = kzalloc(sizeof(struct battery_care_control), GFP_KERNEL);
1974 if (!bcare_ctl)
1975 return -ENOMEM;
1976
1977 bcare_ctl->handle = handle;
1978
1979 sysfs_attr_init(&bcare_ctl->attrs[0].attr);
1980 bcare_ctl->attrs[0].attr.name = "battery_care_limiter";
1981 bcare_ctl->attrs[0].attr.mode = S_IRUGO | S_IWUSR;
1982 bcare_ctl->attrs[0].show = sony_nc_battery_care_limit_show;
1983 bcare_ctl->attrs[0].store = sony_nc_battery_care_limit_store;
1984
1985 ret = device_create_file(&pd->dev, &bcare_ctl->attrs[0]);
1986 if (ret)
1987 goto outkzalloc;
1988
1989 /* 0x0115 is for models with no health reporting capability */
1990 if (handle == 0x0115)
1991 return 0;
1992
1993 sysfs_attr_init(&bcare_ctl->attrs[1].attr);
1994 bcare_ctl->attrs[1].attr.name = "battery_care_health";
1995 bcare_ctl->attrs[1].attr.mode = S_IRUGO;
1996 bcare_ctl->attrs[1].show = sony_nc_battery_care_health_show;
1997
1998 ret = device_create_file(&pd->dev, &bcare_ctl->attrs[1]);
1999 if (ret)
2000 goto outlimiter;
2001
2002 return 0;
2003
2004outlimiter:
2005 device_remove_file(&pd->dev, &bcare_ctl->attrs[0]);
2006
2007outkzalloc:
2008 kfree(bcare_ctl);
2009 bcare_ctl = NULL;
2010
2011 return ret;
2012}
2013
2014static void sony_nc_battery_care_cleanup(struct platform_device *pd)
2015{
2016 if (bcare_ctl) {
2017 device_remove_file(&pd->dev, &bcare_ctl->attrs[0]);
2018 if (bcare_ctl->handle != 0x0115)
2019 device_remove_file(&pd->dev, &bcare_ctl->attrs[1]);
2020
2021 kfree(bcare_ctl);
2022 bcare_ctl = NULL;
2023 }
2024}
2025
2026struct snc_thermal_ctrl {
2027 unsigned int mode;
2028 unsigned int profiles;
2029 struct device_attribute mode_attr;
2030 struct device_attribute profiles_attr;
2031};
2032static struct snc_thermal_ctrl *th_handle;
2033
2034#define THM_PROFILE_MAX 3
2035static const char * const snc_thermal_profiles[] = {
2036 "balanced",
2037 "silent",
2038 "performance"
2039};
2040
2041static int sony_nc_thermal_mode_set(unsigned short mode)
2042{
2043 unsigned int result;
2044
2045 /* the thermal profile seems to be a two bit bitmask:
2046 * lsb -> silent
2047 * msb -> performance
2048 * no bit set is the normal operation and is always valid
2049 * Some vaio models only have "balanced" and "performance"
2050 */
2051 if ((mode && !(th_handle->profiles & mode)) || mode >= THM_PROFILE_MAX)
2052 return -EINVAL;
2053
2054 if (sony_call_snc_handle(0x0122, mode << 0x10 | 0x0200, &result))
2055 return -EIO;
2056
2057 th_handle->mode = mode;
2058
2059 return 0;
2060}
2061
2062static int sony_nc_thermal_mode_get(void)
2063{
2064 unsigned int result;
2065
2066 if (sony_call_snc_handle(0x0122, 0x0100, &result))
2067 return -EIO;
2068
2069 return result & 0xff;
2070}
2071
2072static ssize_t sony_nc_thermal_profiles_show(struct device *dev,
2073 struct device_attribute *attr, char *buffer)
2074{
2075 short cnt;
2076 size_t idx = 0;
2077
2078 for (cnt = 0; cnt < THM_PROFILE_MAX; cnt++) {
2079 if (!cnt || (th_handle->profiles & cnt))
2080 idx += snprintf(buffer + idx, PAGE_SIZE - idx, "%s ",
2081 snc_thermal_profiles[cnt]);
2082 }
2083 idx += snprintf(buffer + idx, PAGE_SIZE - idx, "\n");
2084
2085 return idx;
2086}
2087
2088static ssize_t sony_nc_thermal_mode_store(struct device *dev,
2089 struct device_attribute *attr,
2090 const char *buffer, size_t count)
2091{
2092 unsigned short cmd;
2093 size_t len = count;
2094
2095 if (count == 0)
2096 return -EINVAL;
2097
2098 /* skip the newline if present */
2099 if (buffer[len - 1] == '\n')
2100 len--;
2101
2102 for (cmd = 0; cmd < THM_PROFILE_MAX; cmd++)
2103 if (strncmp(buffer, snc_thermal_profiles[cmd], len) == 0)
2104 break;
2105
2106 if (sony_nc_thermal_mode_set(cmd))
2107 return -EIO;
2108
2109 return count;
2110}
2111
2112static ssize_t sony_nc_thermal_mode_show(struct device *dev,
2113 struct device_attribute *attr, char *buffer)
2114{
2115 ssize_t count = 0;
2116 unsigned int mode = sony_nc_thermal_mode_get();
2117
2118 if (mode < 0)
2119 return mode;
2120
2121 count = snprintf(buffer, PAGE_SIZE, "%s\n", snc_thermal_profiles[mode]);
2122
2123 return count;
2124}
2125
2126static int sony_nc_thermal_setup(struct platform_device *pd)
2127{
2128 int ret = 0;
2129 th_handle = kzalloc(sizeof(struct snc_thermal_ctrl), GFP_KERNEL);
2130 if (!th_handle)
2131 return -ENOMEM;
2132
2133 ret = sony_call_snc_handle(0x0122, 0x0000, &th_handle->profiles);
2134 if (ret) {
2135 pr_warn("couldn't to read the thermal profiles\n");
2136 goto outkzalloc;
2137 }
2138
2139 ret = sony_nc_thermal_mode_get();
2140 if (ret < 0) {
2141 pr_warn("couldn't to read the current thermal profile");
2142 goto outkzalloc;
2143 }
2144 th_handle->mode = ret;
2145
2146 sysfs_attr_init(&th_handle->profiles_attr.attr);
2147 th_handle->profiles_attr.attr.name = "thermal_profiles";
2148 th_handle->profiles_attr.attr.mode = S_IRUGO;
2149 th_handle->profiles_attr.show = sony_nc_thermal_profiles_show;
2150
2151 sysfs_attr_init(&th_handle->mode_attr.attr);
2152 th_handle->mode_attr.attr.name = "thermal_control";
2153 th_handle->mode_attr.attr.mode = S_IRUGO | S_IWUSR;
2154 th_handle->mode_attr.show = sony_nc_thermal_mode_show;
2155 th_handle->mode_attr.store = sony_nc_thermal_mode_store;
2156
2157 ret = device_create_file(&pd->dev, &th_handle->profiles_attr);
2158 if (ret)
2159 goto outkzalloc;
2160
2161 ret = device_create_file(&pd->dev, &th_handle->mode_attr);
2162 if (ret)
2163 goto outprofiles;
2164
2165 return 0;
2166
2167outprofiles:
2168 device_remove_file(&pd->dev, &th_handle->profiles_attr);
2169outkzalloc:
2170 kfree(th_handle);
2171 th_handle = NULL;
2172 return ret;
2173}
2174
2175static void sony_nc_thermal_cleanup(struct platform_device *pd)
2176{
2177 if (th_handle) {
2178 device_remove_file(&pd->dev, &th_handle->profiles_attr);
2179 device_remove_file(&pd->dev, &th_handle->mode_attr);
2180 kfree(th_handle);
2181 th_handle = NULL;
2182 }
2183}
2184
2185static void sony_nc_thermal_resume(void)
2186{
2187 unsigned int status = sony_nc_thermal_mode_get();
2188
2189 if (status != th_handle->mode)
2190 sony_nc_thermal_mode_set(th_handle->mode);
2191}
2192
2193/* resume on LID open */
2194struct snc_lid_resume_control {
2195 struct device_attribute attrs[3];
2196 unsigned int status;
2197};
2198static struct snc_lid_resume_control *lid_ctl;
2199
2200static ssize_t sony_nc_lid_resume_store(struct device *dev,
2201 struct device_attribute *attr,
2202 const char *buffer, size_t count)
2203{
2204 unsigned int result, pos;
2205 unsigned long value;
2206 if (count > 31)
2207 return -EINVAL;
2208
2209 if (kstrtoul(buffer, 10, &value) || value > 1)
2210 return -EINVAL;
2211
2212 /* the value we have to write to SNC is a bitmask:
2213 * +--------------+
2214 * | S3 | S4 | S5 |
2215 * +--------------+
2216 * 2 1 0
2217 */
2218 if (strcmp(attr->attr.name, "lid_resume_S3") == 0)
2219 pos = 2;
2220 else if (strcmp(attr->attr.name, "lid_resume_S4") == 0)
2221 pos = 1;
2222 else if (strcmp(attr->attr.name, "lid_resume_S5") == 0)
2223 pos = 0;
2224 else
2225 return -EINVAL;
2226
2227 if (value)
2228 value = lid_ctl->status | (1 << pos);
2229 else
2230 value = lid_ctl->status & ~(1 << pos);
2231
2232 if (sony_call_snc_handle(0x0119, value << 0x10 | 0x0100, &result))
2233 return -EIO;
2234
2235 lid_ctl->status = value;
2236
2237 return count;
2238}
2239
2240static ssize_t sony_nc_lid_resume_show(struct device *dev,
2241 struct device_attribute *attr, char *buffer)
2242{
2243 unsigned int pos;
2244
2245 if (strcmp(attr->attr.name, "lid_resume_S3") == 0)
2246 pos = 2;
2247 else if (strcmp(attr->attr.name, "lid_resume_S4") == 0)
2248 pos = 1;
2249 else if (strcmp(attr->attr.name, "lid_resume_S5") == 0)
2250 pos = 0;
2251 else
2252 return -EINVAL;
2253
2254 return snprintf(buffer, PAGE_SIZE, "%d\n",
2255 (lid_ctl->status >> pos) & 0x01);
2256}
2257
2258static int sony_nc_lid_resume_setup(struct platform_device *pd)
2259{
2260 unsigned int result;
2261 int i;
2262
2263 if (sony_call_snc_handle(0x0119, 0x0000, &result))
2264 return -EIO;
2265
2266 lid_ctl = kzalloc(sizeof(struct snc_lid_resume_control), GFP_KERNEL);
2267 if (!lid_ctl)
2268 return -ENOMEM;
2269
2270 lid_ctl->status = result & 0x7;
2271
2272 sysfs_attr_init(&lid_ctl->attrs[0].attr);
2273 lid_ctl->attrs[0].attr.name = "lid_resume_S3";
2274 lid_ctl->attrs[0].attr.mode = S_IRUGO | S_IWUSR;
2275 lid_ctl->attrs[0].show = sony_nc_lid_resume_show;
2276 lid_ctl->attrs[0].store = sony_nc_lid_resume_store;
2277
2278 sysfs_attr_init(&lid_ctl->attrs[1].attr);
2279 lid_ctl->attrs[1].attr.name = "lid_resume_S4";
2280 lid_ctl->attrs[1].attr.mode = S_IRUGO | S_IWUSR;
2281 lid_ctl->attrs[1].show = sony_nc_lid_resume_show;
2282 lid_ctl->attrs[1].store = sony_nc_lid_resume_store;
2283
2284 sysfs_attr_init(&lid_ctl->attrs[2].attr);
2285 lid_ctl->attrs[2].attr.name = "lid_resume_S5";
2286 lid_ctl->attrs[2].attr.mode = S_IRUGO | S_IWUSR;
2287 lid_ctl->attrs[2].show = sony_nc_lid_resume_show;
2288 lid_ctl->attrs[2].store = sony_nc_lid_resume_store;
2289
2290 for (i = 0; i < 3; i++) {
2291 result = device_create_file(&pd->dev, &lid_ctl->attrs[i]);
2292 if (result)
2293 goto liderror;
2294 }
2295
2296 return 0;
2297
2298liderror:
2299 for (; i > 0; i--)
2300 device_remove_file(&pd->dev, &lid_ctl->attrs[i]);
2301
2302 kfree(lid_ctl);
2303 lid_ctl = NULL;
2304
2305 return result;
2306}
2307
2308static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
2309{
2310 int i;
2311
2312 if (lid_ctl) {
2313 for (i = 0; i < 3; i++)
2314 device_remove_file(&pd->dev, &lid_ctl->attrs[i]);
2315
2316 kfree(lid_ctl);
2317 lid_ctl = NULL;
2318 }
2319}
2320
2321/* High speed charging function */
2322static struct device_attribute *hsc_handle;
2323
2324static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
2325 struct device_attribute *attr,
2326 const char *buffer, size_t count)
2327{
2328 unsigned int result;
2329 unsigned long value;
2330
2331 if (count > 31)
2332 return -EINVAL;
2333
2334 if (kstrtoul(buffer, 10, &value) || value > 1)
2335 return -EINVAL;
2336
2337 if (sony_call_snc_handle(0x0131, value << 0x10 | 0x0200, &result))
2338 return -EIO;
2339
2340 return count;
2341}
2342
2343static ssize_t sony_nc_highspeed_charging_show(struct device *dev,
2344 struct device_attribute *attr, char *buffer)
2345{
2346 unsigned int result;
2347
2348 if (sony_call_snc_handle(0x0131, 0x0100, &result))
2349 return -EIO;
2350
2351 return snprintf(buffer, PAGE_SIZE, "%d\n", result & 0x01);
2352}
2353
2354static int sony_nc_highspeed_charging_setup(struct platform_device *pd)
2355{
2356 unsigned int result;
2357
2358 if (sony_call_snc_handle(0x0131, 0x0000, &result) || !(result & 0x01)) {
2359 /* some models advertise the handle but have no implementation
2360 * for it
2361 */
2362 pr_info("No High Speed Charging capability found\n");
2363 return 0;
2364 }
2365
2366 hsc_handle = kzalloc(sizeof(struct device_attribute), GFP_KERNEL);
2367 if (!hsc_handle)
2368 return -ENOMEM;
2369
2370 sysfs_attr_init(&hsc_handle->attr);
2371 hsc_handle->attr.name = "battery_highspeed_charging";
2372 hsc_handle->attr.mode = S_IRUGO | S_IWUSR;
2373 hsc_handle->show = sony_nc_highspeed_charging_show;
2374 hsc_handle->store = sony_nc_highspeed_charging_store;
2375
2376 result = device_create_file(&pd->dev, hsc_handle);
2377 if (result) {
2378 kfree(hsc_handle);
2379 hsc_handle = NULL;
2380 return result;
2381 }
2382
2383 return 0;
2384}
2385
2386static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
2387{
2388 if (hsc_handle) {
2389 device_remove_file(&pd->dev, hsc_handle);
2390 kfree(hsc_handle);
2391 hsc_handle = NULL;
2392 }
2393}
2394
2395/* Touchpad enable/disable */
2396struct touchpad_control {
2397 struct device_attribute attr;
2398 int handle;
2399};
2400static struct touchpad_control *tp_ctl;
2401
2402static ssize_t sony_nc_touchpad_store(struct device *dev,
2403 struct device_attribute *attr, const char *buffer, size_t count)
2404{
2405 unsigned int result;
2406 unsigned long value;
2407
2408 if (count > 31)
2409 return -EINVAL;
2410
2411 if (kstrtoul(buffer, 10, &value) || value > 1)
2412 return -EINVAL;
2413
2414 /* sysfs: 0 disabled, 1 enabled
2415 * EC: 0 enabled, 1 disabled
2416 */
2417 if (sony_call_snc_handle(tp_ctl->handle,
2418 (!value << 0x10) | 0x100, &result))
2419 return -EIO;
2420
2421 return count;
2422}
2423
2424static ssize_t sony_nc_touchpad_show(struct device *dev,
2425 struct device_attribute *attr, char *buffer)
2426{
2427 unsigned int result;
2428
2429 if (sony_call_snc_handle(tp_ctl->handle, 0x000, &result))
2430 return -EINVAL;
2431
2432 return snprintf(buffer, PAGE_SIZE, "%d\n", !(result & 0x01));
2433}
2434
2435static int sony_nc_touchpad_setup(struct platform_device *pd,
2436 unsigned int handle)
2437{
2438 int ret = 0;
2439
2440 tp_ctl = kzalloc(sizeof(struct touchpad_control), GFP_KERNEL);
2441 if (!tp_ctl)
2442 return -ENOMEM;
2443
2444 tp_ctl->handle = handle;
2445
2446 sysfs_attr_init(&tp_ctl->attr.attr);
2447 tp_ctl->attr.attr.name = "touchpad";
2448 tp_ctl->attr.attr.mode = S_IRUGO | S_IWUSR;
2449 tp_ctl->attr.show = sony_nc_touchpad_show;
2450 tp_ctl->attr.store = sony_nc_touchpad_store;
2451
2452 ret = device_create_file(&pd->dev, &tp_ctl->attr);
2453 if (ret) {
2454 kfree(tp_ctl);
2455 tp_ctl = NULL;
2456 }
2457
2458 return ret;
2459}
2460
2461static void sony_nc_touchpad_cleanup(struct platform_device *pd)
2462{
2463 if (tp_ctl) {
2464 device_remove_file(&pd->dev, &tp_ctl->attr);
2465 kfree(tp_ctl);
2466 tp_ctl = NULL;
2467 }
1561} 2468}
1562 2469
1563static void sony_nc_backlight_ng_read_limits(int handle, 2470static void sony_nc_backlight_ng_read_limits(int handle,
1564 struct sony_backlight_props *props) 2471 struct sony_backlight_props *props)
1565{ 2472{
1566 int offset; 2473 u64 offset;
1567 acpi_status status; 2474 int i;
1568 u8 brlvl, i;
1569 u8 min = 0xff, max = 0x00; 2475 u8 min = 0xff, max = 0x00;
1570 struct acpi_object_list params; 2476 unsigned char buffer[32] = { 0 };
1571 union acpi_object in_obj;
1572 union acpi_object *lvl_enum;
1573 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1574 2477
1575 props->handle = handle; 2478 props->handle = handle;
1576 props->offset = 0; 2479 props->offset = 0;
@@ -1583,50 +2486,31 @@ static void sony_nc_backlight_ng_read_limits(int handle,
1583 /* try to read the boundaries from ACPI tables, if we fail the above 2486 /* try to read the boundaries from ACPI tables, if we fail the above
1584 * defaults should be reasonable 2487 * defaults should be reasonable
1585 */ 2488 */
1586 params.count = 1; 2489 i = sony_nc_buffer_call(sony_nc_acpi_handle, "SN06", &offset, buffer,
1587 params.pointer = &in_obj; 2490 32);
1588 in_obj.type = ACPI_TYPE_INTEGER; 2491 if (i < 0)
1589 in_obj.integer.value = offset;
1590 status = acpi_evaluate_object(sony_nc_acpi_handle, "SN06", &params,
1591 &buffer);
1592 if (ACPI_FAILURE(status))
1593 return; 2492 return;
1594 2493
1595 lvl_enum = (union acpi_object *) buffer.pointer;
1596 if (!lvl_enum) {
1597 pr_err("No SN06 return object.");
1598 return;
1599 }
1600 if (lvl_enum->type != ACPI_TYPE_BUFFER) {
1601 pr_err("Invalid SN06 return object 0x%.2x\n",
1602 lvl_enum->type);
1603 goto out_invalid;
1604 }
1605
1606 /* the buffer lists brightness levels available, brightness levels are 2494 /* the buffer lists brightness levels available, brightness levels are
1607 * from 0 to 8 in the array, other values are used by ALS control. 2495 * from position 0 to 8 in the array, other values are used by ALS
2496 * control.
1608 */ 2497 */
1609 for (i = 0; i < 9 && i < lvl_enum->buffer.length; i++) { 2498 for (i = 0; i < 9 && i < ARRAY_SIZE(buffer); i++) {
1610 2499
1611 brlvl = *(lvl_enum->buffer.pointer + i); 2500 dprintk("Brightness level: %d\n", buffer[i]);
1612 dprintk("Brightness level: %d\n", brlvl);
1613 2501
1614 if (!brlvl) 2502 if (!buffer[i])
1615 break; 2503 break;
1616 2504
1617 if (brlvl > max) 2505 if (buffer[i] > max)
1618 max = brlvl; 2506 max = buffer[i];
1619 if (brlvl < min) 2507 if (buffer[i] < min)
1620 min = brlvl; 2508 min = buffer[i];
1621 } 2509 }
1622 props->offset = min; 2510 props->offset = min;
1623 props->maxlvl = max; 2511 props->maxlvl = max;
1624 dprintk("Brightness levels: min=%d max=%d\n", props->offset, 2512 dprintk("Brightness levels: min=%d max=%d\n", props->offset,
1625 props->maxlvl); 2513 props->maxlvl);
1626
1627out_invalid:
1628 kfree(buffer.pointer);
1629 return;
1630} 2514}
1631 2515
1632static void sony_nc_backlight_setup(void) 2516static void sony_nc_backlight_setup(void)
@@ -1715,28 +2599,25 @@ static int sony_nc_add(struct acpi_device *device)
1715 2599
1716 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON", 2600 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "ECON",
1717 &handle))) { 2601 &handle))) {
1718 if (acpi_callsetfunc(sony_nc_acpi_handle, "ECON", 1, NULL)) 2602 int arg = 1;
2603 if (sony_nc_int_call(sony_nc_acpi_handle, "ECON", &arg, NULL))
1719 dprintk("ECON Method failed\n"); 2604 dprintk("ECON Method failed\n");
1720 } 2605 }
1721 2606
1722 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00", 2607 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00",
1723 &handle))) { 2608 &handle))) {
1724 dprintk("Doing SNC setup\n"); 2609 dprintk("Doing SNC setup\n");
2610 /* retrieve the available handles */
1725 result = sony_nc_handles_setup(sony_pf_device); 2611 result = sony_nc_handles_setup(sony_pf_device);
1726 if (result) 2612 if (!result)
1727 goto outpresent; 2613 sony_nc_function_setup(device, sony_pf_device);
1728 result = sony_nc_kbd_backlight_setup(sony_pf_device);
1729 if (result)
1730 goto outsnc;
1731 sony_nc_function_setup(device);
1732 sony_nc_rfkill_setup(device);
1733 } 2614 }
1734 2615
1735 /* setup input devices and helper fifo */ 2616 /* setup input devices and helper fifo */
1736 result = sony_laptop_setup_input(device); 2617 result = sony_laptop_setup_input(device);
1737 if (result) { 2618 if (result) {
1738 pr_err("Unable to create input devices\n"); 2619 pr_err("Unable to create input devices\n");
1739 goto outkbdbacklight; 2620 goto outsnc;
1740 } 2621 }
1741 2622
1742 if (acpi_video_backlight_support()) { 2623 if (acpi_video_backlight_support()) {
@@ -1794,10 +2675,8 @@ static int sony_nc_add(struct acpi_device *device)
1794 2675
1795 sony_laptop_remove_input(); 2676 sony_laptop_remove_input();
1796 2677
1797 outkbdbacklight:
1798 sony_nc_kbd_backlight_cleanup(sony_pf_device);
1799
1800 outsnc: 2678 outsnc:
2679 sony_nc_function_cleanup(sony_pf_device);
1801 sony_nc_handles_cleanup(sony_pf_device); 2680 sony_nc_handles_cleanup(sony_pf_device);
1802 2681
1803 outpresent: 2682 outpresent:
@@ -1820,11 +2699,10 @@ static int sony_nc_remove(struct acpi_device *device, int type)
1820 device_remove_file(&sony_pf_device->dev, &item->devattr); 2699 device_remove_file(&sony_pf_device->dev, &item->devattr);
1821 } 2700 }
1822 2701
1823 sony_nc_kbd_backlight_cleanup(sony_pf_device); 2702 sony_nc_function_cleanup(sony_pf_device);
1824 sony_nc_handles_cleanup(sony_pf_device); 2703 sony_nc_handles_cleanup(sony_pf_device);
1825 sony_pf_remove(); 2704 sony_pf_remove();
1826 sony_laptop_remove_input(); 2705 sony_laptop_remove_input();
1827 sony_nc_rfkill_cleanup();
1828 dprintk(SONY_NC_DRIVER_NAME " removed.\n"); 2706 dprintk(SONY_NC_DRIVER_NAME " removed.\n");
1829 2707
1830 return 0; 2708 return 0;
@@ -2437,7 +3315,9 @@ static ssize_t sony_pic_wwanpower_store(struct device *dev,
2437 if (count > 31) 3315 if (count > 31)
2438 return -EINVAL; 3316 return -EINVAL;
2439 3317
2440 value = simple_strtoul(buffer, NULL, 10); 3318 if (kstrtoul(buffer, 10, &value))
3319 return -EINVAL;
3320
2441 mutex_lock(&spic_dev.lock); 3321 mutex_lock(&spic_dev.lock);
2442 __sony_pic_set_wwanpower(value); 3322 __sony_pic_set_wwanpower(value);
2443 mutex_unlock(&spic_dev.lock); 3323 mutex_unlock(&spic_dev.lock);
@@ -2474,7 +3354,9 @@ static ssize_t sony_pic_bluetoothpower_store(struct device *dev,
2474 if (count > 31) 3354 if (count > 31)
2475 return -EINVAL; 3355 return -EINVAL;
2476 3356
2477 value = simple_strtoul(buffer, NULL, 10); 3357 if (kstrtoul(buffer, 10, &value))
3358 return -EINVAL;
3359
2478 mutex_lock(&spic_dev.lock); 3360 mutex_lock(&spic_dev.lock);
2479 __sony_pic_set_bluetoothpower(value); 3361 __sony_pic_set_bluetoothpower(value);
2480 mutex_unlock(&spic_dev.lock); 3362 mutex_unlock(&spic_dev.lock);
@@ -2513,7 +3395,9 @@ static ssize_t sony_pic_fanspeed_store(struct device *dev,
2513 if (count > 31) 3395 if (count > 31)
2514 return -EINVAL; 3396 return -EINVAL;
2515 3397
2516 value = simple_strtoul(buffer, NULL, 10); 3398 if (kstrtoul(buffer, 10, &value))
3399 return -EINVAL;
3400
2517 if (sony_pic_set_fanspeed(value)) 3401 if (sony_pic_set_fanspeed(value))
2518 return -EIO; 3402 return -EIO;
2519 3403
@@ -2671,7 +3555,8 @@ static long sonypi_misc_ioctl(struct file *fp, unsigned int cmd,
2671 ret = -EIO; 3555 ret = -EIO;
2672 break; 3556 break;
2673 } 3557 }
2674 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) { 3558 if (sony_nc_int_call(sony_nc_acpi_handle, "GBRT", NULL,
3559 &value)) {
2675 ret = -EIO; 3560 ret = -EIO;
2676 break; 3561 break;
2677 } 3562 }
@@ -2688,8 +3573,9 @@ static long sonypi_misc_ioctl(struct file *fp, unsigned int cmd,
2688 ret = -EFAULT; 3573 ret = -EFAULT;
2689 break; 3574 break;
2690 } 3575 }
2691 if (acpi_callsetfunc(sony_nc_acpi_handle, "SBRT", 3576 value = (val8 >> 5) + 1;
2692 (val8 >> 5) + 1, NULL)) { 3577 if (sony_nc_int_call(sony_nc_acpi_handle, "SBRT", &value,
3578 NULL)) {
2693 ret = -EIO; 3579 ret = -EIO;
2694 break; 3580 break;
2695 } 3581 }
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index d68c0002f4a2..8b5610d88418 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3402,7 +3402,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
3402 /* Do not issue duplicate brightness change events to 3402 /* Do not issue duplicate brightness change events to
3403 * userspace. tpacpi_detect_brightness_capabilities() must have 3403 * userspace. tpacpi_detect_brightness_capabilities() must have
3404 * been called before this point */ 3404 * been called before this point */
3405 if (tp_features.bright_acpimode && acpi_video_backlight_support()) { 3405 if (acpi_video_backlight_support()) {
3406 pr_info("This ThinkPad has standard ACPI backlight " 3406 pr_info("This ThinkPad has standard ACPI backlight "
3407 "brightness control, supported by the ACPI " 3407 "brightness control, supported by the ACPI "
3408 "video driver\n"); 3408 "video driver\n");
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index 57787d87d9a4..dab10f6edcd4 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -95,6 +95,7 @@ MODULE_LICENSE("GPL");
95 95
96/* registers */ 96/* registers */
97#define HCI_FAN 0x0004 97#define HCI_FAN 0x0004
98#define HCI_TR_BACKLIGHT 0x0005
98#define HCI_SYSTEM_EVENT 0x0016 99#define HCI_SYSTEM_EVENT 0x0016
99#define HCI_VIDEO_OUT 0x001c 100#define HCI_VIDEO_OUT 0x001c
100#define HCI_HOTKEY_EVENT 0x001e 101#define HCI_HOTKEY_EVENT 0x001e
@@ -134,6 +135,7 @@ struct toshiba_acpi_dev {
134 unsigned int system_event_supported:1; 135 unsigned int system_event_supported:1;
135 unsigned int ntfy_supported:1; 136 unsigned int ntfy_supported:1;
136 unsigned int info_supported:1; 137 unsigned int info_supported:1;
138 unsigned int tr_backlight_supported:1;
137 139
138 struct mutex mutex; 140 struct mutex mutex;
139}; 141};
@@ -478,34 +480,70 @@ static const struct rfkill_ops toshiba_rfk_ops = {
478 .poll = bt_rfkill_poll, 480 .poll = bt_rfkill_poll,
479}; 481};
480 482
483static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
484{
485 u32 hci_result;
486 u32 status;
487
488 hci_read1(dev, HCI_TR_BACKLIGHT, &status, &hci_result);
489 *enabled = !status;
490 return hci_result == HCI_SUCCESS ? 0 : -EIO;
491}
492
493static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
494{
495 u32 hci_result;
496 u32 value = !enable;
497
498 hci_write1(dev, HCI_TR_BACKLIGHT, value, &hci_result);
499 return hci_result == HCI_SUCCESS ? 0 : -EIO;
500}
501
481static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; 502static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
482 503
483static int get_lcd(struct backlight_device *bd) 504static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
484{ 505{
485 struct toshiba_acpi_dev *dev = bl_get_data(bd);
486 u32 hci_result; 506 u32 hci_result;
487 u32 value; 507 u32 value;
508 int brightness = 0;
509
510 if (dev->tr_backlight_supported) {
511 bool enabled;
512 int ret = get_tr_backlight_status(dev, &enabled);
513 if (ret)
514 return ret;
515 if (enabled)
516 return 0;
517 brightness++;
518 }
488 519
489 hci_read1(dev, HCI_LCD_BRIGHTNESS, &value, &hci_result); 520 hci_read1(dev, HCI_LCD_BRIGHTNESS, &value, &hci_result);
490 if (hci_result == HCI_SUCCESS) 521 if (hci_result == HCI_SUCCESS)
491 return (value >> HCI_LCD_BRIGHTNESS_SHIFT); 522 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
492 523
493 return -EIO; 524 return -EIO;
494} 525}
495 526
527static int get_lcd_brightness(struct backlight_device *bd)
528{
529 struct toshiba_acpi_dev *dev = bl_get_data(bd);
530 return __get_lcd_brightness(dev);
531}
532
496static int lcd_proc_show(struct seq_file *m, void *v) 533static int lcd_proc_show(struct seq_file *m, void *v)
497{ 534{
498 struct toshiba_acpi_dev *dev = m->private; 535 struct toshiba_acpi_dev *dev = m->private;
499 int value; 536 int value;
537 int levels;
500 538
501 if (!dev->backlight_dev) 539 if (!dev->backlight_dev)
502 return -ENODEV; 540 return -ENODEV;
503 541
504 value = get_lcd(dev->backlight_dev); 542 levels = dev->backlight_dev->props.max_brightness + 1;
543 value = get_lcd_brightness(dev->backlight_dev);
505 if (value >= 0) { 544 if (value >= 0) {
506 seq_printf(m, "brightness: %d\n", value); 545 seq_printf(m, "brightness: %d\n", value);
507 seq_printf(m, "brightness_levels: %d\n", 546 seq_printf(m, "brightness_levels: %d\n", levels);
508 HCI_LCD_BRIGHTNESS_LEVELS);
509 return 0; 547 return 0;
510 } 548 }
511 549
@@ -518,10 +556,19 @@ static int lcd_proc_open(struct inode *inode, struct file *file)
518 return single_open(file, lcd_proc_show, PDE(inode)->data); 556 return single_open(file, lcd_proc_show, PDE(inode)->data);
519} 557}
520 558
521static int set_lcd(struct toshiba_acpi_dev *dev, int value) 559static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
522{ 560{
523 u32 hci_result; 561 u32 hci_result;
524 562
563 if (dev->tr_backlight_supported) {
564 bool enable = !value;
565 int ret = set_tr_backlight_status(dev, enable);
566 if (ret)
567 return ret;
568 if (value)
569 value--;
570 }
571
525 value = value << HCI_LCD_BRIGHTNESS_SHIFT; 572 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
526 hci_write1(dev, HCI_LCD_BRIGHTNESS, value, &hci_result); 573 hci_write1(dev, HCI_LCD_BRIGHTNESS, value, &hci_result);
527 return hci_result == HCI_SUCCESS ? 0 : -EIO; 574 return hci_result == HCI_SUCCESS ? 0 : -EIO;
@@ -530,7 +577,7 @@ static int set_lcd(struct toshiba_acpi_dev *dev, int value)
530static int set_lcd_status(struct backlight_device *bd) 577static int set_lcd_status(struct backlight_device *bd)
531{ 578{
532 struct toshiba_acpi_dev *dev = bl_get_data(bd); 579 struct toshiba_acpi_dev *dev = bl_get_data(bd);
533 return set_lcd(dev, bd->props.brightness); 580 return set_lcd_brightness(dev, bd->props.brightness);
534} 581}
535 582
536static ssize_t lcd_proc_write(struct file *file, const char __user *buf, 583static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
@@ -541,6 +588,7 @@ static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
541 size_t len; 588 size_t len;
542 int value; 589 int value;
543 int ret; 590 int ret;
591 int levels = dev->backlight_dev->props.max_brightness + 1;
544 592
545 len = min(count, sizeof(cmd) - 1); 593 len = min(count, sizeof(cmd) - 1);
546 if (copy_from_user(cmd, buf, len)) 594 if (copy_from_user(cmd, buf, len))
@@ -548,8 +596,8 @@ static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
548 cmd[len] = '\0'; 596 cmd[len] = '\0';
549 597
550 if (sscanf(cmd, " brightness : %i", &value) == 1 && 598 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
551 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) { 599 value >= 0 && value < levels) {
552 ret = set_lcd(dev, value); 600 ret = set_lcd_brightness(dev, value);
553 if (ret == 0) 601 if (ret == 0)
554 ret = count; 602 ret = count;
555 } else { 603 } else {
@@ -860,8 +908,9 @@ static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
860} 908}
861 909
862static const struct backlight_ops toshiba_backlight_data = { 910static const struct backlight_ops toshiba_backlight_data = {
863 .get_brightness = get_lcd, 911 .options = BL_CORE_SUSPENDRESUME,
864 .update_status = set_lcd_status, 912 .get_brightness = get_lcd_brightness,
913 .update_status = set_lcd_status,
865}; 914};
866 915
867static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str, 916static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
@@ -1020,6 +1069,56 @@ static int __devinit toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
1020 return error; 1069 return error;
1021} 1070}
1022 1071
1072static int __devinit toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
1073{
1074 struct backlight_properties props;
1075 int brightness;
1076 int ret;
1077 bool enabled;
1078
1079 /*
1080 * Some machines don't support the backlight methods at all, and
1081 * others support it read-only. Either of these is pretty useless,
1082 * so only register the backlight device if the backlight method
1083 * supports both reads and writes.
1084 */
1085 brightness = __get_lcd_brightness(dev);
1086 if (brightness < 0)
1087 return 0;
1088 ret = set_lcd_brightness(dev, brightness);
1089 if (ret) {
1090 pr_debug("Backlight method is read-only, disabling backlight support\n");
1091 return 0;
1092 }
1093
1094 /* Determine whether or not BIOS supports transflective backlight */
1095 ret = get_tr_backlight_status(dev, &enabled);
1096 dev->tr_backlight_supported = !ret;
1097
1098 memset(&props, 0, sizeof(props));
1099 props.type = BACKLIGHT_PLATFORM;
1100 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
1101
1102 /* adding an extra level and having 0 change to transflective mode */
1103 if (dev->tr_backlight_supported)
1104 props.max_brightness++;
1105
1106 dev->backlight_dev = backlight_device_register("toshiba",
1107 &dev->acpi_dev->dev,
1108 dev,
1109 &toshiba_backlight_data,
1110 &props);
1111 if (IS_ERR(dev->backlight_dev)) {
1112 ret = PTR_ERR(dev->backlight_dev);
1113 pr_err("Could not register toshiba backlight device\n");
1114 dev->backlight_dev = NULL;
1115 return ret;
1116 }
1117
1118 dev->backlight_dev->props.brightness = brightness;
1119 return 0;
1120}
1121
1023static int toshiba_acpi_remove(struct acpi_device *acpi_dev, int type) 1122static int toshiba_acpi_remove(struct acpi_device *acpi_dev, int type)
1024{ 1123{
1025 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); 1124 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
@@ -1078,7 +1177,6 @@ static int __devinit toshiba_acpi_add(struct acpi_device *acpi_dev)
1078 u32 dummy; 1177 u32 dummy;
1079 bool bt_present; 1178 bool bt_present;
1080 int ret = 0; 1179 int ret = 0;
1081 struct backlight_properties props;
1082 1180
1083 if (toshiba_acpi) 1181 if (toshiba_acpi)
1084 return -EBUSY; 1182 return -EBUSY;
@@ -1104,22 +1202,9 @@ static int __devinit toshiba_acpi_add(struct acpi_device *acpi_dev)
1104 1202
1105 mutex_init(&dev->mutex); 1203 mutex_init(&dev->mutex);
1106 1204
1107 memset(&props, 0, sizeof(props)); 1205 ret = toshiba_acpi_setup_backlight(dev);
1108 props.type = BACKLIGHT_PLATFORM; 1206 if (ret)
1109 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
1110 dev->backlight_dev = backlight_device_register("toshiba",
1111 &acpi_dev->dev,
1112 dev,
1113 &toshiba_backlight_data,
1114 &props);
1115 if (IS_ERR(dev->backlight_dev)) {
1116 ret = PTR_ERR(dev->backlight_dev);
1117
1118 pr_err("Could not register toshiba backlight device\n");
1119 dev->backlight_dev = NULL;
1120 goto error; 1207 goto error;
1121 }
1122 dev->backlight_dev->props.brightness = get_lcd(dev->backlight_dev);
1123 1208
1124 /* Register rfkill switch for Bluetooth */ 1209 /* Register rfkill switch for Bluetooth */
1125 if (hci_get_bt_present(dev, &bt_present) == HCI_SUCCESS && bt_present) { 1210 if (hci_get_bt_present(dev, &bt_present) == HCI_SUCCESS && bt_present) {
diff --git a/drivers/platform/x86/xo1-rfkill.c b/drivers/platform/x86/xo1-rfkill.c
index 41781ed8301c..b57ad8641480 100644
--- a/drivers/platform/x86/xo1-rfkill.c
+++ b/drivers/platform/x86/xo1-rfkill.c
@@ -15,15 +15,26 @@
15 15
16#include <asm/olpc.h> 16#include <asm/olpc.h>
17 17
18static bool card_blocked;
19
18static int rfkill_set_block(void *data, bool blocked) 20static int rfkill_set_block(void *data, bool blocked)
19{ 21{
20 unsigned char cmd; 22 unsigned char cmd;
23 int r;
24
25 if (blocked == card_blocked)
26 return 0;
27
21 if (blocked) 28 if (blocked)
22 cmd = EC_WLAN_ENTER_RESET; 29 cmd = EC_WLAN_ENTER_RESET;
23 else 30 else
24 cmd = EC_WLAN_LEAVE_RESET; 31 cmd = EC_WLAN_LEAVE_RESET;
25 32
26 return olpc_ec_cmd(cmd, NULL, 0, NULL, 0); 33 r = olpc_ec_cmd(cmd, NULL, 0, NULL, 0);
34 if (r == 0)
35 card_blocked = blocked;
36
37 return r;
27} 38}
28 39
29static const struct rfkill_ops rfkill_ops = { 40static const struct rfkill_ops rfkill_ops = {
diff --git a/drivers/rapidio/Kconfig b/drivers/rapidio/Kconfig
index bc8719238793..6194d35ebb97 100644
--- a/drivers/rapidio/Kconfig
+++ b/drivers/rapidio/Kconfig
@@ -22,6 +22,20 @@ config RAPIDIO_ENABLE_RX_TX_PORTS
22 ports for Input/Output direction to allow other traffic 22 ports for Input/Output direction to allow other traffic
23 than Maintenance transfers. 23 than Maintenance transfers.
24 24
25config RAPIDIO_DMA_ENGINE
26 bool "DMA Engine support for RapidIO"
27 depends on RAPIDIO
28 select DMADEVICES
29 select DMA_ENGINE
30 help
31 Say Y here if you want to use DMA Engine frameork for RapidIO data
32 transfers to/from target RIO devices. RapidIO uses NREAD and
33 NWRITE (NWRITE_R, SWRITE) requests to transfer data between local
34 memory and memory on remote target device. You need a DMA controller
35 capable to perform data transfers to/from RapidIO.
36
37 If you are unsure about this, say Y here.
38
25config RAPIDIO_DEBUG 39config RAPIDIO_DEBUG
26 bool "RapidIO subsystem debug messages" 40 bool "RapidIO subsystem debug messages"
27 depends on RAPIDIO 41 depends on RAPIDIO
diff --git a/drivers/rapidio/devices/Makefile b/drivers/rapidio/devices/Makefile
index 3b7b4e2dff7c..7b62860f34f8 100644
--- a/drivers/rapidio/devices/Makefile
+++ b/drivers/rapidio/devices/Makefile
@@ -3,3 +3,6 @@
3# 3#
4 4
5obj-$(CONFIG_RAPIDIO_TSI721) += tsi721.o 5obj-$(CONFIG_RAPIDIO_TSI721) += tsi721.o
6ifeq ($(CONFIG_RAPIDIO_DMA_ENGINE),y)
7obj-$(CONFIG_RAPIDIO_TSI721) += tsi721_dma.o
8endif
diff --git a/drivers/rapidio/devices/tsi721.c b/drivers/rapidio/devices/tsi721.c
index 30d2072f480b..722246cf20ab 100644
--- a/drivers/rapidio/devices/tsi721.c
+++ b/drivers/rapidio/devices/tsi721.c
@@ -108,6 +108,7 @@ static int tsi721_maint_dma(struct tsi721_device *priv, u32 sys_size,
108 u16 destid, u8 hopcount, u32 offset, int len, 108 u16 destid, u8 hopcount, u32 offset, int len,
109 u32 *data, int do_wr) 109 u32 *data, int do_wr)
110{ 110{
111 void __iomem *regs = priv->regs + TSI721_DMAC_BASE(priv->mdma.ch_id);
111 struct tsi721_dma_desc *bd_ptr; 112 struct tsi721_dma_desc *bd_ptr;
112 u32 rd_count, swr_ptr, ch_stat; 113 u32 rd_count, swr_ptr, ch_stat;
113 int i, err = 0; 114 int i, err = 0;
@@ -116,10 +117,9 @@ static int tsi721_maint_dma(struct tsi721_device *priv, u32 sys_size,
116 if (offset > (RIO_MAINT_SPACE_SZ - len) || (len != sizeof(u32))) 117 if (offset > (RIO_MAINT_SPACE_SZ - len) || (len != sizeof(u32)))
117 return -EINVAL; 118 return -EINVAL;
118 119
119 bd_ptr = priv->bdma[TSI721_DMACH_MAINT].bd_base; 120 bd_ptr = priv->mdma.bd_base;
120 121
121 rd_count = ioread32( 122 rd_count = ioread32(regs + TSI721_DMAC_DRDCNT);
122 priv->regs + TSI721_DMAC_DRDCNT(TSI721_DMACH_MAINT));
123 123
124 /* Initialize DMA descriptor */ 124 /* Initialize DMA descriptor */
125 bd_ptr[0].type_id = cpu_to_le32((DTYPE2 << 29) | (op << 19) | destid); 125 bd_ptr[0].type_id = cpu_to_le32((DTYPE2 << 29) | (op << 19) | destid);
@@ -134,19 +134,18 @@ static int tsi721_maint_dma(struct tsi721_device *priv, u32 sys_size,
134 mb(); 134 mb();
135 135
136 /* Start DMA operation */ 136 /* Start DMA operation */
137 iowrite32(rd_count + 2, 137 iowrite32(rd_count + 2, regs + TSI721_DMAC_DWRCNT);
138 priv->regs + TSI721_DMAC_DWRCNT(TSI721_DMACH_MAINT)); 138 ioread32(regs + TSI721_DMAC_DWRCNT);
139 ioread32(priv->regs + TSI721_DMAC_DWRCNT(TSI721_DMACH_MAINT));
140 i = 0; 139 i = 0;
141 140
142 /* Wait until DMA transfer is finished */ 141 /* Wait until DMA transfer is finished */
143 while ((ch_stat = ioread32(priv->regs + 142 while ((ch_stat = ioread32(regs + TSI721_DMAC_STS))
144 TSI721_DMAC_STS(TSI721_DMACH_MAINT))) & TSI721_DMAC_STS_RUN) { 143 & TSI721_DMAC_STS_RUN) {
145 udelay(1); 144 udelay(1);
146 if (++i >= 5000000) { 145 if (++i >= 5000000) {
147 dev_dbg(&priv->pdev->dev, 146 dev_dbg(&priv->pdev->dev,
148 "%s : DMA[%d] read timeout ch_status=%x\n", 147 "%s : DMA[%d] read timeout ch_status=%x\n",
149 __func__, TSI721_DMACH_MAINT, ch_stat); 148 __func__, priv->mdma.ch_id, ch_stat);
150 if (!do_wr) 149 if (!do_wr)
151 *data = 0xffffffff; 150 *data = 0xffffffff;
152 err = -EIO; 151 err = -EIO;
@@ -162,13 +161,10 @@ static int tsi721_maint_dma(struct tsi721_device *priv, u32 sys_size,
162 __func__, ch_stat); 161 __func__, ch_stat);
163 dev_dbg(&priv->pdev->dev, "OP=%d : destid=%x hc=%x off=%x\n", 162 dev_dbg(&priv->pdev->dev, "OP=%d : destid=%x hc=%x off=%x\n",
164 do_wr ? MAINT_WR : MAINT_RD, destid, hopcount, offset); 163 do_wr ? MAINT_WR : MAINT_RD, destid, hopcount, offset);
165 iowrite32(TSI721_DMAC_INT_ALL, 164 iowrite32(TSI721_DMAC_INT_ALL, regs + TSI721_DMAC_INT);
166 priv->regs + TSI721_DMAC_INT(TSI721_DMACH_MAINT)); 165 iowrite32(TSI721_DMAC_CTL_INIT, regs + TSI721_DMAC_CTL);
167 iowrite32(TSI721_DMAC_CTL_INIT,
168 priv->regs + TSI721_DMAC_CTL(TSI721_DMACH_MAINT));
169 udelay(10); 166 udelay(10);
170 iowrite32(0, priv->regs + 167 iowrite32(0, regs + TSI721_DMAC_DWRCNT);
171 TSI721_DMAC_DWRCNT(TSI721_DMACH_MAINT));
172 udelay(1); 168 udelay(1);
173 if (!do_wr) 169 if (!do_wr)
174 *data = 0xffffffff; 170 *data = 0xffffffff;
@@ -184,8 +180,8 @@ static int tsi721_maint_dma(struct tsi721_device *priv, u32 sys_size,
184 * NOTE: Skipping check and clear FIFO entries because we are waiting 180 * NOTE: Skipping check and clear FIFO entries because we are waiting
185 * for transfer to be completed. 181 * for transfer to be completed.
186 */ 182 */
187 swr_ptr = ioread32(priv->regs + TSI721_DMAC_DSWP(TSI721_DMACH_MAINT)); 183 swr_ptr = ioread32(regs + TSI721_DMAC_DSWP);
188 iowrite32(swr_ptr, priv->regs + TSI721_DMAC_DSRP(TSI721_DMACH_MAINT)); 184 iowrite32(swr_ptr, regs + TSI721_DMAC_DSRP);
189err_out: 185err_out:
190 186
191 return err; 187 return err;
@@ -541,6 +537,22 @@ static irqreturn_t tsi721_irqhandler(int irq, void *ptr)
541 tsi721_pw_handler(mport); 537 tsi721_pw_handler(mport);
542 } 538 }
543 539
540#ifdef CONFIG_RAPIDIO_DMA_ENGINE
541 if (dev_int & TSI721_DEV_INT_BDMA_CH) {
542 int ch;
543
544 if (dev_ch_int & TSI721_INT_BDMA_CHAN_M) {
545 dev_dbg(&priv->pdev->dev,
546 "IRQ from DMA channel 0x%08x\n", dev_ch_int);
547
548 for (ch = 0; ch < TSI721_DMA_MAXCH; ch++) {
549 if (!(dev_ch_int & TSI721_INT_BDMA_CHAN(ch)))
550 continue;
551 tsi721_bdma_handler(&priv->bdma[ch]);
552 }
553 }
554 }
555#endif
544 return IRQ_HANDLED; 556 return IRQ_HANDLED;
545} 557}
546 558
@@ -553,18 +565,26 @@ static void tsi721_interrupts_init(struct tsi721_device *priv)
553 priv->regs + TSI721_SR_CHINT(IDB_QUEUE)); 565 priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
554 iowrite32(TSI721_SR_CHINT_IDBQRCV, 566 iowrite32(TSI721_SR_CHINT_IDBQRCV,
555 priv->regs + TSI721_SR_CHINTE(IDB_QUEUE)); 567 priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
556 iowrite32(TSI721_INT_SR2PC_CHAN(IDB_QUEUE),
557 priv->regs + TSI721_DEV_CHAN_INTE);
558 568
559 /* Enable SRIO MAC interrupts */ 569 /* Enable SRIO MAC interrupts */
560 iowrite32(TSI721_RIO_EM_DEV_INT_EN_INT, 570 iowrite32(TSI721_RIO_EM_DEV_INT_EN_INT,
561 priv->regs + TSI721_RIO_EM_DEV_INT_EN); 571 priv->regs + TSI721_RIO_EM_DEV_INT_EN);
562 572
573 /* Enable interrupts from channels in use */
574#ifdef CONFIG_RAPIDIO_DMA_ENGINE
575 intr = TSI721_INT_SR2PC_CHAN(IDB_QUEUE) |
576 (TSI721_INT_BDMA_CHAN_M &
577 ~TSI721_INT_BDMA_CHAN(TSI721_DMACH_MAINT));
578#else
579 intr = TSI721_INT_SR2PC_CHAN(IDB_QUEUE);
580#endif
581 iowrite32(intr, priv->regs + TSI721_DEV_CHAN_INTE);
582
563 if (priv->flags & TSI721_USING_MSIX) 583 if (priv->flags & TSI721_USING_MSIX)
564 intr = TSI721_DEV_INT_SRIO; 584 intr = TSI721_DEV_INT_SRIO;
565 else 585 else
566 intr = TSI721_DEV_INT_SR2PC_CH | TSI721_DEV_INT_SRIO | 586 intr = TSI721_DEV_INT_SR2PC_CH | TSI721_DEV_INT_SRIO |
567 TSI721_DEV_INT_SMSG_CH; 587 TSI721_DEV_INT_SMSG_CH | TSI721_DEV_INT_BDMA_CH;
568 588
569 iowrite32(intr, priv->regs + TSI721_DEV_INTE); 589 iowrite32(intr, priv->regs + TSI721_DEV_INTE);
570 ioread32(priv->regs + TSI721_DEV_INTE); 590 ioread32(priv->regs + TSI721_DEV_INTE);
@@ -715,12 +735,29 @@ static int tsi721_enable_msix(struct tsi721_device *priv)
715 TSI721_MSIX_OMSG_INT(i); 735 TSI721_MSIX_OMSG_INT(i);
716 } 736 }
717 737
738#ifdef CONFIG_RAPIDIO_DMA_ENGINE
739 /*
740 * Initialize MSI-X entries for Block DMA Engine:
741 * this driver supports XXX DMA channels
742 * (one is reserved for SRIO maintenance transactions)
743 */
744 for (i = 0; i < TSI721_DMA_CHNUM; i++) {
745 entries[TSI721_VECT_DMA0_DONE + i].entry =
746 TSI721_MSIX_DMACH_DONE(i);
747 entries[TSI721_VECT_DMA0_INT + i].entry =
748 TSI721_MSIX_DMACH_INT(i);
749 }
750#endif /* CONFIG_RAPIDIO_DMA_ENGINE */
751
718 err = pci_enable_msix(priv->pdev, entries, ARRAY_SIZE(entries)); 752 err = pci_enable_msix(priv->pdev, entries, ARRAY_SIZE(entries));
719 if (err) { 753 if (err) {
720 if (err > 0) 754 if (err > 0)
721 dev_info(&priv->pdev->dev, 755 dev_info(&priv->pdev->dev,
722 "Only %d MSI-X vectors available, " 756 "Only %d MSI-X vectors available, "
723 "not using MSI-X\n", err); 757 "not using MSI-X\n", err);
758 else
759 dev_err(&priv->pdev->dev,
760 "Failed to enable MSI-X (err=%d)\n", err);
724 return err; 761 return err;
725 } 762 }
726 763
@@ -760,6 +797,22 @@ static int tsi721_enable_msix(struct tsi721_device *priv)
760 i, pci_name(priv->pdev)); 797 i, pci_name(priv->pdev));
761 } 798 }
762 799
800#ifdef CONFIG_RAPIDIO_DMA_ENGINE
801 for (i = 0; i < TSI721_DMA_CHNUM; i++) {
802 priv->msix[TSI721_VECT_DMA0_DONE + i].vector =
803 entries[TSI721_VECT_DMA0_DONE + i].vector;
804 snprintf(priv->msix[TSI721_VECT_DMA0_DONE + i].irq_name,
805 IRQ_DEVICE_NAME_MAX, DRV_NAME "-dmad%d@pci:%s",
806 i, pci_name(priv->pdev));
807
808 priv->msix[TSI721_VECT_DMA0_INT + i].vector =
809 entries[TSI721_VECT_DMA0_INT + i].vector;
810 snprintf(priv->msix[TSI721_VECT_DMA0_INT + i].irq_name,
811 IRQ_DEVICE_NAME_MAX, DRV_NAME "-dmai%d@pci:%s",
812 i, pci_name(priv->pdev));
813 }
814#endif /* CONFIG_RAPIDIO_DMA_ENGINE */
815
763 return 0; 816 return 0;
764} 817}
765#endif /* CONFIG_PCI_MSI */ 818#endif /* CONFIG_PCI_MSI */
@@ -888,20 +941,34 @@ static void tsi721_doorbell_free(struct tsi721_device *priv)
888 priv->idb_base = NULL; 941 priv->idb_base = NULL;
889} 942}
890 943
891static int tsi721_bdma_ch_init(struct tsi721_device *priv, int chnum) 944/**
945 * tsi721_bdma_maint_init - Initialize maintenance request BDMA channel.
946 * @priv: pointer to tsi721 private data
947 *
948 * Initialize BDMA channel allocated for RapidIO maintenance read/write
949 * request generation
950 * Returns %0 on success or %-ENOMEM on failure.
951 */
952static int tsi721_bdma_maint_init(struct tsi721_device *priv)
892{ 953{
893 struct tsi721_dma_desc *bd_ptr; 954 struct tsi721_dma_desc *bd_ptr;
894 u64 *sts_ptr; 955 u64 *sts_ptr;
895 dma_addr_t bd_phys, sts_phys; 956 dma_addr_t bd_phys, sts_phys;
896 int sts_size; 957 int sts_size;
897 int bd_num = priv->bdma[chnum].bd_num; 958 int bd_num = 2;
959 void __iomem *regs;
898 960
899 dev_dbg(&priv->pdev->dev, "Init Block DMA Engine, CH%d\n", chnum); 961 dev_dbg(&priv->pdev->dev,
962 "Init Block DMA Engine for Maintenance requests, CH%d\n",
963 TSI721_DMACH_MAINT);
900 964
901 /* 965 /*
902 * Initialize DMA channel for maintenance requests 966 * Initialize DMA channel for maintenance requests
903 */ 967 */
904 968
969 priv->mdma.ch_id = TSI721_DMACH_MAINT;
970 regs = priv->regs + TSI721_DMAC_BASE(TSI721_DMACH_MAINT);
971
905 /* Allocate space for DMA descriptors */ 972 /* Allocate space for DMA descriptors */
906 bd_ptr = dma_zalloc_coherent(&priv->pdev->dev, 973 bd_ptr = dma_zalloc_coherent(&priv->pdev->dev,
907 bd_num * sizeof(struct tsi721_dma_desc), 974 bd_num * sizeof(struct tsi721_dma_desc),
@@ -909,8 +976,9 @@ static int tsi721_bdma_ch_init(struct tsi721_device *priv, int chnum)
909 if (!bd_ptr) 976 if (!bd_ptr)
910 return -ENOMEM; 977 return -ENOMEM;
911 978
912 priv->bdma[chnum].bd_phys = bd_phys; 979 priv->mdma.bd_num = bd_num;
913 priv->bdma[chnum].bd_base = bd_ptr; 980 priv->mdma.bd_phys = bd_phys;
981 priv->mdma.bd_base = bd_ptr;
914 982
915 dev_dbg(&priv->pdev->dev, "DMA descriptors @ %p (phys = %llx)\n", 983 dev_dbg(&priv->pdev->dev, "DMA descriptors @ %p (phys = %llx)\n",
916 bd_ptr, (unsigned long long)bd_phys); 984 bd_ptr, (unsigned long long)bd_phys);
@@ -927,13 +995,13 @@ static int tsi721_bdma_ch_init(struct tsi721_device *priv, int chnum)
927 dma_free_coherent(&priv->pdev->dev, 995 dma_free_coherent(&priv->pdev->dev,
928 bd_num * sizeof(struct tsi721_dma_desc), 996 bd_num * sizeof(struct tsi721_dma_desc),
929 bd_ptr, bd_phys); 997 bd_ptr, bd_phys);
930 priv->bdma[chnum].bd_base = NULL; 998 priv->mdma.bd_base = NULL;
931 return -ENOMEM; 999 return -ENOMEM;
932 } 1000 }
933 1001
934 priv->bdma[chnum].sts_phys = sts_phys; 1002 priv->mdma.sts_phys = sts_phys;
935 priv->bdma[chnum].sts_base = sts_ptr; 1003 priv->mdma.sts_base = sts_ptr;
936 priv->bdma[chnum].sts_size = sts_size; 1004 priv->mdma.sts_size = sts_size;
937 1005
938 dev_dbg(&priv->pdev->dev, 1006 dev_dbg(&priv->pdev->dev,
939 "desc status FIFO @ %p (phys = %llx) size=0x%x\n", 1007 "desc status FIFO @ %p (phys = %llx) size=0x%x\n",
@@ -946,83 +1014,61 @@ static int tsi721_bdma_ch_init(struct tsi721_device *priv, int chnum)
946 bd_ptr[bd_num - 1].next_hi = cpu_to_le32((u64)bd_phys >> 32); 1014 bd_ptr[bd_num - 1].next_hi = cpu_to_le32((u64)bd_phys >> 32);
947 1015
948 /* Setup DMA descriptor pointers */ 1016 /* Setup DMA descriptor pointers */
949 iowrite32(((u64)bd_phys >> 32), 1017 iowrite32(((u64)bd_phys >> 32), regs + TSI721_DMAC_DPTRH);
950 priv->regs + TSI721_DMAC_DPTRH(chnum));
951 iowrite32(((u64)bd_phys & TSI721_DMAC_DPTRL_MASK), 1018 iowrite32(((u64)bd_phys & TSI721_DMAC_DPTRL_MASK),
952 priv->regs + TSI721_DMAC_DPTRL(chnum)); 1019 regs + TSI721_DMAC_DPTRL);
953 1020
954 /* Setup descriptor status FIFO */ 1021 /* Setup descriptor status FIFO */
955 iowrite32(((u64)sts_phys >> 32), 1022 iowrite32(((u64)sts_phys >> 32), regs + TSI721_DMAC_DSBH);
956 priv->regs + TSI721_DMAC_DSBH(chnum));
957 iowrite32(((u64)sts_phys & TSI721_DMAC_DSBL_MASK), 1023 iowrite32(((u64)sts_phys & TSI721_DMAC_DSBL_MASK),
958 priv->regs + TSI721_DMAC_DSBL(chnum)); 1024 regs + TSI721_DMAC_DSBL);
959 iowrite32(TSI721_DMAC_DSSZ_SIZE(sts_size), 1025 iowrite32(TSI721_DMAC_DSSZ_SIZE(sts_size),
960 priv->regs + TSI721_DMAC_DSSZ(chnum)); 1026 regs + TSI721_DMAC_DSSZ);
961 1027
962 /* Clear interrupt bits */ 1028 /* Clear interrupt bits */
963 iowrite32(TSI721_DMAC_INT_ALL, 1029 iowrite32(TSI721_DMAC_INT_ALL, regs + TSI721_DMAC_INT);
964 priv->regs + TSI721_DMAC_INT(chnum));
965 1030
966 ioread32(priv->regs + TSI721_DMAC_INT(chnum)); 1031 ioread32(regs + TSI721_DMAC_INT);
967 1032
968 /* Toggle DMA channel initialization */ 1033 /* Toggle DMA channel initialization */
969 iowrite32(TSI721_DMAC_CTL_INIT, priv->regs + TSI721_DMAC_CTL(chnum)); 1034 iowrite32(TSI721_DMAC_CTL_INIT, regs + TSI721_DMAC_CTL);
970 ioread32(priv->regs + TSI721_DMAC_CTL(chnum)); 1035 ioread32(regs + TSI721_DMAC_CTL);
971 udelay(10); 1036 udelay(10);
972 1037
973 return 0; 1038 return 0;
974} 1039}
975 1040
976static int tsi721_bdma_ch_free(struct tsi721_device *priv, int chnum) 1041static int tsi721_bdma_maint_free(struct tsi721_device *priv)
977{ 1042{
978 u32 ch_stat; 1043 u32 ch_stat;
1044 struct tsi721_bdma_maint *mdma = &priv->mdma;
1045 void __iomem *regs = priv->regs + TSI721_DMAC_BASE(mdma->ch_id);
979 1046
980 if (priv->bdma[chnum].bd_base == NULL) 1047 if (mdma->bd_base == NULL)
981 return 0; 1048 return 0;
982 1049
983 /* Check if DMA channel still running */ 1050 /* Check if DMA channel still running */
984 ch_stat = ioread32(priv->regs + TSI721_DMAC_STS(chnum)); 1051 ch_stat = ioread32(regs + TSI721_DMAC_STS);
985 if (ch_stat & TSI721_DMAC_STS_RUN) 1052 if (ch_stat & TSI721_DMAC_STS_RUN)
986 return -EFAULT; 1053 return -EFAULT;
987 1054
988 /* Put DMA channel into init state */ 1055 /* Put DMA channel into init state */
989 iowrite32(TSI721_DMAC_CTL_INIT, 1056 iowrite32(TSI721_DMAC_CTL_INIT, regs + TSI721_DMAC_CTL);
990 priv->regs + TSI721_DMAC_CTL(chnum));
991 1057
992 /* Free space allocated for DMA descriptors */ 1058 /* Free space allocated for DMA descriptors */
993 dma_free_coherent(&priv->pdev->dev, 1059 dma_free_coherent(&priv->pdev->dev,
994 priv->bdma[chnum].bd_num * sizeof(struct tsi721_dma_desc), 1060 mdma->bd_num * sizeof(struct tsi721_dma_desc),
995 priv->bdma[chnum].bd_base, priv->bdma[chnum].bd_phys); 1061 mdma->bd_base, mdma->bd_phys);
996 priv->bdma[chnum].bd_base = NULL; 1062 mdma->bd_base = NULL;
997 1063
998 /* Free space allocated for status FIFO */ 1064 /* Free space allocated for status FIFO */
999 dma_free_coherent(&priv->pdev->dev, 1065 dma_free_coherent(&priv->pdev->dev,
1000 priv->bdma[chnum].sts_size * sizeof(struct tsi721_dma_sts), 1066 mdma->sts_size * sizeof(struct tsi721_dma_sts),
1001 priv->bdma[chnum].sts_base, priv->bdma[chnum].sts_phys); 1067 mdma->sts_base, mdma->sts_phys);
1002 priv->bdma[chnum].sts_base = NULL; 1068 mdma->sts_base = NULL;
1003 return 0;
1004}
1005
1006static int tsi721_bdma_init(struct tsi721_device *priv)
1007{
1008 /* Initialize BDMA channel allocated for RapidIO maintenance read/write
1009 * request generation
1010 */
1011 priv->bdma[TSI721_DMACH_MAINT].bd_num = 2;
1012 if (tsi721_bdma_ch_init(priv, TSI721_DMACH_MAINT)) {
1013 dev_err(&priv->pdev->dev, "Unable to initialize maintenance DMA"
1014 " channel %d, aborting\n", TSI721_DMACH_MAINT);
1015 return -ENOMEM;
1016 }
1017
1018 return 0; 1069 return 0;
1019} 1070}
1020 1071
1021static void tsi721_bdma_free(struct tsi721_device *priv)
1022{
1023 tsi721_bdma_ch_free(priv, TSI721_DMACH_MAINT);
1024}
1025
1026/* Enable Inbound Messaging Interrupts */ 1072/* Enable Inbound Messaging Interrupts */
1027static void 1073static void
1028tsi721_imsg_interrupt_enable(struct tsi721_device *priv, int ch, 1074tsi721_imsg_interrupt_enable(struct tsi721_device *priv, int ch,
@@ -2035,7 +2081,8 @@ static void tsi721_disable_ints(struct tsi721_device *priv)
2035 2081
2036 /* Disable all BDMA Channel interrupts */ 2082 /* Disable all BDMA Channel interrupts */
2037 for (ch = 0; ch < TSI721_DMA_MAXCH; ch++) 2083 for (ch = 0; ch < TSI721_DMA_MAXCH; ch++)
2038 iowrite32(0, priv->regs + TSI721_DMAC_INTE(ch)); 2084 iowrite32(0,
2085 priv->regs + TSI721_DMAC_BASE(ch) + TSI721_DMAC_INTE);
2039 2086
2040 /* Disable all general BDMA interrupts */ 2087 /* Disable all general BDMA interrupts */
2041 iowrite32(0, priv->regs + TSI721_BDMA_INTE); 2088 iowrite32(0, priv->regs + TSI721_BDMA_INTE);
@@ -2104,6 +2151,7 @@ static int __devinit tsi721_setup_mport(struct tsi721_device *priv)
2104 mport->phy_type = RIO_PHY_SERIAL; 2151 mport->phy_type = RIO_PHY_SERIAL;
2105 mport->priv = (void *)priv; 2152 mport->priv = (void *)priv;
2106 mport->phys_efptr = 0x100; 2153 mport->phys_efptr = 0x100;
2154 priv->mport = mport;
2107 2155
2108 INIT_LIST_HEAD(&mport->dbells); 2156 INIT_LIST_HEAD(&mport->dbells);
2109 2157
@@ -2129,17 +2177,21 @@ static int __devinit tsi721_setup_mport(struct tsi721_device *priv)
2129 if (!err) { 2177 if (!err) {
2130 tsi721_interrupts_init(priv); 2178 tsi721_interrupts_init(priv);
2131 ops->pwenable = tsi721_pw_enable; 2179 ops->pwenable = tsi721_pw_enable;
2132 } else 2180 } else {
2133 dev_err(&pdev->dev, "Unable to get assigned PCI IRQ " 2181 dev_err(&pdev->dev, "Unable to get assigned PCI IRQ "
2134 "vector %02X err=0x%x\n", pdev->irq, err); 2182 "vector %02X err=0x%x\n", pdev->irq, err);
2183 goto err_exit;
2184 }
2135 2185
2186#ifdef CONFIG_RAPIDIO_DMA_ENGINE
2187 tsi721_register_dma(priv);
2188#endif
2136 /* Enable SRIO link */ 2189 /* Enable SRIO link */
2137 iowrite32(ioread32(priv->regs + TSI721_DEVCTL) | 2190 iowrite32(ioread32(priv->regs + TSI721_DEVCTL) |
2138 TSI721_DEVCTL_SRBOOT_CMPL, 2191 TSI721_DEVCTL_SRBOOT_CMPL,
2139 priv->regs + TSI721_DEVCTL); 2192 priv->regs + TSI721_DEVCTL);
2140 2193
2141 rio_register_mport(mport); 2194 rio_register_mport(mport);
2142 priv->mport = mport;
2143 2195
2144 if (mport->host_deviceid >= 0) 2196 if (mport->host_deviceid >= 0)
2145 iowrite32(RIO_PORT_GEN_HOST | RIO_PORT_GEN_MASTER | 2197 iowrite32(RIO_PORT_GEN_HOST | RIO_PORT_GEN_MASTER |
@@ -2149,6 +2201,11 @@ static int __devinit tsi721_setup_mport(struct tsi721_device *priv)
2149 iowrite32(0, priv->regs + (0x100 + RIO_PORT_GEN_CTL_CSR)); 2201 iowrite32(0, priv->regs + (0x100 + RIO_PORT_GEN_CTL_CSR));
2150 2202
2151 return 0; 2203 return 0;
2204
2205err_exit:
2206 kfree(mport);
2207 kfree(ops);
2208 return err;
2152} 2209}
2153 2210
2154static int __devinit tsi721_probe(struct pci_dev *pdev, 2211static int __devinit tsi721_probe(struct pci_dev *pdev,
@@ -2294,7 +2351,7 @@ static int __devinit tsi721_probe(struct pci_dev *pdev,
2294 tsi721_init_pc2sr_mapping(priv); 2351 tsi721_init_pc2sr_mapping(priv);
2295 tsi721_init_sr2pc_mapping(priv); 2352 tsi721_init_sr2pc_mapping(priv);
2296 2353
2297 if (tsi721_bdma_init(priv)) { 2354 if (tsi721_bdma_maint_init(priv)) {
2298 dev_err(&pdev->dev, "BDMA initialization failed, aborting\n"); 2355 dev_err(&pdev->dev, "BDMA initialization failed, aborting\n");
2299 err = -ENOMEM; 2356 err = -ENOMEM;
2300 goto err_unmap_bars; 2357 goto err_unmap_bars;
@@ -2319,7 +2376,7 @@ static int __devinit tsi721_probe(struct pci_dev *pdev,
2319err_free_consistent: 2376err_free_consistent:
2320 tsi721_doorbell_free(priv); 2377 tsi721_doorbell_free(priv);
2321err_free_bdma: 2378err_free_bdma:
2322 tsi721_bdma_free(priv); 2379 tsi721_bdma_maint_free(priv);
2323err_unmap_bars: 2380err_unmap_bars:
2324 if (priv->regs) 2381 if (priv->regs)
2325 iounmap(priv->regs); 2382 iounmap(priv->regs);
diff --git a/drivers/rapidio/devices/tsi721.h b/drivers/rapidio/devices/tsi721.h
index 1c226b31af13..59de9d7be346 100644
--- a/drivers/rapidio/devices/tsi721.h
+++ b/drivers/rapidio/devices/tsi721.h
@@ -167,6 +167,8 @@
167#define TSI721_DEV_INTE 0x29840 167#define TSI721_DEV_INTE 0x29840
168#define TSI721_DEV_INT 0x29844 168#define TSI721_DEV_INT 0x29844
169#define TSI721_DEV_INTSET 0x29848 169#define TSI721_DEV_INTSET 0x29848
170#define TSI721_DEV_INT_BDMA_CH 0x00002000
171#define TSI721_DEV_INT_BDMA_NCH 0x00001000
170#define TSI721_DEV_INT_SMSG_CH 0x00000800 172#define TSI721_DEV_INT_SMSG_CH 0x00000800
171#define TSI721_DEV_INT_SMSG_NCH 0x00000400 173#define TSI721_DEV_INT_SMSG_NCH 0x00000400
172#define TSI721_DEV_INT_SR2PC_CH 0x00000200 174#define TSI721_DEV_INT_SR2PC_CH 0x00000200
@@ -181,6 +183,8 @@
181#define TSI721_INT_IMSG_CHAN(x) (1 << (16 + (x))) 183#define TSI721_INT_IMSG_CHAN(x) (1 << (16 + (x)))
182#define TSI721_INT_OMSG_CHAN_M 0x0000ff00 184#define TSI721_INT_OMSG_CHAN_M 0x0000ff00
183#define TSI721_INT_OMSG_CHAN(x) (1 << (8 + (x))) 185#define TSI721_INT_OMSG_CHAN(x) (1 << (8 + (x)))
186#define TSI721_INT_BDMA_CHAN_M 0x000000ff
187#define TSI721_INT_BDMA_CHAN(x) (1 << (x))
184 188
185/* 189/*
186 * PC2SR block registers 190 * PC2SR block registers
@@ -235,14 +239,16 @@
235 * x = 0..7 239 * x = 0..7
236 */ 240 */
237 241
238#define TSI721_DMAC_DWRCNT(x) (0x51000 + (x) * 0x1000) 242#define TSI721_DMAC_BASE(x) (0x51000 + (x) * 0x1000)
239#define TSI721_DMAC_DRDCNT(x) (0x51004 + (x) * 0x1000)
240 243
241#define TSI721_DMAC_CTL(x) (0x51008 + (x) * 0x1000) 244#define TSI721_DMAC_DWRCNT 0x000
245#define TSI721_DMAC_DRDCNT 0x004
246
247#define TSI721_DMAC_CTL 0x008
242#define TSI721_DMAC_CTL_SUSP 0x00000002 248#define TSI721_DMAC_CTL_SUSP 0x00000002
243#define TSI721_DMAC_CTL_INIT 0x00000001 249#define TSI721_DMAC_CTL_INIT 0x00000001
244 250
245#define TSI721_DMAC_INT(x) (0x5100c + (x) * 0x1000) 251#define TSI721_DMAC_INT 0x00c
246#define TSI721_DMAC_INT_STFULL 0x00000010 252#define TSI721_DMAC_INT_STFULL 0x00000010
247#define TSI721_DMAC_INT_DONE 0x00000008 253#define TSI721_DMAC_INT_DONE 0x00000008
248#define TSI721_DMAC_INT_SUSP 0x00000004 254#define TSI721_DMAC_INT_SUSP 0x00000004
@@ -250,34 +256,33 @@
250#define TSI721_DMAC_INT_IOFDONE 0x00000001 256#define TSI721_DMAC_INT_IOFDONE 0x00000001
251#define TSI721_DMAC_INT_ALL 0x0000001f 257#define TSI721_DMAC_INT_ALL 0x0000001f
252 258
253#define TSI721_DMAC_INTSET(x) (0x51010 + (x) * 0x1000) 259#define TSI721_DMAC_INTSET 0x010
254 260
255#define TSI721_DMAC_STS(x) (0x51014 + (x) * 0x1000) 261#define TSI721_DMAC_STS 0x014
256#define TSI721_DMAC_STS_ABORT 0x00400000 262#define TSI721_DMAC_STS_ABORT 0x00400000
257#define TSI721_DMAC_STS_RUN 0x00200000 263#define TSI721_DMAC_STS_RUN 0x00200000
258#define TSI721_DMAC_STS_CS 0x001f0000 264#define TSI721_DMAC_STS_CS 0x001f0000
259 265
260#define TSI721_DMAC_INTE(x) (0x51018 + (x) * 0x1000) 266#define TSI721_DMAC_INTE 0x018
261 267
262#define TSI721_DMAC_DPTRL(x) (0x51024 + (x) * 0x1000) 268#define TSI721_DMAC_DPTRL 0x024
263#define TSI721_DMAC_DPTRL_MASK 0xffffffe0 269#define TSI721_DMAC_DPTRL_MASK 0xffffffe0
264 270
265#define TSI721_DMAC_DPTRH(x) (0x51028 + (x) * 0x1000) 271#define TSI721_DMAC_DPTRH 0x028
266 272
267#define TSI721_DMAC_DSBL(x) (0x5102c + (x) * 0x1000) 273#define TSI721_DMAC_DSBL 0x02c
268#define TSI721_DMAC_DSBL_MASK 0xffffffc0 274#define TSI721_DMAC_DSBL_MASK 0xffffffc0
269 275
270#define TSI721_DMAC_DSBH(x) (0x51030 + (x) * 0x1000) 276#define TSI721_DMAC_DSBH 0x030
271 277
272#define TSI721_DMAC_DSSZ(x) (0x51034 + (x) * 0x1000) 278#define TSI721_DMAC_DSSZ 0x034
273#define TSI721_DMAC_DSSZ_SIZE_M 0x0000000f 279#define TSI721_DMAC_DSSZ_SIZE_M 0x0000000f
274#define TSI721_DMAC_DSSZ_SIZE(size) (__fls(size) - 4) 280#define TSI721_DMAC_DSSZ_SIZE(size) (__fls(size) - 4)
275 281
276 282#define TSI721_DMAC_DSRP 0x038
277#define TSI721_DMAC_DSRP(x) (0x51038 + (x) * 0x1000)
278#define TSI721_DMAC_DSRP_MASK 0x0007ffff 283#define TSI721_DMAC_DSRP_MASK 0x0007ffff
279 284
280#define TSI721_DMAC_DSWP(x) (0x5103c + (x) * 0x1000) 285#define TSI721_DMAC_DSWP 0x03c
281#define TSI721_DMAC_DSWP_MASK 0x0007ffff 286#define TSI721_DMAC_DSWP_MASK 0x0007ffff
282 287
283#define TSI721_BDMA_INTE 0x5f000 288#define TSI721_BDMA_INTE 0x5f000
@@ -612,6 +617,8 @@ enum dma_rtype {
612#define TSI721_DMACH_MAINT 0 /* DMA channel for maint requests */ 617#define TSI721_DMACH_MAINT 0 /* DMA channel for maint requests */
613#define TSI721_DMACH_MAINT_NBD 32 /* Number of BDs for maint requests */ 618#define TSI721_DMACH_MAINT_NBD 32 /* Number of BDs for maint requests */
614 619
620#define TSI721_DMACH_DMA 1 /* DMA channel for data transfers */
621
615#define MSG_DMA_ENTRY_INX_TO_SIZE(x) ((0x10 << (x)) & 0xFFFF0) 622#define MSG_DMA_ENTRY_INX_TO_SIZE(x) ((0x10 << (x)) & 0xFFFF0)
616 623
617enum tsi721_smsg_int_flag { 624enum tsi721_smsg_int_flag {
@@ -626,7 +633,48 @@ enum tsi721_smsg_int_flag {
626 633
627/* Structures */ 634/* Structures */
628 635
636#ifdef CONFIG_RAPIDIO_DMA_ENGINE
637
638struct tsi721_tx_desc {
639 struct dma_async_tx_descriptor txd;
640 struct tsi721_dma_desc *hw_desc;
641 u16 destid;
642 /* low 64-bits of 66-bit RIO address */
643 u64 rio_addr;
644 /* upper 2-bits of 66-bit RIO address */
645 u8 rio_addr_u;
646 bool interrupt;
647 struct list_head desc_node;
648 struct list_head tx_list;
649};
650
629struct tsi721_bdma_chan { 651struct tsi721_bdma_chan {
652 int id;
653 void __iomem *regs;
654 int bd_num; /* number of buffer descriptors */
655 void *bd_base; /* start of DMA descriptors */
656 dma_addr_t bd_phys;
657 void *sts_base; /* start of DMA BD status FIFO */
658 dma_addr_t sts_phys;
659 int sts_size;
660 u32 sts_rdptr;
661 u32 wr_count;
662 u32 wr_count_next;
663
664 struct dma_chan dchan;
665 struct tsi721_tx_desc *tx_desc;
666 spinlock_t lock;
667 struct list_head active_list;
668 struct list_head queue;
669 struct list_head free_list;
670 dma_cookie_t completed_cookie;
671 struct tasklet_struct tasklet;
672};
673
674#endif /* CONFIG_RAPIDIO_DMA_ENGINE */
675
676struct tsi721_bdma_maint {
677 int ch_id; /* BDMA channel number */
630 int bd_num; /* number of buffer descriptors */ 678 int bd_num; /* number of buffer descriptors */
631 void *bd_base; /* start of DMA descriptors */ 679 void *bd_base; /* start of DMA descriptors */
632 dma_addr_t bd_phys; 680 dma_addr_t bd_phys;
@@ -721,6 +769,24 @@ enum tsi721_msix_vect {
721 TSI721_VECT_IMB1_INT, 769 TSI721_VECT_IMB1_INT,
722 TSI721_VECT_IMB2_INT, 770 TSI721_VECT_IMB2_INT,
723 TSI721_VECT_IMB3_INT, 771 TSI721_VECT_IMB3_INT,
772#ifdef CONFIG_RAPIDIO_DMA_ENGINE
773 TSI721_VECT_DMA0_DONE,
774 TSI721_VECT_DMA1_DONE,
775 TSI721_VECT_DMA2_DONE,
776 TSI721_VECT_DMA3_DONE,
777 TSI721_VECT_DMA4_DONE,
778 TSI721_VECT_DMA5_DONE,
779 TSI721_VECT_DMA6_DONE,
780 TSI721_VECT_DMA7_DONE,
781 TSI721_VECT_DMA0_INT,
782 TSI721_VECT_DMA1_INT,
783 TSI721_VECT_DMA2_INT,
784 TSI721_VECT_DMA3_INT,
785 TSI721_VECT_DMA4_INT,
786 TSI721_VECT_DMA5_INT,
787 TSI721_VECT_DMA6_INT,
788 TSI721_VECT_DMA7_INT,
789#endif /* CONFIG_RAPIDIO_DMA_ENGINE */
724 TSI721_VECT_MAX 790 TSI721_VECT_MAX
725}; 791};
726 792
@@ -754,7 +820,11 @@ struct tsi721_device {
754 u32 pw_discard_count; 820 u32 pw_discard_count;
755 821
756 /* BDMA Engine */ 822 /* BDMA Engine */
823 struct tsi721_bdma_maint mdma; /* Maintenance rd/wr request channel */
824
825#ifdef CONFIG_RAPIDIO_DMA_ENGINE
757 struct tsi721_bdma_chan bdma[TSI721_DMA_CHNUM]; 826 struct tsi721_bdma_chan bdma[TSI721_DMA_CHNUM];
827#endif
758 828
759 /* Inbound Messaging */ 829 /* Inbound Messaging */
760 int imsg_init[TSI721_IMSG_CHNUM]; 830 int imsg_init[TSI721_IMSG_CHNUM];
@@ -765,4 +835,9 @@ struct tsi721_device {
765 struct tsi721_omsg_ring omsg_ring[TSI721_OMSG_CHNUM]; 835 struct tsi721_omsg_ring omsg_ring[TSI721_OMSG_CHNUM];
766}; 836};
767 837
838#ifdef CONFIG_RAPIDIO_DMA_ENGINE
839extern void tsi721_bdma_handler(struct tsi721_bdma_chan *bdma_chan);
840extern int __devinit tsi721_register_dma(struct tsi721_device *priv);
841#endif
842
768#endif 843#endif
diff --git a/drivers/rapidio/devices/tsi721_dma.c b/drivers/rapidio/devices/tsi721_dma.c
new file mode 100644
index 000000000000..92e06a5c62ec
--- /dev/null
+++ b/drivers/rapidio/devices/tsi721_dma.c
@@ -0,0 +1,823 @@
1/*
2 * DMA Engine support for Tsi721 PCIExpress-to-SRIO bridge
3 *
4 * Copyright 2011 Integrated Device Technology, Inc.
5 * Alexandre Bounine <alexandre.bounine@idt.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59
19 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include <linux/io.h>
23#include <linux/errno.h>
24#include <linux/init.h>
25#include <linux/ioport.h>
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/pci.h>
29#include <linux/rio.h>
30#include <linux/rio_drv.h>
31#include <linux/dma-mapping.h>
32#include <linux/interrupt.h>
33#include <linux/kfifo.h>
34#include <linux/delay.h>
35
36#include "tsi721.h"
37
38static inline struct tsi721_bdma_chan *to_tsi721_chan(struct dma_chan *chan)
39{
40 return container_of(chan, struct tsi721_bdma_chan, dchan);
41}
42
43static inline struct tsi721_device *to_tsi721(struct dma_device *ddev)
44{
45 return container_of(ddev, struct rio_mport, dma)->priv;
46}
47
48static inline
49struct tsi721_tx_desc *to_tsi721_desc(struct dma_async_tx_descriptor *txd)
50{
51 return container_of(txd, struct tsi721_tx_desc, txd);
52}
53
54static inline
55struct tsi721_tx_desc *tsi721_dma_first_active(
56 struct tsi721_bdma_chan *bdma_chan)
57{
58 return list_first_entry(&bdma_chan->active_list,
59 struct tsi721_tx_desc, desc_node);
60}
61
62static int tsi721_bdma_ch_init(struct tsi721_bdma_chan *bdma_chan)
63{
64 struct tsi721_dma_desc *bd_ptr;
65 struct device *dev = bdma_chan->dchan.device->dev;
66 u64 *sts_ptr;
67 dma_addr_t bd_phys;
68 dma_addr_t sts_phys;
69 int sts_size;
70 int bd_num = bdma_chan->bd_num;
71
72 dev_dbg(dev, "Init Block DMA Engine, CH%d\n", bdma_chan->id);
73
74 /* Allocate space for DMA descriptors */
75 bd_ptr = dma_zalloc_coherent(dev,
76 bd_num * sizeof(struct tsi721_dma_desc),
77 &bd_phys, GFP_KERNEL);
78 if (!bd_ptr)
79 return -ENOMEM;
80
81 bdma_chan->bd_phys = bd_phys;
82 bdma_chan->bd_base = bd_ptr;
83
84 dev_dbg(dev, "DMA descriptors @ %p (phys = %llx)\n",
85 bd_ptr, (unsigned long long)bd_phys);
86
87 /* Allocate space for descriptor status FIFO */
88 sts_size = (bd_num >= TSI721_DMA_MINSTSSZ) ?
89 bd_num : TSI721_DMA_MINSTSSZ;
90 sts_size = roundup_pow_of_two(sts_size);
91 sts_ptr = dma_zalloc_coherent(dev,
92 sts_size * sizeof(struct tsi721_dma_sts),
93 &sts_phys, GFP_KERNEL);
94 if (!sts_ptr) {
95 /* Free space allocated for DMA descriptors */
96 dma_free_coherent(dev,
97 bd_num * sizeof(struct tsi721_dma_desc),
98 bd_ptr, bd_phys);
99 bdma_chan->bd_base = NULL;
100 return -ENOMEM;
101 }
102
103 bdma_chan->sts_phys = sts_phys;
104 bdma_chan->sts_base = sts_ptr;
105 bdma_chan->sts_size = sts_size;
106
107 dev_dbg(dev,
108 "desc status FIFO @ %p (phys = %llx) size=0x%x\n",
109 sts_ptr, (unsigned long long)sts_phys, sts_size);
110
111 /* Initialize DMA descriptors ring */
112 bd_ptr[bd_num - 1].type_id = cpu_to_le32(DTYPE3 << 29);
113 bd_ptr[bd_num - 1].next_lo = cpu_to_le32((u64)bd_phys &
114 TSI721_DMAC_DPTRL_MASK);
115 bd_ptr[bd_num - 1].next_hi = cpu_to_le32((u64)bd_phys >> 32);
116
117 /* Setup DMA descriptor pointers */
118 iowrite32(((u64)bd_phys >> 32),
119 bdma_chan->regs + TSI721_DMAC_DPTRH);
120 iowrite32(((u64)bd_phys & TSI721_DMAC_DPTRL_MASK),
121 bdma_chan->regs + TSI721_DMAC_DPTRL);
122
123 /* Setup descriptor status FIFO */
124 iowrite32(((u64)sts_phys >> 32),
125 bdma_chan->regs + TSI721_DMAC_DSBH);
126 iowrite32(((u64)sts_phys & TSI721_DMAC_DSBL_MASK),
127 bdma_chan->regs + TSI721_DMAC_DSBL);
128 iowrite32(TSI721_DMAC_DSSZ_SIZE(sts_size),
129 bdma_chan->regs + TSI721_DMAC_DSSZ);
130
131 /* Clear interrupt bits */
132 iowrite32(TSI721_DMAC_INT_ALL,
133 bdma_chan->regs + TSI721_DMAC_INT);
134
135 ioread32(bdma_chan->regs + TSI721_DMAC_INT);
136
137 /* Toggle DMA channel initialization */
138 iowrite32(TSI721_DMAC_CTL_INIT, bdma_chan->regs + TSI721_DMAC_CTL);
139 ioread32(bdma_chan->regs + TSI721_DMAC_CTL);
140 bdma_chan->wr_count = bdma_chan->wr_count_next = 0;
141 bdma_chan->sts_rdptr = 0;
142 udelay(10);
143
144 return 0;
145}
146
147static int tsi721_bdma_ch_free(struct tsi721_bdma_chan *bdma_chan)
148{
149 u32 ch_stat;
150
151 if (bdma_chan->bd_base == NULL)
152 return 0;
153
154 /* Check if DMA channel still running */
155 ch_stat = ioread32(bdma_chan->regs + TSI721_DMAC_STS);
156 if (ch_stat & TSI721_DMAC_STS_RUN)
157 return -EFAULT;
158
159 /* Put DMA channel into init state */
160 iowrite32(TSI721_DMAC_CTL_INIT, bdma_chan->regs + TSI721_DMAC_CTL);
161
162 /* Free space allocated for DMA descriptors */
163 dma_free_coherent(bdma_chan->dchan.device->dev,
164 bdma_chan->bd_num * sizeof(struct tsi721_dma_desc),
165 bdma_chan->bd_base, bdma_chan->bd_phys);
166 bdma_chan->bd_base = NULL;
167
168 /* Free space allocated for status FIFO */
169 dma_free_coherent(bdma_chan->dchan.device->dev,
170 bdma_chan->sts_size * sizeof(struct tsi721_dma_sts),
171 bdma_chan->sts_base, bdma_chan->sts_phys);
172 bdma_chan->sts_base = NULL;
173 return 0;
174}
175
176static void
177tsi721_bdma_interrupt_enable(struct tsi721_bdma_chan *bdma_chan, int enable)
178{
179 if (enable) {
180 /* Clear pending BDMA channel interrupts */
181 iowrite32(TSI721_DMAC_INT_ALL,
182 bdma_chan->regs + TSI721_DMAC_INT);
183 ioread32(bdma_chan->regs + TSI721_DMAC_INT);
184 /* Enable BDMA channel interrupts */
185 iowrite32(TSI721_DMAC_INT_ALL,
186 bdma_chan->regs + TSI721_DMAC_INTE);
187 } else {
188 /* Disable BDMA channel interrupts */
189 iowrite32(0, bdma_chan->regs + TSI721_DMAC_INTE);
190 /* Clear pending BDMA channel interrupts */
191 iowrite32(TSI721_DMAC_INT_ALL,
192 bdma_chan->regs + TSI721_DMAC_INT);
193 }
194
195}
196
197static bool tsi721_dma_is_idle(struct tsi721_bdma_chan *bdma_chan)
198{
199 u32 sts;
200
201 sts = ioread32(bdma_chan->regs + TSI721_DMAC_STS);
202 return ((sts & TSI721_DMAC_STS_RUN) == 0);
203}
204
205void tsi721_bdma_handler(struct tsi721_bdma_chan *bdma_chan)
206{
207 /* Disable BDMA channel interrupts */
208 iowrite32(0, bdma_chan->regs + TSI721_DMAC_INTE);
209
210 tasklet_schedule(&bdma_chan->tasklet);
211}
212
213#ifdef CONFIG_PCI_MSI
214/**
215 * tsi721_omsg_msix - MSI-X interrupt handler for BDMA channels
216 * @irq: Linux interrupt number
217 * @ptr: Pointer to interrupt-specific data (BDMA channel structure)
218 *
219 * Handles BDMA channel interrupts signaled using MSI-X.
220 */
221static irqreturn_t tsi721_bdma_msix(int irq, void *ptr)
222{
223 struct tsi721_bdma_chan *bdma_chan = ptr;
224
225 tsi721_bdma_handler(bdma_chan);
226 return IRQ_HANDLED;
227}
228#endif /* CONFIG_PCI_MSI */
229
230/* Must be called with the spinlock held */
231static void tsi721_start_dma(struct tsi721_bdma_chan *bdma_chan)
232{
233 if (!tsi721_dma_is_idle(bdma_chan)) {
234 dev_err(bdma_chan->dchan.device->dev,
235 "BUG: Attempt to start non-idle channel\n");
236 return;
237 }
238
239 if (bdma_chan->wr_count == bdma_chan->wr_count_next) {
240 dev_err(bdma_chan->dchan.device->dev,
241 "BUG: Attempt to start DMA with no BDs ready\n");
242 return;
243 }
244
245 dev_dbg(bdma_chan->dchan.device->dev,
246 "tx_chan: %p, chan: %d, regs: %p\n",
247 bdma_chan, bdma_chan->dchan.chan_id, bdma_chan->regs);
248
249 iowrite32(bdma_chan->wr_count_next,
250 bdma_chan->regs + TSI721_DMAC_DWRCNT);
251 ioread32(bdma_chan->regs + TSI721_DMAC_DWRCNT);
252
253 bdma_chan->wr_count = bdma_chan->wr_count_next;
254}
255
256static void tsi721_desc_put(struct tsi721_bdma_chan *bdma_chan,
257 struct tsi721_tx_desc *desc)
258{
259 dev_dbg(bdma_chan->dchan.device->dev,
260 "Put desc: %p into free list\n", desc);
261
262 if (desc) {
263 spin_lock_bh(&bdma_chan->lock);
264 list_splice_init(&desc->tx_list, &bdma_chan->free_list);
265 list_add(&desc->desc_node, &bdma_chan->free_list);
266 bdma_chan->wr_count_next = bdma_chan->wr_count;
267 spin_unlock_bh(&bdma_chan->lock);
268 }
269}
270
271static
272struct tsi721_tx_desc *tsi721_desc_get(struct tsi721_bdma_chan *bdma_chan)
273{
274 struct tsi721_tx_desc *tx_desc, *_tx_desc;
275 struct tsi721_tx_desc *ret = NULL;
276 int i;
277
278 spin_lock_bh(&bdma_chan->lock);
279 list_for_each_entry_safe(tx_desc, _tx_desc,
280 &bdma_chan->free_list, desc_node) {
281 if (async_tx_test_ack(&tx_desc->txd)) {
282 list_del(&tx_desc->desc_node);
283 ret = tx_desc;
284 break;
285 }
286 dev_dbg(bdma_chan->dchan.device->dev,
287 "desc %p not ACKed\n", tx_desc);
288 }
289
290 i = bdma_chan->wr_count_next % bdma_chan->bd_num;
291 if (i == bdma_chan->bd_num - 1) {
292 i = 0;
293 bdma_chan->wr_count_next++; /* skip link descriptor */
294 }
295
296 bdma_chan->wr_count_next++;
297 tx_desc->txd.phys = bdma_chan->bd_phys +
298 i * sizeof(struct tsi721_dma_desc);
299 tx_desc->hw_desc = &((struct tsi721_dma_desc *)bdma_chan->bd_base)[i];
300
301 spin_unlock_bh(&bdma_chan->lock);
302
303 return ret;
304}
305
306static int
307tsi721_fill_desc(struct tsi721_bdma_chan *bdma_chan,
308 struct tsi721_tx_desc *desc, struct scatterlist *sg,
309 enum dma_rtype rtype, u32 sys_size)
310{
311 struct tsi721_dma_desc *bd_ptr = desc->hw_desc;
312 u64 rio_addr;
313
314 if (sg_dma_len(sg) > TSI721_DMAD_BCOUNT1 + 1) {
315 dev_err(bdma_chan->dchan.device->dev,
316 "SG element is too large\n");
317 return -EINVAL;
318 }
319
320 dev_dbg(bdma_chan->dchan.device->dev,
321 "desc: 0x%llx, addr: 0x%llx len: 0x%x\n",
322 (u64)desc->txd.phys, (unsigned long long)sg_dma_address(sg),
323 sg_dma_len(sg));
324
325 dev_dbg(bdma_chan->dchan.device->dev,
326 "bd_ptr = %p did=%d raddr=0x%llx\n",
327 bd_ptr, desc->destid, desc->rio_addr);
328
329 /* Initialize DMA descriptor */
330 bd_ptr->type_id = cpu_to_le32((DTYPE1 << 29) |
331 (rtype << 19) | desc->destid);
332 if (desc->interrupt)
333 bd_ptr->type_id |= cpu_to_le32(TSI721_DMAD_IOF);
334 bd_ptr->bcount = cpu_to_le32(((desc->rio_addr & 0x3) << 30) |
335 (sys_size << 26) | sg_dma_len(sg));
336 rio_addr = (desc->rio_addr >> 2) |
337 ((u64)(desc->rio_addr_u & 0x3) << 62);
338 bd_ptr->raddr_lo = cpu_to_le32(rio_addr & 0xffffffff);
339 bd_ptr->raddr_hi = cpu_to_le32(rio_addr >> 32);
340 bd_ptr->t1.bufptr_lo = cpu_to_le32(
341 (u64)sg_dma_address(sg) & 0xffffffff);
342 bd_ptr->t1.bufptr_hi = cpu_to_le32((u64)sg_dma_address(sg) >> 32);
343 bd_ptr->t1.s_dist = 0;
344 bd_ptr->t1.s_size = 0;
345
346 return 0;
347}
348
349static void tsi721_dma_chain_complete(struct tsi721_bdma_chan *bdma_chan,
350 struct tsi721_tx_desc *desc)
351{
352 struct dma_async_tx_descriptor *txd = &desc->txd;
353 dma_async_tx_callback callback = txd->callback;
354 void *param = txd->callback_param;
355
356 list_splice_init(&desc->tx_list, &bdma_chan->free_list);
357 list_move(&desc->desc_node, &bdma_chan->free_list);
358 bdma_chan->completed_cookie = txd->cookie;
359
360 if (callback)
361 callback(param);
362}
363
364static void tsi721_dma_complete_all(struct tsi721_bdma_chan *bdma_chan)
365{
366 struct tsi721_tx_desc *desc, *_d;
367 LIST_HEAD(list);
368
369 BUG_ON(!tsi721_dma_is_idle(bdma_chan));
370
371 if (!list_empty(&bdma_chan->queue))
372 tsi721_start_dma(bdma_chan);
373
374 list_splice_init(&bdma_chan->active_list, &list);
375 list_splice_init(&bdma_chan->queue, &bdma_chan->active_list);
376
377 list_for_each_entry_safe(desc, _d, &list, desc_node)
378 tsi721_dma_chain_complete(bdma_chan, desc);
379}
380
381static void tsi721_clr_stat(struct tsi721_bdma_chan *bdma_chan)
382{
383 u32 srd_ptr;
384 u64 *sts_ptr;
385 int i, j;
386
387 /* Check and clear descriptor status FIFO entries */
388 srd_ptr = bdma_chan->sts_rdptr;
389 sts_ptr = bdma_chan->sts_base;
390 j = srd_ptr * 8;
391 while (sts_ptr[j]) {
392 for (i = 0; i < 8 && sts_ptr[j]; i++, j++)
393 sts_ptr[j] = 0;
394
395 ++srd_ptr;
396 srd_ptr %= bdma_chan->sts_size;
397 j = srd_ptr * 8;
398 }
399
400 iowrite32(srd_ptr, bdma_chan->regs + TSI721_DMAC_DSRP);
401 bdma_chan->sts_rdptr = srd_ptr;
402}
403
404static void tsi721_advance_work(struct tsi721_bdma_chan *bdma_chan)
405{
406 if (list_empty(&bdma_chan->active_list) ||
407 list_is_singular(&bdma_chan->active_list)) {
408 dev_dbg(bdma_chan->dchan.device->dev,
409 "%s: Active_list empty\n", __func__);
410 tsi721_dma_complete_all(bdma_chan);
411 } else {
412 dev_dbg(bdma_chan->dchan.device->dev,
413 "%s: Active_list NOT empty\n", __func__);
414 tsi721_dma_chain_complete(bdma_chan,
415 tsi721_dma_first_active(bdma_chan));
416 tsi721_start_dma(bdma_chan);
417 }
418}
419
420static void tsi721_dma_tasklet(unsigned long data)
421{
422 struct tsi721_bdma_chan *bdma_chan = (struct tsi721_bdma_chan *)data;
423 u32 dmac_int, dmac_sts;
424
425 dmac_int = ioread32(bdma_chan->regs + TSI721_DMAC_INT);
426 dev_dbg(bdma_chan->dchan.device->dev, "%s: DMAC%d_INT = 0x%x\n",
427 __func__, bdma_chan->id, dmac_int);
428 /* Clear channel interrupts */
429 iowrite32(dmac_int, bdma_chan->regs + TSI721_DMAC_INT);
430
431 if (dmac_int & TSI721_DMAC_INT_ERR) {
432 dmac_sts = ioread32(bdma_chan->regs + TSI721_DMAC_STS);
433 dev_err(bdma_chan->dchan.device->dev,
434 "%s: DMA ERROR - DMAC%d_STS = 0x%x\n",
435 __func__, bdma_chan->id, dmac_sts);
436 }
437
438 if (dmac_int & TSI721_DMAC_INT_STFULL) {
439 dev_err(bdma_chan->dchan.device->dev,
440 "%s: DMAC%d descriptor status FIFO is full\n",
441 __func__, bdma_chan->id);
442 }
443
444 if (dmac_int & (TSI721_DMAC_INT_DONE | TSI721_DMAC_INT_IOFDONE)) {
445 tsi721_clr_stat(bdma_chan);
446 spin_lock(&bdma_chan->lock);
447 tsi721_advance_work(bdma_chan);
448 spin_unlock(&bdma_chan->lock);
449 }
450
451 /* Re-Enable BDMA channel interrupts */
452 iowrite32(TSI721_DMAC_INT_ALL, bdma_chan->regs + TSI721_DMAC_INTE);
453}
454
455static dma_cookie_t tsi721_tx_submit(struct dma_async_tx_descriptor *txd)
456{
457 struct tsi721_tx_desc *desc = to_tsi721_desc(txd);
458 struct tsi721_bdma_chan *bdma_chan = to_tsi721_chan(txd->chan);
459 dma_cookie_t cookie;
460
461 spin_lock_bh(&bdma_chan->lock);
462
463 cookie = txd->chan->cookie;
464 if (++cookie < 0)
465 cookie = 1;
466 txd->chan->cookie = cookie;
467 txd->cookie = cookie;
468
469 if (list_empty(&bdma_chan->active_list)) {
470 list_add_tail(&desc->desc_node, &bdma_chan->active_list);
471 tsi721_start_dma(bdma_chan);
472 } else {
473 list_add_tail(&desc->desc_node, &bdma_chan->queue);
474 }
475
476 spin_unlock_bh(&bdma_chan->lock);
477 return cookie;
478}
479
480static int tsi721_alloc_chan_resources(struct dma_chan *dchan)
481{
482 struct tsi721_bdma_chan *bdma_chan = to_tsi721_chan(dchan);
483#ifdef CONFIG_PCI_MSI
484 struct tsi721_device *priv = to_tsi721(dchan->device);
485#endif
486 struct tsi721_tx_desc *desc = NULL;
487 LIST_HEAD(tmp_list);
488 int i;
489 int rc;
490
491 if (bdma_chan->bd_base)
492 return bdma_chan->bd_num - 1;
493
494 /* Initialize BDMA channel */
495 if (tsi721_bdma_ch_init(bdma_chan)) {
496 dev_err(dchan->device->dev, "Unable to initialize data DMA"
497 " channel %d, aborting\n", bdma_chan->id);
498 return -ENOMEM;
499 }
500
501 /* Alocate matching number of logical descriptors */
502 desc = kcalloc((bdma_chan->bd_num - 1), sizeof(struct tsi721_tx_desc),
503 GFP_KERNEL);
504 if (!desc) {
505 dev_err(dchan->device->dev,
506 "Failed to allocate logical descriptors\n");
507 rc = -ENOMEM;
508 goto err_out;
509 }
510
511 bdma_chan->tx_desc = desc;
512
513 for (i = 0; i < bdma_chan->bd_num - 1; i++) {
514 dma_async_tx_descriptor_init(&desc[i].txd, dchan);
515 desc[i].txd.tx_submit = tsi721_tx_submit;
516 desc[i].txd.flags = DMA_CTRL_ACK;
517 INIT_LIST_HEAD(&desc[i].tx_list);
518 list_add_tail(&desc[i].desc_node, &tmp_list);
519 }
520
521 spin_lock_bh(&bdma_chan->lock);
522 list_splice(&tmp_list, &bdma_chan->free_list);
523 bdma_chan->completed_cookie = dchan->cookie = 1;
524 spin_unlock_bh(&bdma_chan->lock);
525
526#ifdef CONFIG_PCI_MSI
527 if (priv->flags & TSI721_USING_MSIX) {
528 /* Request interrupt service if we are in MSI-X mode */
529 rc = request_irq(
530 priv->msix[TSI721_VECT_DMA0_DONE +
531 bdma_chan->id].vector,
532 tsi721_bdma_msix, 0,
533 priv->msix[TSI721_VECT_DMA0_DONE +
534 bdma_chan->id].irq_name,
535 (void *)bdma_chan);
536
537 if (rc) {
538 dev_dbg(dchan->device->dev,
539 "Unable to allocate MSI-X interrupt for "
540 "BDMA%d-DONE\n", bdma_chan->id);
541 goto err_out;
542 }
543
544 rc = request_irq(priv->msix[TSI721_VECT_DMA0_INT +
545 bdma_chan->id].vector,
546 tsi721_bdma_msix, 0,
547 priv->msix[TSI721_VECT_DMA0_INT +
548 bdma_chan->id].irq_name,
549 (void *)bdma_chan);
550
551 if (rc) {
552 dev_dbg(dchan->device->dev,
553 "Unable to allocate MSI-X interrupt for "
554 "BDMA%d-INT\n", bdma_chan->id);
555 free_irq(
556 priv->msix[TSI721_VECT_DMA0_DONE +
557 bdma_chan->id].vector,
558 (void *)bdma_chan);
559 rc = -EIO;
560 goto err_out;
561 }
562 }
563#endif /* CONFIG_PCI_MSI */
564
565 tasklet_enable(&bdma_chan->tasklet);
566 tsi721_bdma_interrupt_enable(bdma_chan, 1);
567
568 return bdma_chan->bd_num - 1;
569
570err_out:
571 kfree(desc);
572 tsi721_bdma_ch_free(bdma_chan);
573 return rc;
574}
575
576static void tsi721_free_chan_resources(struct dma_chan *dchan)
577{
578 struct tsi721_bdma_chan *bdma_chan = to_tsi721_chan(dchan);
579#ifdef CONFIG_PCI_MSI
580 struct tsi721_device *priv = to_tsi721(dchan->device);
581#endif
582 LIST_HEAD(list);
583
584 dev_dbg(dchan->device->dev, "%s: Entry\n", __func__);
585
586 if (bdma_chan->bd_base == NULL)
587 return;
588
589 BUG_ON(!list_empty(&bdma_chan->active_list));
590 BUG_ON(!list_empty(&bdma_chan->queue));
591
592 tasklet_disable(&bdma_chan->tasklet);
593
594 spin_lock_bh(&bdma_chan->lock);
595 list_splice_init(&bdma_chan->free_list, &list);
596 spin_unlock_bh(&bdma_chan->lock);
597
598 tsi721_bdma_interrupt_enable(bdma_chan, 0);
599
600#ifdef CONFIG_PCI_MSI
601 if (priv->flags & TSI721_USING_MSIX) {
602 free_irq(priv->msix[TSI721_VECT_DMA0_DONE +
603 bdma_chan->id].vector, (void *)bdma_chan);
604 free_irq(priv->msix[TSI721_VECT_DMA0_INT +
605 bdma_chan->id].vector, (void *)bdma_chan);
606 }
607#endif /* CONFIG_PCI_MSI */
608
609 tsi721_bdma_ch_free(bdma_chan);
610 kfree(bdma_chan->tx_desc);
611}
612
613static
614enum dma_status tsi721_tx_status(struct dma_chan *dchan, dma_cookie_t cookie,
615 struct dma_tx_state *txstate)
616{
617 struct tsi721_bdma_chan *bdma_chan = to_tsi721_chan(dchan);
618 dma_cookie_t last_used;
619 dma_cookie_t last_completed;
620 int ret;
621
622 spin_lock_bh(&bdma_chan->lock);
623 last_completed = bdma_chan->completed_cookie;
624 last_used = dchan->cookie;
625 spin_unlock_bh(&bdma_chan->lock);
626
627 ret = dma_async_is_complete(cookie, last_completed, last_used);
628
629 dma_set_tx_state(txstate, last_completed, last_used, 0);
630
631 dev_dbg(dchan->device->dev,
632 "%s: exit, ret: %d, last_completed: %d, last_used: %d\n",
633 __func__, ret, last_completed, last_used);
634
635 return ret;
636}
637
638static void tsi721_issue_pending(struct dma_chan *dchan)
639{
640 struct tsi721_bdma_chan *bdma_chan = to_tsi721_chan(dchan);
641
642 dev_dbg(dchan->device->dev, "%s: Entry\n", __func__);
643
644 if (tsi721_dma_is_idle(bdma_chan)) {
645 spin_lock_bh(&bdma_chan->lock);
646 tsi721_advance_work(bdma_chan);
647 spin_unlock_bh(&bdma_chan->lock);
648 } else
649 dev_dbg(dchan->device->dev,
650 "%s: DMA channel still busy\n", __func__);
651}
652
653static
654struct dma_async_tx_descriptor *tsi721_prep_rio_sg(struct dma_chan *dchan,
655 struct scatterlist *sgl, unsigned int sg_len,
656 enum dma_transfer_direction dir, unsigned long flags,
657 void *tinfo)
658{
659 struct tsi721_bdma_chan *bdma_chan = to_tsi721_chan(dchan);
660 struct tsi721_tx_desc *desc = NULL;
661 struct tsi721_tx_desc *first = NULL;
662 struct scatterlist *sg;
663 struct rio_dma_ext *rext = tinfo;
664 u64 rio_addr = rext->rio_addr; /* limited to 64-bit rio_addr for now */
665 unsigned int i;
666 u32 sys_size = dma_to_mport(dchan->device)->sys_size;
667 enum dma_rtype rtype;
668
669 if (!sgl || !sg_len) {
670 dev_err(dchan->device->dev, "%s: No SG list\n", __func__);
671 return NULL;
672 }
673
674 if (dir == DMA_DEV_TO_MEM)
675 rtype = NREAD;
676 else if (dir == DMA_MEM_TO_DEV) {
677 switch (rext->wr_type) {
678 case RDW_ALL_NWRITE:
679 rtype = ALL_NWRITE;
680 break;
681 case RDW_ALL_NWRITE_R:
682 rtype = ALL_NWRITE_R;
683 break;
684 case RDW_LAST_NWRITE_R:
685 default:
686 rtype = LAST_NWRITE_R;
687 break;
688 }
689 } else {
690 dev_err(dchan->device->dev,
691 "%s: Unsupported DMA direction option\n", __func__);
692 return NULL;
693 }
694
695 for_each_sg(sgl, sg, sg_len, i) {
696 int err;
697
698 dev_dbg(dchan->device->dev, "%s: sg #%d\n", __func__, i);
699 desc = tsi721_desc_get(bdma_chan);
700 if (!desc) {
701 dev_err(dchan->device->dev,
702 "Not enough descriptors available\n");
703 goto err_desc_get;
704 }
705
706 if (sg_is_last(sg))
707 desc->interrupt = (flags & DMA_PREP_INTERRUPT) != 0;
708 else
709 desc->interrupt = false;
710
711 desc->destid = rext->destid;
712 desc->rio_addr = rio_addr;
713 desc->rio_addr_u = 0;
714
715 err = tsi721_fill_desc(bdma_chan, desc, sg, rtype, sys_size);
716 if (err) {
717 dev_err(dchan->device->dev,
718 "Failed to build desc: %d\n", err);
719 goto err_desc_get;
720 }
721
722 rio_addr += sg_dma_len(sg);
723
724 if (!first)
725 first = desc;
726 else
727 list_add_tail(&desc->desc_node, &first->tx_list);
728 }
729
730 first->txd.cookie = -EBUSY;
731 desc->txd.flags = flags;
732
733 return &first->txd;
734
735err_desc_get:
736 tsi721_desc_put(bdma_chan, first);
737 return NULL;
738}
739
740static int tsi721_device_control(struct dma_chan *dchan, enum dma_ctrl_cmd cmd,
741 unsigned long arg)
742{
743 struct tsi721_bdma_chan *bdma_chan = to_tsi721_chan(dchan);
744 struct tsi721_tx_desc *desc, *_d;
745 LIST_HEAD(list);
746
747 dev_dbg(dchan->device->dev, "%s: Entry\n", __func__);
748
749 if (cmd != DMA_TERMINATE_ALL)
750 return -ENXIO;
751
752 spin_lock_bh(&bdma_chan->lock);
753
754 /* make sure to stop the transfer */
755 iowrite32(TSI721_DMAC_CTL_SUSP, bdma_chan->regs + TSI721_DMAC_CTL);
756
757 list_splice_init(&bdma_chan->active_list, &list);
758 list_splice_init(&bdma_chan->queue, &list);
759
760 list_for_each_entry_safe(desc, _d, &list, desc_node)
761 tsi721_dma_chain_complete(bdma_chan, desc);
762
763 spin_unlock_bh(&bdma_chan->lock);
764
765 return 0;
766}
767
768int __devinit tsi721_register_dma(struct tsi721_device *priv)
769{
770 int i;
771 int nr_channels = TSI721_DMA_MAXCH;
772 int err;
773 struct rio_mport *mport = priv->mport;
774
775 mport->dma.dev = &priv->pdev->dev;
776 mport->dma.chancnt = nr_channels;
777
778 INIT_LIST_HEAD(&mport->dma.channels);
779
780 for (i = 0; i < nr_channels; i++) {
781 struct tsi721_bdma_chan *bdma_chan = &priv->bdma[i];
782
783 if (i == TSI721_DMACH_MAINT)
784 continue;
785
786 bdma_chan->bd_num = 64;
787 bdma_chan->regs = priv->regs + TSI721_DMAC_BASE(i);
788
789 bdma_chan->dchan.device = &mport->dma;
790 bdma_chan->dchan.cookie = 1;
791 bdma_chan->dchan.chan_id = i;
792 bdma_chan->id = i;
793
794 spin_lock_init(&bdma_chan->lock);
795
796 INIT_LIST_HEAD(&bdma_chan->active_list);
797 INIT_LIST_HEAD(&bdma_chan->queue);
798 INIT_LIST_HEAD(&bdma_chan->free_list);
799
800 tasklet_init(&bdma_chan->tasklet, tsi721_dma_tasklet,
801 (unsigned long)bdma_chan);
802 tasklet_disable(&bdma_chan->tasklet);
803 list_add_tail(&bdma_chan->dchan.device_node,
804 &mport->dma.channels);
805 }
806
807 dma_cap_zero(mport->dma.cap_mask);
808 dma_cap_set(DMA_PRIVATE, mport->dma.cap_mask);
809 dma_cap_set(DMA_SLAVE, mport->dma.cap_mask);
810
811 mport->dma.device_alloc_chan_resources = tsi721_alloc_chan_resources;
812 mport->dma.device_free_chan_resources = tsi721_free_chan_resources;
813 mport->dma.device_tx_status = tsi721_tx_status;
814 mport->dma.device_issue_pending = tsi721_issue_pending;
815 mport->dma.device_prep_slave_sg = tsi721_prep_rio_sg;
816 mport->dma.device_control = tsi721_device_control;
817
818 err = dma_async_device_register(&mport->dma);
819 if (err)
820 dev_err(&priv->pdev->dev, "Failed to register DMA device\n");
821
822 return err;
823}
diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c
index 86c9a091a2ff..c40665a4fa33 100644
--- a/drivers/rapidio/rio.c
+++ b/drivers/rapidio/rio.c
@@ -1121,6 +1121,87 @@ int rio_std_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
1121 return 0; 1121 return 0;
1122} 1122}
1123 1123
1124#ifdef CONFIG_RAPIDIO_DMA_ENGINE
1125
1126static bool rio_chan_filter(struct dma_chan *chan, void *arg)
1127{
1128 struct rio_dev *rdev = arg;
1129
1130 /* Check that DMA device belongs to the right MPORT */
1131 return (rdev->net->hport ==
1132 container_of(chan->device, struct rio_mport, dma));
1133}
1134
1135/**
1136 * rio_request_dma - request RapidIO capable DMA channel that supports
1137 * specified target RapidIO device.
1138 * @rdev: RIO device control structure
1139 *
1140 * Returns pointer to allocated DMA channel or NULL if failed.
1141 */
1142struct dma_chan *rio_request_dma(struct rio_dev *rdev)
1143{
1144 dma_cap_mask_t mask;
1145 struct dma_chan *dchan;
1146
1147 dma_cap_zero(mask);
1148 dma_cap_set(DMA_SLAVE, mask);
1149 dchan = dma_request_channel(mask, rio_chan_filter, rdev);
1150
1151 return dchan;
1152}
1153EXPORT_SYMBOL_GPL(rio_request_dma);
1154
1155/**
1156 * rio_release_dma - release specified DMA channel
1157 * @dchan: DMA channel to release
1158 */
1159void rio_release_dma(struct dma_chan *dchan)
1160{
1161 dma_release_channel(dchan);
1162}
1163EXPORT_SYMBOL_GPL(rio_release_dma);
1164
1165/**
1166 * rio_dma_prep_slave_sg - RapidIO specific wrapper
1167 * for device_prep_slave_sg callback defined by DMAENGINE.
1168 * @rdev: RIO device control structure
1169 * @dchan: DMA channel to configure
1170 * @data: RIO specific data descriptor
1171 * @direction: DMA data transfer direction (TO or FROM the device)
1172 * @flags: dmaengine defined flags
1173 *
1174 * Initializes RapidIO capable DMA channel for the specified data transfer.
1175 * Uses DMA channel private extension to pass information related to remote
1176 * target RIO device.
1177 * Returns pointer to DMA transaction descriptor or NULL if failed.
1178 */
1179struct dma_async_tx_descriptor *rio_dma_prep_slave_sg(struct rio_dev *rdev,
1180 struct dma_chan *dchan, struct rio_dma_data *data,
1181 enum dma_transfer_direction direction, unsigned long flags)
1182{
1183 struct dma_async_tx_descriptor *txd = NULL;
1184 struct rio_dma_ext rio_ext;
1185
1186 if (dchan->device->device_prep_slave_sg == NULL) {
1187 pr_err("%s: prep_rio_sg == NULL\n", __func__);
1188 return NULL;
1189 }
1190
1191 rio_ext.destid = rdev->destid;
1192 rio_ext.rio_addr_u = data->rio_addr_u;
1193 rio_ext.rio_addr = data->rio_addr;
1194 rio_ext.wr_type = data->wr_type;
1195
1196 txd = dmaengine_prep_rio_sg(dchan, data->sg, data->sg_len,
1197 direction, flags, &rio_ext);
1198
1199 return txd;
1200}
1201EXPORT_SYMBOL_GPL(rio_dma_prep_slave_sg);
1202
1203#endif /* CONFIG_RAPIDIO_DMA_ENGINE */
1204
1124static void rio_fixup_device(struct rio_dev *dev) 1205static void rio_fixup_device(struct rio_dev *dev)
1125{ 1206{
1126} 1207}
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 35819e312624..6cc4358f68c1 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -1033,7 +1033,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_state *state,
1033 if (!retinfo) 1033 if (!retinfo)
1034 return -EFAULT; 1034 return -EFAULT;
1035 memset(&tmp, 0, sizeof(tmp)); 1035 memset(&tmp, 0, sizeof(tmp));
1036 tty_lock(tty); 1036 tty_lock();
1037 tmp.line = tty->index; 1037 tmp.line = tty->index;
1038 tmp.port = state->port; 1038 tmp.port = state->port;
1039 tmp.flags = state->tport.flags; 1039 tmp.flags = state->tport.flags;
@@ -1042,7 +1042,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_state *state,
1042 tmp.close_delay = state->tport.close_delay; 1042 tmp.close_delay = state->tport.close_delay;
1043 tmp.closing_wait = state->tport.closing_wait; 1043 tmp.closing_wait = state->tport.closing_wait;
1044 tmp.custom_divisor = state->custom_divisor; 1044 tmp.custom_divisor = state->custom_divisor;
1045 tty_unlock(tty); 1045 tty_unlock();
1046 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) 1046 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
1047 return -EFAULT; 1047 return -EFAULT;
1048 return 0; 1048 return 0;
@@ -1059,12 +1059,12 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
1059 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 1059 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1060 return -EFAULT; 1060 return -EFAULT;
1061 1061
1062 tty_lock(tty); 1062 tty_lock();
1063 change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) || 1063 change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) ||
1064 new_serial.custom_divisor != state->custom_divisor; 1064 new_serial.custom_divisor != state->custom_divisor;
1065 if (new_serial.irq || new_serial.port != state->port || 1065 if (new_serial.irq || new_serial.port != state->port ||
1066 new_serial.xmit_fifo_size != state->xmit_fifo_size) { 1066 new_serial.xmit_fifo_size != state->xmit_fifo_size) {
1067 tty_unlock(tty); 1067 tty_unlock();
1068 return -EINVAL; 1068 return -EINVAL;
1069 } 1069 }
1070 1070
@@ -1074,7 +1074,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
1074 (new_serial.xmit_fifo_size != state->xmit_fifo_size) || 1074 (new_serial.xmit_fifo_size != state->xmit_fifo_size) ||
1075 ((new_serial.flags & ~ASYNC_USR_MASK) != 1075 ((new_serial.flags & ~ASYNC_USR_MASK) !=
1076 (port->flags & ~ASYNC_USR_MASK))) { 1076 (port->flags & ~ASYNC_USR_MASK))) {
1077 tty_unlock(tty); 1077 tty_unlock();
1078 return -EPERM; 1078 return -EPERM;
1079 } 1079 }
1080 port->flags = ((port->flags & ~ASYNC_USR_MASK) | 1080 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
@@ -1084,7 +1084,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
1084 } 1084 }
1085 1085
1086 if (new_serial.baud_base < 9600) { 1086 if (new_serial.baud_base < 9600) {
1087 tty_unlock(tty); 1087 tty_unlock();
1088 return -EINVAL; 1088 return -EINVAL;
1089 } 1089 }
1090 1090
@@ -1116,7 +1116,7 @@ check_and_exit:
1116 } 1116 }
1117 } else 1117 } else
1118 retval = startup(tty, state); 1118 retval = startup(tty, state);
1119 tty_unlock(tty); 1119 tty_unlock();
1120 return retval; 1120 return retval;
1121} 1121}
1122 1122
diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
index 6984e1a2686a..e61cabdd69df 100644
--- a/drivers/tty/cyclades.c
+++ b/drivers/tty/cyclades.c
@@ -1599,7 +1599,7 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
1599 * If the port is the middle of closing, bail out now 1599 * If the port is the middle of closing, bail out now
1600 */ 1600 */
1601 if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) { 1601 if (tty_hung_up_p(filp) || (info->port.flags & ASYNC_CLOSING)) {
1602 wait_event_interruptible_tty(tty, info->port.close_wait, 1602 wait_event_interruptible_tty(info->port.close_wait,
1603 !(info->port.flags & ASYNC_CLOSING)); 1603 !(info->port.flags & ASYNC_CLOSING));
1604 return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS; 1604 return (info->port.flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
1605 } 1605 }
diff --git a/drivers/tty/n_r3964.c b/drivers/tty/n_r3964.c
index 656ad93bbc96..5c6c31459a2f 100644
--- a/drivers/tty/n_r3964.c
+++ b/drivers/tty/n_r3964.c
@@ -1065,8 +1065,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1065 1065
1066 TRACE_L("read()"); 1066 TRACE_L("read()");
1067 1067
1068 /* FIXME: should use a private lock */ 1068 tty_lock();
1069 tty_lock(tty);
1070 1069
1071 pClient = findClient(pInfo, task_pid(current)); 1070 pClient = findClient(pInfo, task_pid(current));
1072 if (pClient) { 1071 if (pClient) {
@@ -1078,7 +1077,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1078 goto unlock; 1077 goto unlock;
1079 } 1078 }
1080 /* block until there is a message: */ 1079 /* block until there is a message: */
1081 wait_event_interruptible_tty(tty, pInfo->read_wait, 1080 wait_event_interruptible_tty(pInfo->read_wait,
1082 (pMsg = remove_msg(pInfo, pClient))); 1081 (pMsg = remove_msg(pInfo, pClient)));
1083 } 1082 }
1084 1083
@@ -1108,7 +1107,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1108 } 1107 }
1109 ret = -EPERM; 1108 ret = -EPERM;
1110unlock: 1109unlock:
1111 tty_unlock(tty); 1110 tty_unlock();
1112 return ret; 1111 return ret;
1113} 1112}
1114 1113
@@ -1157,7 +1156,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1157 pHeader->locks = 0; 1156 pHeader->locks = 0;
1158 pHeader->owner = NULL; 1157 pHeader->owner = NULL;
1159 1158
1160 tty_lock(tty); 1159 tty_lock();
1161 1160
1162 pClient = findClient(pInfo, task_pid(current)); 1161 pClient = findClient(pInfo, task_pid(current));
1163 if (pClient) { 1162 if (pClient) {
@@ -1176,7 +1175,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1176 add_tx_queue(pInfo, pHeader); 1175 add_tx_queue(pInfo, pHeader);
1177 trigger_transmit(pInfo); 1176 trigger_transmit(pInfo);
1178 1177
1179 tty_unlock(tty); 1178 tty_unlock();
1180 1179
1181 return 0; 1180 return 0;
1182} 1181}
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 65c7c62c7aae..5505ffc91da4 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -47,7 +47,6 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
47 wake_up_interruptible(&tty->read_wait); 47 wake_up_interruptible(&tty->read_wait);
48 wake_up_interruptible(&tty->write_wait); 48 wake_up_interruptible(&tty->write_wait);
49 tty->packet = 0; 49 tty->packet = 0;
50 /* Review - krefs on tty_link ?? */
51 if (!tty->link) 50 if (!tty->link)
52 return; 51 return;
53 tty->link->packet = 0; 52 tty->link->packet = 0;
@@ -63,9 +62,9 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
63 mutex_unlock(&devpts_mutex); 62 mutex_unlock(&devpts_mutex);
64 } 63 }
65#endif 64#endif
66 tty_unlock(tty); 65 tty_unlock();
67 tty_vhangup(tty->link); 66 tty_vhangup(tty->link);
68 tty_lock(tty); 67 tty_lock();
69 } 68 }
70} 69}
71 70
@@ -623,27 +622,26 @@ static int ptmx_open(struct inode *inode, struct file *filp)
623 return retval; 622 return retval;
624 623
625 /* find a device that is not in use. */ 624 /* find a device that is not in use. */
626 mutex_lock(&devpts_mutex); 625 tty_lock();
627 index = devpts_new_index(inode); 626 index = devpts_new_index(inode);
627 tty_unlock();
628 if (index < 0) { 628 if (index < 0) {
629 retval = index; 629 retval = index;
630 goto err_file; 630 goto err_file;
631 } 631 }
632 632
633 mutex_unlock(&devpts_mutex);
634
635 mutex_lock(&tty_mutex); 633 mutex_lock(&tty_mutex);
634 mutex_lock(&devpts_mutex);
636 tty = tty_init_dev(ptm_driver, index); 635 tty = tty_init_dev(ptm_driver, index);
636 mutex_unlock(&devpts_mutex);
637 tty_lock();
638 mutex_unlock(&tty_mutex);
637 639
638 if (IS_ERR(tty)) { 640 if (IS_ERR(tty)) {
639 retval = PTR_ERR(tty); 641 retval = PTR_ERR(tty);
640 goto out; 642 goto out;
641 } 643 }
642 644
643 /* The tty returned here is locked so we can safely
644 drop the mutex */
645 mutex_unlock(&tty_mutex);
646
647 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ 645 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
648 646
649 tty_add_file(tty, filp); 647 tty_add_file(tty, filp);
@@ -656,17 +654,16 @@ static int ptmx_open(struct inode *inode, struct file *filp)
656 if (retval) 654 if (retval)
657 goto err_release; 655 goto err_release;
658 656
659 tty_unlock(tty); 657 tty_unlock();
660 return 0; 658 return 0;
661err_release: 659err_release:
662 tty_unlock(tty); 660 tty_unlock();
663 tty_release(inode, filp); 661 tty_release(inode, filp);
664 return retval; 662 return retval;
665out: 663out:
666 mutex_unlock(&tty_mutex);
667 devpts_kill_index(inode, index); 664 devpts_kill_index(inode, index);
665 tty_unlock();
668err_file: 666err_file:
669 mutex_unlock(&devpts_mutex);
670 tty_free_file(filp); 667 tty_free_file(filp);
671 return retval; 668 return retval;
672} 669}
diff --git a/drivers/tty/serial/crisv10.c b/drivers/tty/serial/crisv10.c
index 7264d4d26717..80b6b1b1f725 100644
--- a/drivers/tty/serial/crisv10.c
+++ b/drivers/tty/serial/crisv10.c
@@ -3976,7 +3976,7 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
3976 */ 3976 */
3977 if (tty_hung_up_p(filp) || 3977 if (tty_hung_up_p(filp) ||
3978 (info->flags & ASYNC_CLOSING)) { 3978 (info->flags & ASYNC_CLOSING)) {
3979 wait_event_interruptible_tty(tty, info->close_wait, 3979 wait_event_interruptible_tty(info->close_wait,
3980 !(info->flags & ASYNC_CLOSING)); 3980 !(info->flags & ASYNC_CLOSING));
3981#ifdef SERIAL_DO_RESTART 3981#ifdef SERIAL_DO_RESTART
3982 if (info->flags & ASYNC_HUP_NOTIFY) 3982 if (info->flags & ASYNC_HUP_NOTIFY)
@@ -4052,9 +4052,9 @@ block_til_ready(struct tty_struct *tty, struct file * filp,
4052 printk("block_til_ready blocking: ttyS%d, count = %d\n", 4052 printk("block_til_ready blocking: ttyS%d, count = %d\n",
4053 info->line, info->count); 4053 info->line, info->count);
4054#endif 4054#endif
4055 tty_unlock(tty); 4055 tty_unlock();
4056 schedule(); 4056 schedule();
4057 tty_lock(tty); 4057 tty_lock();
4058 } 4058 }
4059 set_current_state(TASK_RUNNING); 4059 set_current_state(TASK_RUNNING);
4060 remove_wait_queue(&info->open_wait, &wait); 4060 remove_wait_queue(&info->open_wait, &wait);
@@ -4115,7 +4115,7 @@ rs_open(struct tty_struct *tty, struct file * filp)
4115 */ 4115 */
4116 if (tty_hung_up_p(filp) || 4116 if (tty_hung_up_p(filp) ||
4117 (info->flags & ASYNC_CLOSING)) { 4117 (info->flags & ASYNC_CLOSING)) {
4118 wait_event_interruptible_tty(tty, info->close_wait, 4118 wait_event_interruptible_tty(info->close_wait,
4119 !(info->flags & ASYNC_CLOSING)); 4119 !(info->flags & ASYNC_CLOSING));
4120#ifdef SERIAL_DO_RESTART 4120#ifdef SERIAL_DO_RESTART
4121 return ((info->flags & ASYNC_HUP_NOTIFY) ? 4121 return ((info->flags & ASYNC_HUP_NOTIFY) ?
diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
index 5ed0daae6564..593d40ad0a6b 100644
--- a/drivers/tty/synclink.c
+++ b/drivers/tty/synclink.c
@@ -3338,9 +3338,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3338 printk("%s(%d):block_til_ready blocking on %s count=%d\n", 3338 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
3339 __FILE__,__LINE__, tty->driver->name, port->count ); 3339 __FILE__,__LINE__, tty->driver->name, port->count );
3340 3340
3341 tty_unlock(tty); 3341 tty_unlock();
3342 schedule(); 3342 schedule();
3343 tty_lock(tty); 3343 tty_lock();
3344 } 3344 }
3345 3345
3346 set_current_state(TASK_RUNNING); 3346 set_current_state(TASK_RUNNING);
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index 45b43f11ca39..aa1debf97cc7 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -3336,9 +3336,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3336 } 3336 }
3337 3337
3338 DBGINFO(("%s block_til_ready wait\n", tty->driver->name)); 3338 DBGINFO(("%s block_til_ready wait\n", tty->driver->name));
3339 tty_unlock(tty); 3339 tty_unlock();
3340 schedule(); 3340 schedule();
3341 tty_lock(tty); 3341 tty_lock();
3342 } 3342 }
3343 3343
3344 set_current_state(TASK_RUNNING); 3344 set_current_state(TASK_RUNNING);
diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
index 4a1e4f07765b..a3dddc12d2fe 100644
--- a/drivers/tty/synclinkmp.c
+++ b/drivers/tty/synclinkmp.c
@@ -3357,9 +3357,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3357 printk("%s(%d):%s block_til_ready() count=%d\n", 3357 printk("%s(%d):%s block_til_ready() count=%d\n",
3358 __FILE__,__LINE__, tty->driver->name, port->count ); 3358 __FILE__,__LINE__, tty->driver->name, port->count );
3359 3359
3360 tty_unlock(tty); 3360 tty_unlock();
3361 schedule(); 3361 schedule();
3362 tty_lock(tty); 3362 tty_lock();
3363 } 3363 }
3364 3364
3365 set_current_state(TASK_RUNNING); 3365 set_current_state(TASK_RUNNING);
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 9e930c009bf2..b425c79675ad 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -185,7 +185,6 @@ void free_tty_struct(struct tty_struct *tty)
185 put_device(tty->dev); 185 put_device(tty->dev);
186 kfree(tty->write_buf); 186 kfree(tty->write_buf);
187 tty_buffer_free_all(tty); 187 tty_buffer_free_all(tty);
188 tty->magic = 0xDEADDEAD;
189 kfree(tty); 188 kfree(tty);
190} 189}
191 190
@@ -574,7 +573,7 @@ void __tty_hangup(struct tty_struct *tty)
574 } 573 }
575 spin_unlock(&redirect_lock); 574 spin_unlock(&redirect_lock);
576 575
577 tty_lock(tty); 576 tty_lock();
578 577
579 /* some functions below drop BTM, so we need this bit */ 578 /* some functions below drop BTM, so we need this bit */
580 set_bit(TTY_HUPPING, &tty->flags); 579 set_bit(TTY_HUPPING, &tty->flags);
@@ -667,7 +666,7 @@ void __tty_hangup(struct tty_struct *tty)
667 clear_bit(TTY_HUPPING, &tty->flags); 666 clear_bit(TTY_HUPPING, &tty->flags);
668 tty_ldisc_enable(tty); 667 tty_ldisc_enable(tty);
669 668
670 tty_unlock(tty); 669 tty_unlock();
671 670
672 if (f) 671 if (f)
673 fput(f); 672 fput(f);
@@ -1104,12 +1103,12 @@ void tty_write_message(struct tty_struct *tty, char *msg)
1104{ 1103{
1105 if (tty) { 1104 if (tty) {
1106 mutex_lock(&tty->atomic_write_lock); 1105 mutex_lock(&tty->atomic_write_lock);
1107 tty_lock(tty); 1106 tty_lock();
1108 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) { 1107 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags)) {
1109 tty_unlock(tty); 1108 tty_unlock();
1110 tty->ops->write(tty, msg, strlen(msg)); 1109 tty->ops->write(tty, msg, strlen(msg));
1111 } else 1110 } else
1112 tty_unlock(tty); 1111 tty_unlock();
1113 tty_write_unlock(tty); 1112 tty_write_unlock(tty);
1114 } 1113 }
1115 return; 1114 return;
@@ -1404,7 +1403,6 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
1404 } 1403 }
1405 initialize_tty_struct(tty, driver, idx); 1404 initialize_tty_struct(tty, driver, idx);
1406 1405
1407 tty_lock(tty);
1408 retval = tty_driver_install_tty(driver, tty); 1406 retval = tty_driver_install_tty(driver, tty);
1409 if (retval < 0) 1407 if (retval < 0)
1410 goto err_deinit_tty; 1408 goto err_deinit_tty;
@@ -1417,11 +1415,9 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
1417 retval = tty_ldisc_setup(tty, tty->link); 1415 retval = tty_ldisc_setup(tty, tty->link);
1418 if (retval) 1416 if (retval)
1419 goto err_release_tty; 1417 goto err_release_tty;
1420 /* Return the tty locked so that it cannot vanish under the caller */
1421 return tty; 1418 return tty;
1422 1419
1423err_deinit_tty: 1420err_deinit_tty:
1424 tty_unlock(tty);
1425 deinitialize_tty_struct(tty); 1421 deinitialize_tty_struct(tty);
1426 free_tty_struct(tty); 1422 free_tty_struct(tty);
1427err_module_put: 1423err_module_put:
@@ -1430,7 +1426,6 @@ err_module_put:
1430 1426
1431 /* call the tty release_tty routine to clean out this slot */ 1427 /* call the tty release_tty routine to clean out this slot */
1432err_release_tty: 1428err_release_tty:
1433 tty_unlock(tty);
1434 printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, " 1429 printk_ratelimited(KERN_INFO "tty_init_dev: ldisc open failed, "
1435 "clearing slot %d\n", idx); 1430 "clearing slot %d\n", idx);
1436 release_tty(tty, idx); 1431 release_tty(tty, idx);
@@ -1633,7 +1628,7 @@ int tty_release(struct inode *inode, struct file *filp)
1633 if (tty_paranoia_check(tty, inode, __func__)) 1628 if (tty_paranoia_check(tty, inode, __func__))
1634 return 0; 1629 return 0;
1635 1630
1636 tty_lock(tty); 1631 tty_lock();
1637 check_tty_count(tty, __func__); 1632 check_tty_count(tty, __func__);
1638 1633
1639 __tty_fasync(-1, filp, 0); 1634 __tty_fasync(-1, filp, 0);
@@ -1642,11 +1637,10 @@ int tty_release(struct inode *inode, struct file *filp)
1642 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1637 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1643 tty->driver->subtype == PTY_TYPE_MASTER); 1638 tty->driver->subtype == PTY_TYPE_MASTER);
1644 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0; 1639 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0;
1645 /* Review: parallel close */
1646 o_tty = tty->link; 1640 o_tty = tty->link;
1647 1641
1648 if (tty_release_checks(tty, o_tty, idx)) { 1642 if (tty_release_checks(tty, o_tty, idx)) {
1649 tty_unlock(tty); 1643 tty_unlock();
1650 return 0; 1644 return 0;
1651 } 1645 }
1652 1646
@@ -1658,7 +1652,7 @@ int tty_release(struct inode *inode, struct file *filp)
1658 if (tty->ops->close) 1652 if (tty->ops->close)
1659 tty->ops->close(tty, filp); 1653 tty->ops->close(tty, filp);
1660 1654
1661 tty_unlock(tty); 1655 tty_unlock();
1662 /* 1656 /*
1663 * Sanity check: if tty->count is going to zero, there shouldn't be 1657 * Sanity check: if tty->count is going to zero, there shouldn't be
1664 * any waiters on tty->read_wait or tty->write_wait. We test the 1658 * any waiters on tty->read_wait or tty->write_wait. We test the
@@ -1681,7 +1675,7 @@ int tty_release(struct inode *inode, struct file *filp)
1681 opens on /dev/tty */ 1675 opens on /dev/tty */
1682 1676
1683 mutex_lock(&tty_mutex); 1677 mutex_lock(&tty_mutex);
1684 tty_lock_pair(tty, o_tty); 1678 tty_lock();
1685 tty_closing = tty->count <= 1; 1679 tty_closing = tty->count <= 1;
1686 o_tty_closing = o_tty && 1680 o_tty_closing = o_tty &&
1687 (o_tty->count <= (pty_master ? 1 : 0)); 1681 (o_tty->count <= (pty_master ? 1 : 0));
@@ -1712,7 +1706,7 @@ int tty_release(struct inode *inode, struct file *filp)
1712 1706
1713 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n", 1707 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n",
1714 __func__, tty_name(tty, buf)); 1708 __func__, tty_name(tty, buf));
1715 tty_unlock_pair(tty, o_tty); 1709 tty_unlock();
1716 mutex_unlock(&tty_mutex); 1710 mutex_unlock(&tty_mutex);
1717 schedule(); 1711 schedule();
1718 } 1712 }
@@ -1775,7 +1769,7 @@ int tty_release(struct inode *inode, struct file *filp)
1775 1769
1776 /* check whether both sides are closing ... */ 1770 /* check whether both sides are closing ... */
1777 if (!tty_closing || (o_tty && !o_tty_closing)) { 1771 if (!tty_closing || (o_tty && !o_tty_closing)) {
1778 tty_unlock_pair(tty, o_tty); 1772 tty_unlock();
1779 return 0; 1773 return 0;
1780 } 1774 }
1781 1775
@@ -1788,16 +1782,14 @@ int tty_release(struct inode *inode, struct file *filp)
1788 tty_ldisc_release(tty, o_tty); 1782 tty_ldisc_release(tty, o_tty);
1789 /* 1783 /*
1790 * The release_tty function takes care of the details of clearing 1784 * The release_tty function takes care of the details of clearing
1791 * the slots and preserving the termios structure. The tty_unlock_pair 1785 * the slots and preserving the termios structure.
1792 * should be safe as we keep a kref while the tty is locked (so the
1793 * unlock never unlocks a freed tty).
1794 */ 1786 */
1795 release_tty(tty, idx); 1787 release_tty(tty, idx);
1796 tty_unlock_pair(tty, o_tty);
1797 1788
1798 /* Make this pty number available for reallocation */ 1789 /* Make this pty number available for reallocation */
1799 if (devpts) 1790 if (devpts)
1800 devpts_kill_index(inode, idx); 1791 devpts_kill_index(inode, idx);
1792 tty_unlock();
1801 return 0; 1793 return 0;
1802} 1794}
1803 1795
@@ -1901,9 +1893,6 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
1901 * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev. 1893 * Locking: tty_mutex protects tty, tty_lookup_driver and tty_init_dev.
1902 * tty->count should protect the rest. 1894 * tty->count should protect the rest.
1903 * ->siglock protects ->signal/->sighand 1895 * ->siglock protects ->signal/->sighand
1904 *
1905 * Note: the tty_unlock/lock cases without a ref are only safe due to
1906 * tty_mutex
1907 */ 1896 */
1908 1897
1909static int tty_open(struct inode *inode, struct file *filp) 1898static int tty_open(struct inode *inode, struct file *filp)
@@ -1927,7 +1916,8 @@ retry_open:
1927 retval = 0; 1916 retval = 0;
1928 1917
1929 mutex_lock(&tty_mutex); 1918 mutex_lock(&tty_mutex);
1930 /* This is protected by the tty_mutex */ 1919 tty_lock();
1920
1931 tty = tty_open_current_tty(device, filp); 1921 tty = tty_open_current_tty(device, filp);
1932 if (IS_ERR(tty)) { 1922 if (IS_ERR(tty)) {
1933 retval = PTR_ERR(tty); 1923 retval = PTR_ERR(tty);
@@ -1948,19 +1938,17 @@ retry_open:
1948 } 1938 }
1949 1939
1950 if (tty) { 1940 if (tty) {
1951 tty_lock(tty);
1952 retval = tty_reopen(tty); 1941 retval = tty_reopen(tty);
1953 if (retval < 0) { 1942 if (retval)
1954 tty_unlock(tty);
1955 tty = ERR_PTR(retval); 1943 tty = ERR_PTR(retval);
1956 } 1944 } else
1957 } else /* Returns with the tty_lock held for now */
1958 tty = tty_init_dev(driver, index); 1945 tty = tty_init_dev(driver, index);
1959 1946
1960 mutex_unlock(&tty_mutex); 1947 mutex_unlock(&tty_mutex);
1961 if (driver) 1948 if (driver)
1962 tty_driver_kref_put(driver); 1949 tty_driver_kref_put(driver);
1963 if (IS_ERR(tty)) { 1950 if (IS_ERR(tty)) {
1951 tty_unlock();
1964 retval = PTR_ERR(tty); 1952 retval = PTR_ERR(tty);
1965 goto err_file; 1953 goto err_file;
1966 } 1954 }
@@ -1989,7 +1977,7 @@ retry_open:
1989 printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__, 1977 printk(KERN_DEBUG "%s: error %d in opening %s...\n", __func__,
1990 retval, tty->name); 1978 retval, tty->name);
1991#endif 1979#endif
1992 tty_unlock(tty); /* need to call tty_release without BTM */ 1980 tty_unlock(); /* need to call tty_release without BTM */
1993 tty_release(inode, filp); 1981 tty_release(inode, filp);
1994 if (retval != -ERESTARTSYS) 1982 if (retval != -ERESTARTSYS)
1995 return retval; 1983 return retval;
@@ -2001,15 +1989,17 @@ retry_open:
2001 /* 1989 /*
2002 * Need to reset f_op in case a hangup happened. 1990 * Need to reset f_op in case a hangup happened.
2003 */ 1991 */
1992 tty_lock();
2004 if (filp->f_op == &hung_up_tty_fops) 1993 if (filp->f_op == &hung_up_tty_fops)
2005 filp->f_op = &tty_fops; 1994 filp->f_op = &tty_fops;
1995 tty_unlock();
2006 goto retry_open; 1996 goto retry_open;
2007 } 1997 }
2008 tty_unlock(tty); 1998 tty_unlock();
2009 1999
2010 2000
2011 mutex_lock(&tty_mutex); 2001 mutex_lock(&tty_mutex);
2012 tty_lock(tty); 2002 tty_lock();
2013 spin_lock_irq(&current->sighand->siglock); 2003 spin_lock_irq(&current->sighand->siglock);
2014 if (!noctty && 2004 if (!noctty &&
2015 current->signal->leader && 2005 current->signal->leader &&
@@ -2017,10 +2007,11 @@ retry_open:
2017 tty->session == NULL) 2007 tty->session == NULL)
2018 __proc_set_tty(current, tty); 2008 __proc_set_tty(current, tty);
2019 spin_unlock_irq(&current->sighand->siglock); 2009 spin_unlock_irq(&current->sighand->siglock);
2020 tty_unlock(tty); 2010 tty_unlock();
2021 mutex_unlock(&tty_mutex); 2011 mutex_unlock(&tty_mutex);
2022 return 0; 2012 return 0;
2023err_unlock: 2013err_unlock:
2014 tty_unlock();
2024 mutex_unlock(&tty_mutex); 2015 mutex_unlock(&tty_mutex);
2025 /* after locks to avoid deadlock */ 2016 /* after locks to avoid deadlock */
2026 if (!IS_ERR_OR_NULL(driver)) 2017 if (!IS_ERR_OR_NULL(driver))
@@ -2103,13 +2094,10 @@ out:
2103 2094
2104static int tty_fasync(int fd, struct file *filp, int on) 2095static int tty_fasync(int fd, struct file *filp, int on)
2105{ 2096{
2106 struct tty_struct *tty = file_tty(filp);
2107 int retval; 2097 int retval;
2108 2098 tty_lock();
2109 tty_lock(tty);
2110 retval = __tty_fasync(fd, filp, on); 2099 retval = __tty_fasync(fd, filp, on);
2111 tty_unlock(tty); 2100 tty_unlock();
2112
2113 return retval; 2101 return retval;
2114} 2102}
2115 2103
@@ -2946,7 +2934,6 @@ void initialize_tty_struct(struct tty_struct *tty,
2946 tty->pgrp = NULL; 2934 tty->pgrp = NULL;
2947 tty->overrun_time = jiffies; 2935 tty->overrun_time = jiffies;
2948 tty_buffer_init(tty); 2936 tty_buffer_init(tty);
2949 mutex_init(&tty->legacy_mutex);
2950 mutex_init(&tty->termios_mutex); 2937 mutex_init(&tty->termios_mutex);
2951 mutex_init(&tty->ldisc_mutex); 2938 mutex_init(&tty->ldisc_mutex);
2952 init_waitqueue_head(&tty->write_wait); 2939 init_waitqueue_head(&tty->write_wait);
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index ba8be396a621..9911eb6b34cd 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -568,7 +568,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
568 if (IS_ERR(new_ldisc)) 568 if (IS_ERR(new_ldisc))
569 return PTR_ERR(new_ldisc); 569 return PTR_ERR(new_ldisc);
570 570
571 tty_lock(tty); 571 tty_lock();
572 /* 572 /*
573 * We need to look at the tty locking here for pty/tty pairs 573 * We need to look at the tty locking here for pty/tty pairs
574 * when both sides try to change in parallel. 574 * when both sides try to change in parallel.
@@ -582,12 +582,12 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
582 */ 582 */
583 583
584 if (tty->ldisc->ops->num == ldisc) { 584 if (tty->ldisc->ops->num == ldisc) {
585 tty_unlock(tty); 585 tty_unlock();
586 tty_ldisc_put(new_ldisc); 586 tty_ldisc_put(new_ldisc);
587 return 0; 587 return 0;
588 } 588 }
589 589
590 tty_unlock(tty); 590 tty_unlock();
591 /* 591 /*
592 * Problem: What do we do if this blocks ? 592 * Problem: What do we do if this blocks ?
593 * We could deadlock here 593 * We could deadlock here
@@ -595,7 +595,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
595 595
596 tty_wait_until_sent(tty, 0); 596 tty_wait_until_sent(tty, 0);
597 597
598 tty_lock(tty); 598 tty_lock();
599 mutex_lock(&tty->ldisc_mutex); 599 mutex_lock(&tty->ldisc_mutex);
600 600
601 /* 601 /*
@@ -605,10 +605,10 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
605 605
606 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { 606 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) {
607 mutex_unlock(&tty->ldisc_mutex); 607 mutex_unlock(&tty->ldisc_mutex);
608 tty_unlock(tty); 608 tty_unlock();
609 wait_event(tty_ldisc_wait, 609 wait_event(tty_ldisc_wait,
610 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0); 610 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0);
611 tty_lock(tty); 611 tty_lock();
612 mutex_lock(&tty->ldisc_mutex); 612 mutex_lock(&tty->ldisc_mutex);
613 } 613 }
614 614
@@ -623,7 +623,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
623 623
624 o_ldisc = tty->ldisc; 624 o_ldisc = tty->ldisc;
625 625
626 tty_unlock(tty); 626 tty_unlock();
627 /* 627 /*
628 * Make sure we don't change while someone holds a 628 * Make sure we don't change while someone holds a
629 * reference to the line discipline. The TTY_LDISC bit 629 * reference to the line discipline. The TTY_LDISC bit
@@ -650,7 +650,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
650 650
651 retval = tty_ldisc_wait_idle(tty, 5 * HZ); 651 retval = tty_ldisc_wait_idle(tty, 5 * HZ);
652 652
653 tty_lock(tty); 653 tty_lock();
654 mutex_lock(&tty->ldisc_mutex); 654 mutex_lock(&tty->ldisc_mutex);
655 655
656 /* handle wait idle failure locked */ 656 /* handle wait idle failure locked */
@@ -665,7 +665,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc)
665 clear_bit(TTY_LDISC_CHANGING, &tty->flags); 665 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
666 mutex_unlock(&tty->ldisc_mutex); 666 mutex_unlock(&tty->ldisc_mutex);
667 tty_ldisc_put(new_ldisc); 667 tty_ldisc_put(new_ldisc);
668 tty_unlock(tty); 668 tty_unlock();
669 return -EIO; 669 return -EIO;
670 } 670 }
671 671
@@ -708,7 +708,7 @@ enable:
708 if (o_work) 708 if (o_work)
709 schedule_work(&o_tty->buf.work); 709 schedule_work(&o_tty->buf.work);
710 mutex_unlock(&tty->ldisc_mutex); 710 mutex_unlock(&tty->ldisc_mutex);
711 tty_unlock(tty); 711 tty_unlock();
712 return retval; 712 return retval;
713} 713}
714 714
@@ -816,11 +816,11 @@ void tty_ldisc_hangup(struct tty_struct *tty)
816 * need to wait for another function taking the BTM 816 * need to wait for another function taking the BTM
817 */ 817 */
818 clear_bit(TTY_LDISC, &tty->flags); 818 clear_bit(TTY_LDISC, &tty->flags);
819 tty_unlock(tty); 819 tty_unlock();
820 cancel_work_sync(&tty->buf.work); 820 cancel_work_sync(&tty->buf.work);
821 mutex_unlock(&tty->ldisc_mutex); 821 mutex_unlock(&tty->ldisc_mutex);
822retry: 822retry:
823 tty_lock(tty); 823 tty_lock();
824 mutex_lock(&tty->ldisc_mutex); 824 mutex_lock(&tty->ldisc_mutex);
825 825
826 /* At this point we have a closed ldisc and we want to 826 /* At this point we have a closed ldisc and we want to
@@ -831,7 +831,7 @@ retry:
831 if (atomic_read(&tty->ldisc->users) != 1) { 831 if (atomic_read(&tty->ldisc->users) != 1) {
832 char cur_n[TASK_COMM_LEN], tty_n[64]; 832 char cur_n[TASK_COMM_LEN], tty_n[64];
833 long timeout = 3 * HZ; 833 long timeout = 3 * HZ;
834 tty_unlock(tty); 834 tty_unlock();
835 835
836 while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) { 836 while (tty_ldisc_wait_idle(tty, timeout) == -EBUSY) {
837 timeout = MAX_SCHEDULE_TIMEOUT; 837 timeout = MAX_SCHEDULE_TIMEOUT;
@@ -894,23 +894,6 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
894 tty_ldisc_enable(tty); 894 tty_ldisc_enable(tty);
895 return 0; 895 return 0;
896} 896}
897
898static void tty_ldisc_kill(struct tty_struct *tty)
899{
900 mutex_lock(&tty->ldisc_mutex);
901 /*
902 * Now kill off the ldisc
903 */
904 tty_ldisc_close(tty, tty->ldisc);
905 tty_ldisc_put(tty->ldisc);
906 /* Force an oops if we mess this up */
907 tty->ldisc = NULL;
908
909 /* Ensure the next open requests the N_TTY ldisc */
910 tty_set_termios_ldisc(tty, N_TTY);
911 mutex_unlock(&tty->ldisc_mutex);
912}
913
914/** 897/**
915 * tty_ldisc_release - release line discipline 898 * tty_ldisc_release - release line discipline
916 * @tty: tty being shut down 899 * @tty: tty being shut down
@@ -929,19 +912,27 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
929 * race with the set_ldisc code path. 912 * race with the set_ldisc code path.
930 */ 913 */
931 914
932 tty_unlock_pair(tty, o_tty); 915 tty_unlock();
933 tty_ldisc_halt(tty); 916 tty_ldisc_halt(tty);
934 tty_ldisc_flush_works(tty); 917 tty_ldisc_flush_works(tty);
935 if (o_tty) { 918 tty_lock();
936 tty_ldisc_halt(o_tty);
937 tty_ldisc_flush_works(o_tty);
938 }
939 tty_lock_pair(tty, o_tty);
940 919
920 mutex_lock(&tty->ldisc_mutex);
921 /*
922 * Now kill off the ldisc
923 */
924 tty_ldisc_close(tty, tty->ldisc);
925 tty_ldisc_put(tty->ldisc);
926 /* Force an oops if we mess this up */
927 tty->ldisc = NULL;
928
929 /* Ensure the next open requests the N_TTY ldisc */
930 tty_set_termios_ldisc(tty, N_TTY);
931 mutex_unlock(&tty->ldisc_mutex);
941 932
942 tty_ldisc_kill(tty); 933 /* This will need doing differently if we need to lock */
943 if (o_tty) 934 if (o_tty)
944 tty_ldisc_kill(o_tty); 935 tty_ldisc_release(o_tty, NULL);
945 936
946 /* And the memory resources remaining (buffers, termios) will be 937 /* And the memory resources remaining (buffers, termios) will be
947 disposed of when the kref hits zero */ 938 disposed of when the kref hits zero */
diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c
index 67feac9e6ebb..9ff986c32a21 100644
--- a/drivers/tty/tty_mutex.c
+++ b/drivers/tty/tty_mutex.c
@@ -4,70 +4,29 @@
4#include <linux/semaphore.h> 4#include <linux/semaphore.h>
5#include <linux/sched.h> 5#include <linux/sched.h>
6 6
7/* Legacy tty mutex glue */ 7/*
8 8 * The 'big tty mutex'
9enum { 9 *
10 TTY_MUTEX_NORMAL, 10 * This mutex is taken and released by tty_lock() and tty_unlock(),
11 TTY_MUTEX_NESTED, 11 * replacing the older big kernel lock.
12}; 12 * It can no longer be taken recursively, and does not get
13 * released implicitly while sleeping.
14 *
15 * Don't use in new code.
16 */
17static DEFINE_MUTEX(big_tty_mutex);
13 18
14/* 19/*
15 * Getting the big tty mutex. 20 * Getting the big tty mutex.
16 */ 21 */
17 22void __lockfunc tty_lock(void)
18static void __lockfunc tty_lock_nested(struct tty_struct *tty,
19 unsigned int subclass)
20{ 23{
21 if (tty->magic != TTY_MAGIC) { 24 mutex_lock(&big_tty_mutex);
22 printk(KERN_ERR "L Bad %p\n", tty);
23 WARN_ON(1);
24 return;
25 }
26 tty_kref_get(tty);
27 mutex_lock_nested(&tty->legacy_mutex, subclass);
28}
29
30void __lockfunc tty_lock(struct tty_struct *tty)
31{
32 return tty_lock_nested(tty, TTY_MUTEX_NORMAL);
33} 25}
34EXPORT_SYMBOL(tty_lock); 26EXPORT_SYMBOL(tty_lock);
35 27
36void __lockfunc tty_unlock(struct tty_struct *tty) 28void __lockfunc tty_unlock(void)
37{ 29{
38 if (tty->magic != TTY_MAGIC) { 30 mutex_unlock(&big_tty_mutex);
39 printk(KERN_ERR "U Bad %p\n", tty);
40 WARN_ON(1);
41 return;
42 }
43 mutex_unlock(&tty->legacy_mutex);
44 tty_kref_put(tty);
45} 31}
46EXPORT_SYMBOL(tty_unlock); 32EXPORT_SYMBOL(tty_unlock);
47
48/*
49 * Getting the big tty mutex for a pair of ttys with lock ordering
50 * On a non pty/tty pair tty2 can be NULL which is just fine.
51 */
52void __lockfunc tty_lock_pair(struct tty_struct *tty,
53 struct tty_struct *tty2)
54{
55 if (tty < tty2) {
56 tty_lock(tty);
57 tty_lock_nested(tty2, TTY_MUTEX_NESTED);
58 } else {
59 if (tty2 && tty2 != tty)
60 tty_lock(tty2);
61 tty_lock_nested(tty, TTY_MUTEX_NESTED);
62 }
63}
64EXPORT_SYMBOL(tty_lock_pair);
65
66void __lockfunc tty_unlock_pair(struct tty_struct *tty,
67 struct tty_struct *tty2)
68{
69 tty_unlock(tty);
70 if (tty2 && tty2 != tty)
71 tty_unlock(tty2);
72}
73EXPORT_SYMBOL(tty_unlock_pair);
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index d9cca95a5452..bf6e238146ae 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -230,7 +230,7 @@ int tty_port_block_til_ready(struct tty_port *port,
230 230
231 /* block if port is in the process of being closed */ 231 /* block if port is in the process of being closed */
232 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { 232 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
233 wait_event_interruptible_tty(tty, port->close_wait, 233 wait_event_interruptible_tty(port->close_wait,
234 !(port->flags & ASYNC_CLOSING)); 234 !(port->flags & ASYNC_CLOSING));
235 if (port->flags & ASYNC_HUP_NOTIFY) 235 if (port->flags & ASYNC_HUP_NOTIFY)
236 return -EAGAIN; 236 return -EAGAIN;
@@ -296,9 +296,9 @@ int tty_port_block_til_ready(struct tty_port *port,
296 retval = -ERESTARTSYS; 296 retval = -ERESTARTSYS;
297 break; 297 break;
298 } 298 }
299 tty_unlock(tty); 299 tty_unlock();
300 schedule(); 300 schedule();
301 tty_lock(tty); 301 tty_lock();
302 } 302 }
303 finish_wait(&port->open_wait, &wait); 303 finish_wait(&port->open_wait, &wait);
304 304
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index a290be51a1f4..0217f7415ef5 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -2210,7 +2210,7 @@ config FB_XILINX
2210 2210
2211config FB_COBALT 2211config FB_COBALT
2212 tristate "Cobalt server LCD frame buffer support" 2212 tristate "Cobalt server LCD frame buffer support"
2213 depends on FB && MIPS_COBALT 2213 depends on FB && (MIPS_COBALT || MIPS_SEAD3)
2214 2214
2215config FB_SH7760 2215config FB_SH7760
2216 bool "SH7760/SH7763/SH7720/SH7721 LCDC support" 2216 bool "SH7760/SH7763/SH7720/SH7721 LCDC support"
@@ -2382,6 +2382,39 @@ config FB_BROADSHEET
2382 and could also have been called by other names when coupled with 2382 and could also have been called by other names when coupled with
2383 a bridge adapter. 2383 a bridge adapter.
2384 2384
2385config FB_AUO_K190X
2386 tristate "AUO-K190X EPD controller support"
2387 depends on FB
2388 select FB_SYS_FILLRECT
2389 select FB_SYS_COPYAREA
2390 select FB_SYS_IMAGEBLIT
2391 select FB_SYS_FOPS
2392 select FB_DEFERRED_IO
2393 help
2394 Provides support for epaper controllers from the K190X series
2395 of AUO. These controllers can be used to drive epaper displays
2396 from Sipix.
2397
2398 This option enables the common support, shared by the individual
2399 controller drivers. You will also have to enable the driver
2400 for the controller type used in your device.
2401
2402config FB_AUO_K1900
2403 tristate "AUO-K1900 EPD controller support"
2404 depends on FB && FB_AUO_K190X
2405 help
2406 This driver implements support for the AUO K1900 epd-controller.
2407 This controller can drive Sipix epaper displays but can only do
2408 serial updates, reducing the number of possible frames per second.
2409
2410config FB_AUO_K1901
2411 tristate "AUO-K1901 EPD controller support"
2412 depends on FB && FB_AUO_K190X
2413 help
2414 This driver implements support for the AUO K1901 epd-controller.
2415 This controller can drive Sipix epaper displays and supports
2416 concurrent updates, making higher frames per second possible.
2417
2385config FB_JZ4740 2418config FB_JZ4740
2386 tristate "JZ4740 LCD framebuffer support" 2419 tristate "JZ4740 LCD framebuffer support"
2387 depends on FB && MACH_JZ4740 2420 depends on FB && MACH_JZ4740
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 9356add945b3..ee8dafb69e36 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -118,6 +118,9 @@ obj-$(CONFIG_FB_PMAGB_B) += pmagb-b-fb.o
118obj-$(CONFIG_FB_MAXINE) += maxinefb.o 118obj-$(CONFIG_FB_MAXINE) += maxinefb.o
119obj-$(CONFIG_FB_METRONOME) += metronomefb.o 119obj-$(CONFIG_FB_METRONOME) += metronomefb.o
120obj-$(CONFIG_FB_BROADSHEET) += broadsheetfb.o 120obj-$(CONFIG_FB_BROADSHEET) += broadsheetfb.o
121obj-$(CONFIG_FB_AUO_K190X) += auo_k190x.o
122obj-$(CONFIG_FB_AUO_K1900) += auo_k1900fb.o
123obj-$(CONFIG_FB_AUO_K1901) += auo_k1901fb.o
121obj-$(CONFIG_FB_S1D13XXX) += s1d13xxxfb.o 124obj-$(CONFIG_FB_S1D13XXX) += s1d13xxxfb.o
122obj-$(CONFIG_FB_SH7760) += sh7760fb.o 125obj-$(CONFIG_FB_SH7760) += sh7760fb.o
123obj-$(CONFIG_FB_IMX) += imxfb.o 126obj-$(CONFIG_FB_IMX) += imxfb.o
diff --git a/drivers/video/auo_k1900fb.c b/drivers/video/auo_k1900fb.c
new file mode 100644
index 000000000000..c36cf961dcb2
--- /dev/null
+++ b/drivers/video/auo_k1900fb.c
@@ -0,0 +1,198 @@
1/*
2 * auok190xfb.c -- FB driver for AUO-K1900 controllers
3 *
4 * Copyright (C) 2011, 2012 Heiko Stuebner <heiko@sntech.de>
5 *
6 * based on broadsheetfb.c
7 *
8 * Copyright (C) 2008, Jaya Kumar
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
15 *
16 * This driver is written to be used with the AUO-K1900 display controller.
17 *
18 * It is intended to be architecture independent. A board specific driver
19 * must be used to perform all the physical IO interactions.
20 *
21 * The controller supports different update modes:
22 * mode0+1 16 step gray (4bit)
23 * mode2 4 step gray (2bit) - FIXME: add strange refresh
24 * mode3 2 step gray (1bit) - FIXME: add strange refresh
25 * mode4 handwriting mode (strange behaviour)
26 * mode5 automatic selection of update mode
27 */
28
29#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/errno.h>
32#include <linux/string.h>
33#include <linux/mm.h>
34#include <linux/slab.h>
35#include <linux/delay.h>
36#include <linux/interrupt.h>
37#include <linux/fb.h>
38#include <linux/init.h>
39#include <linux/platform_device.h>
40#include <linux/list.h>
41#include <linux/firmware.h>
42#include <linux/gpio.h>
43#include <linux/pm_runtime.h>
44
45#include <video/auo_k190xfb.h>
46
47#include "auo_k190x.h"
48
49/*
50 * AUO-K1900 specific commands
51 */
52
53#define AUOK1900_CMD_PARTIALDISP 0x1001
54#define AUOK1900_CMD_ROTATION 0x1006
55#define AUOK1900_CMD_LUT_STOP 0x1009
56
57#define AUOK1900_INIT_TEMP_AVERAGE (1 << 13)
58#define AUOK1900_INIT_ROTATE(_x) ((_x & 0x3) << 10)
59#define AUOK1900_INIT_RESOLUTION(_res) ((_res & 0x7) << 2)
60
61static void auok1900_init(struct auok190xfb_par *par)
62{
63 struct auok190x_board *board = par->board;
64 u16 init_param = 0;
65
66 init_param |= AUOK1900_INIT_TEMP_AVERAGE;
67 init_param |= AUOK1900_INIT_ROTATE(par->rotation);
68 init_param |= AUOK190X_INIT_INVERSE_WHITE;
69 init_param |= AUOK190X_INIT_FORMAT0;
70 init_param |= AUOK1900_INIT_RESOLUTION(par->resolution);
71 init_param |= AUOK190X_INIT_SHIFT_RIGHT;
72
73 auok190x_send_cmdargs(par, AUOK190X_CMD_INIT, 1, &init_param);
74
75 /* let the controller finish */
76 board->wait_for_rdy(par);
77}
78
79static void auok1900_update_region(struct auok190xfb_par *par, int mode,
80 u16 y1, u16 y2)
81{
82 struct device *dev = par->info->device;
83 unsigned char *buf = (unsigned char *)par->info->screen_base;
84 int xres = par->info->var.xres;
85 u16 args[4];
86
87 pm_runtime_get_sync(dev);
88
89 mutex_lock(&(par->io_lock));
90
91 /* y1 and y2 must be a multiple of 2 so drop the lowest bit */
92 y1 &= 0xfffe;
93 y2 &= 0xfffe;
94
95 dev_dbg(dev, "update (x,y,w,h,mode)=(%d,%d,%d,%d,%d)\n",
96 1, y1+1, xres, y2-y1, mode);
97
98 /* to FIX handle different partial update modes */
99 args[0] = mode | 1;
100 args[1] = y1 + 1;
101 args[2] = xres;
102 args[3] = y2 - y1;
103 buf += y1 * xres;
104 auok190x_send_cmdargs_pixels(par, AUOK1900_CMD_PARTIALDISP, 4, args,
105 ((y2 - y1) * xres)/2, (u16 *) buf);
106 auok190x_send_command(par, AUOK190X_CMD_DATA_STOP);
107
108 par->update_cnt++;
109
110 mutex_unlock(&(par->io_lock));
111
112 pm_runtime_mark_last_busy(dev);
113 pm_runtime_put_autosuspend(dev);
114}
115
116static void auok1900fb_dpy_update_pages(struct auok190xfb_par *par,
117 u16 y1, u16 y2)
118{
119 int mode;
120
121 if (par->update_mode < 0) {
122 mode = AUOK190X_UPDATE_MODE(1);
123 par->last_mode = -1;
124 } else {
125 mode = AUOK190X_UPDATE_MODE(par->update_mode);
126 par->last_mode = par->update_mode;
127 }
128
129 if (par->flash)
130 mode |= AUOK190X_UPDATE_NONFLASH;
131
132 auok1900_update_region(par, mode, y1, y2);
133}
134
135static void auok1900fb_dpy_update(struct auok190xfb_par *par)
136{
137 int mode;
138
139 if (par->update_mode < 0) {
140 mode = AUOK190X_UPDATE_MODE(0);
141 par->last_mode = -1;
142 } else {
143 mode = AUOK190X_UPDATE_MODE(par->update_mode);
144 par->last_mode = par->update_mode;
145 }
146
147 if (par->flash)
148 mode |= AUOK190X_UPDATE_NONFLASH;
149
150 auok1900_update_region(par, mode, 0, par->info->var.yres);
151 par->update_cnt = 0;
152}
153
154static bool auok1900fb_need_refresh(struct auok190xfb_par *par)
155{
156 return (par->update_cnt > 10);
157}
158
159static int __devinit auok1900fb_probe(struct platform_device *pdev)
160{
161 struct auok190x_init_data init;
162 struct auok190x_board *board;
163
164 /* pick up board specific routines */
165 board = pdev->dev.platform_data;
166 if (!board)
167 return -EINVAL;
168
169 /* fill temporary init struct for common init */
170 init.id = "auo_k1900fb";
171 init.board = board;
172 init.update_partial = auok1900fb_dpy_update_pages;
173 init.update_all = auok1900fb_dpy_update;
174 init.need_refresh = auok1900fb_need_refresh;
175 init.init = auok1900_init;
176
177 return auok190x_common_probe(pdev, &init);
178}
179
180static int __devexit auok1900fb_remove(struct platform_device *pdev)
181{
182 return auok190x_common_remove(pdev);
183}
184
185static struct platform_driver auok1900fb_driver = {
186 .probe = auok1900fb_probe,
187 .remove = __devexit_p(auok1900fb_remove),
188 .driver = {
189 .owner = THIS_MODULE,
190 .name = "auo_k1900fb",
191 .pm = &auok190x_pm,
192 },
193};
194module_platform_driver(auok1900fb_driver);
195
196MODULE_DESCRIPTION("framebuffer driver for the AUO-K1900 EPD controller");
197MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
198MODULE_LICENSE("GPL");
diff --git a/drivers/video/auo_k1901fb.c b/drivers/video/auo_k1901fb.c
new file mode 100644
index 000000000000..1c054c18616e
--- /dev/null
+++ b/drivers/video/auo_k1901fb.c
@@ -0,0 +1,251 @@
1/*
2 * auok190xfb.c -- FB driver for AUO-K1901 controllers
3 *
4 * Copyright (C) 2011, 2012 Heiko Stuebner <heiko@sntech.de>
5 *
6 * based on broadsheetfb.c
7 *
8 * Copyright (C) 2008, Jaya Kumar
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
15 *
16 * This driver is written to be used with the AUO-K1901 display controller.
17 *
18 * It is intended to be architecture independent. A board specific driver
19 * must be used to perform all the physical IO interactions.
20 *
21 * The controller supports different update modes:
22 * mode0+1 16 step gray (4bit)
23 * mode2+3 4 step gray (2bit)
24 * mode4+5 2 step gray (1bit)
25 * - mode4 is described as "without LUT"
26 * mode7 automatic selection of update mode
27 *
28 * The most interesting difference to the K1900 is the ability to do screen
29 * updates in an asynchronous fashion. Where the K1900 needs to wait for the
30 * current update to complete, the K1901 can process later updates already.
31 */
32
33#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/errno.h>
36#include <linux/string.h>
37#include <linux/mm.h>
38#include <linux/slab.h>
39#include <linux/delay.h>
40#include <linux/interrupt.h>
41#include <linux/fb.h>
42#include <linux/init.h>
43#include <linux/platform_device.h>
44#include <linux/list.h>
45#include <linux/firmware.h>
46#include <linux/gpio.h>
47#include <linux/pm_runtime.h>
48
49#include <video/auo_k190xfb.h>
50
51#include "auo_k190x.h"
52
53/*
54 * AUO-K1901 specific commands
55 */
56
57#define AUOK1901_CMD_LUT_INTERFACE 0x0005
58#define AUOK1901_CMD_DMA_START 0x1001
59#define AUOK1901_CMD_CURSOR_START 0x1007
60#define AUOK1901_CMD_CURSOR_STOP AUOK190X_CMD_DATA_STOP
61#define AUOK1901_CMD_DDMA_START 0x1009
62
63#define AUOK1901_INIT_GATE_PULSE_LOW (0 << 14)
64#define AUOK1901_INIT_GATE_PULSE_HIGH (1 << 14)
65#define AUOK1901_INIT_SINGLE_GATE (0 << 13)
66#define AUOK1901_INIT_DOUBLE_GATE (1 << 13)
67
68/* Bits to pixels
69 * Mode 15-12 11-8 7-4 3-0
70 * format2 2 T 1 T
71 * format3 1 T 2 T
72 * format4 T 2 T 1
73 * format5 T 1 T 2
74 *
75 * halftone modes:
76 * format6 2 2 1 1
77 * format7 1 1 2 2
78 */
79#define AUOK1901_INIT_FORMAT2 (1 << 7)
80#define AUOK1901_INIT_FORMAT3 ((1 << 7) | (1 << 6))
81#define AUOK1901_INIT_FORMAT4 (1 << 8)
82#define AUOK1901_INIT_FORMAT5 ((1 << 8) | (1 << 6))
83#define AUOK1901_INIT_FORMAT6 ((1 << 8) | (1 << 7))
84#define AUOK1901_INIT_FORMAT7 ((1 << 8) | (1 << 7) | (1 << 6))
85
86/* res[4] to bit 10
87 * res[3-0] to bits 5-2
88 */
89#define AUOK1901_INIT_RESOLUTION(_res) (((_res & (1 << 4)) << 6) \
90 | ((_res & 0xf) << 2))
91
92/*
93 * portrait / landscape orientation in AUOK1901_CMD_DMA_START
94 */
95#define AUOK1901_DMA_ROTATE90(_rot) ((_rot & 1) << 13)
96
97/*
98 * equivalent to 1 << 11, needs the ~ to have same rotation like K1900
99 */
100#define AUOK1901_DDMA_ROTATE180(_rot) ((~_rot & 2) << 10)
101
102static void auok1901_init(struct auok190xfb_par *par)
103{
104 struct auok190x_board *board = par->board;
105 u16 init_param = 0;
106
107 init_param |= AUOK190X_INIT_INVERSE_WHITE;
108 init_param |= AUOK190X_INIT_FORMAT0;
109 init_param |= AUOK1901_INIT_RESOLUTION(par->resolution);
110 init_param |= AUOK190X_INIT_SHIFT_LEFT;
111
112 auok190x_send_cmdargs(par, AUOK190X_CMD_INIT, 1, &init_param);
113
114 /* let the controller finish */
115 board->wait_for_rdy(par);
116}
117
118static void auok1901_update_region(struct auok190xfb_par *par, int mode,
119 u16 y1, u16 y2)
120{
121 struct device *dev = par->info->device;
122 unsigned char *buf = (unsigned char *)par->info->screen_base;
123 int xres = par->info->var.xres;
124 u16 args[5];
125
126 pm_runtime_get_sync(dev);
127
128 mutex_lock(&(par->io_lock));
129
130 /* y1 and y2 must be a multiple of 2 so drop the lowest bit */
131 y1 &= 0xfffe;
132 y2 &= 0xfffe;
133
134 dev_dbg(dev, "update (x,y,w,h,mode)=(%d,%d,%d,%d,%d)\n",
135 1, y1+1, xres, y2-y1, mode);
136
137 /* K1901: first transfer the region data */
138 args[0] = AUOK1901_DMA_ROTATE90(par->rotation) | 1;
139 args[1] = y1 + 1;
140 args[2] = xres;
141 args[3] = y2 - y1;
142 buf += y1 * xres;
143 auok190x_send_cmdargs_pixels_nowait(par, AUOK1901_CMD_DMA_START, 4,
144 args, ((y2 - y1) * xres)/2,
145 (u16 *) buf);
146 auok190x_send_command_nowait(par, AUOK190X_CMD_DATA_STOP);
147
148 /* K1901: second tell the controller to update the region with mode */
149 args[0] = mode | AUOK1901_DDMA_ROTATE180(par->rotation);
150 args[1] = 1;
151 args[2] = y1 + 1;
152 args[3] = xres;
153 args[4] = y2 - y1;
154 auok190x_send_cmdargs_nowait(par, AUOK1901_CMD_DDMA_START, 5, args);
155
156 par->update_cnt++;
157
158 mutex_unlock(&(par->io_lock));
159
160 pm_runtime_mark_last_busy(dev);
161 pm_runtime_put_autosuspend(dev);
162}
163
164static void auok1901fb_dpy_update_pages(struct auok190xfb_par *par,
165 u16 y1, u16 y2)
166{
167 int mode;
168
169 if (par->update_mode < 0) {
170 mode = AUOK190X_UPDATE_MODE(1);
171 par->last_mode = -1;
172 } else {
173 mode = AUOK190X_UPDATE_MODE(par->update_mode);
174 par->last_mode = par->update_mode;
175 }
176
177 if (par->flash)
178 mode |= AUOK190X_UPDATE_NONFLASH;
179
180 auok1901_update_region(par, mode, y1, y2);
181}
182
183static void auok1901fb_dpy_update(struct auok190xfb_par *par)
184{
185 int mode;
186
187 /* When doing full updates, wait for the controller to be ready
188 * This will hopefully catch some hangs of the K1901
189 */
190 par->board->wait_for_rdy(par);
191
192 if (par->update_mode < 0) {
193 mode = AUOK190X_UPDATE_MODE(0);
194 par->last_mode = -1;
195 } else {
196 mode = AUOK190X_UPDATE_MODE(par->update_mode);
197 par->last_mode = par->update_mode;
198 }
199
200 if (par->flash)
201 mode |= AUOK190X_UPDATE_NONFLASH;
202
203 auok1901_update_region(par, mode, 0, par->info->var.yres);
204 par->update_cnt = 0;
205}
206
207static bool auok1901fb_need_refresh(struct auok190xfb_par *par)
208{
209 return (par->update_cnt > 10);
210}
211
212static int __devinit auok1901fb_probe(struct platform_device *pdev)
213{
214 struct auok190x_init_data init;
215 struct auok190x_board *board;
216
217 /* pick up board specific routines */
218 board = pdev->dev.platform_data;
219 if (!board)
220 return -EINVAL;
221
222 /* fill temporary init struct for common init */
223 init.id = "auo_k1901fb";
224 init.board = board;
225 init.update_partial = auok1901fb_dpy_update_pages;
226 init.update_all = auok1901fb_dpy_update;
227 init.need_refresh = auok1901fb_need_refresh;
228 init.init = auok1901_init;
229
230 return auok190x_common_probe(pdev, &init);
231}
232
233static int __devexit auok1901fb_remove(struct platform_device *pdev)
234{
235 return auok190x_common_remove(pdev);
236}
237
238static struct platform_driver auok1901fb_driver = {
239 .probe = auok1901fb_probe,
240 .remove = __devexit_p(auok1901fb_remove),
241 .driver = {
242 .owner = THIS_MODULE,
243 .name = "auo_k1901fb",
244 .pm = &auok190x_pm,
245 },
246};
247module_platform_driver(auok1901fb_driver);
248
249MODULE_DESCRIPTION("framebuffer driver for the AUO-K1901 EPD controller");
250MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
251MODULE_LICENSE("GPL");
diff --git a/drivers/video/auo_k190x.c b/drivers/video/auo_k190x.c
new file mode 100644
index 000000000000..77da6a2f43dc
--- /dev/null
+++ b/drivers/video/auo_k190x.c
@@ -0,0 +1,1046 @@
1/*
2 * Common code for AUO-K190X framebuffer drivers
3 *
4 * Copyright (C) 2012 Heiko Stuebner <heiko@sntech.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/gpio.h>
14#include <linux/pm_runtime.h>
15#include <linux/fb.h>
16#include <linux/delay.h>
17#include <linux/uaccess.h>
18#include <linux/vmalloc.h>
19#include <linux/regulator/consumer.h>
20
21#include <video/auo_k190xfb.h>
22
23#include "auo_k190x.h"
24
25struct panel_info {
26 int w;
27 int h;
28};
29
30/* table of panel specific parameters to be indexed into by the board drivers */
31static struct panel_info panel_table[] = {
32 /* standard 6" */
33 [AUOK190X_RESOLUTION_800_600] = {
34 .w = 800,
35 .h = 600,
36 },
37 /* standard 9" */
38 [AUOK190X_RESOLUTION_1024_768] = {
39 .w = 1024,
40 .h = 768,
41 },
42};
43
44/*
45 * private I80 interface to the board driver
46 */
47
48static void auok190x_issue_data(struct auok190xfb_par *par, u16 data)
49{
50 par->board->set_ctl(par, AUOK190X_I80_WR, 0);
51 par->board->set_hdb(par, data);
52 par->board->set_ctl(par, AUOK190X_I80_WR, 1);
53}
54
55static void auok190x_issue_cmd(struct auok190xfb_par *par, u16 data)
56{
57 par->board->set_ctl(par, AUOK190X_I80_DC, 0);
58 auok190x_issue_data(par, data);
59 par->board->set_ctl(par, AUOK190X_I80_DC, 1);
60}
61
62static int auok190x_issue_pixels(struct auok190xfb_par *par, int size,
63 u16 *data)
64{
65 struct device *dev = par->info->device;
66 int i;
67 u16 tmp;
68
69 if (size & 3) {
70 dev_err(dev, "issue_pixels: size %d must be a multiple of 4\n",
71 size);
72 return -EINVAL;
73 }
74
75 for (i = 0; i < (size >> 1); i++) {
76 par->board->set_ctl(par, AUOK190X_I80_WR, 0);
77
78 /* simple reduction of 8bit staticgray to 4bit gray
79 * combines 4 * 4bit pixel values into a 16bit value
80 */
81 tmp = (data[2*i] & 0xF0) >> 4;
82 tmp |= (data[2*i] & 0xF000) >> 8;
83 tmp |= (data[2*i+1] & 0xF0) << 4;
84 tmp |= (data[2*i+1] & 0xF000);
85
86 par->board->set_hdb(par, tmp);
87 par->board->set_ctl(par, AUOK190X_I80_WR, 1);
88 }
89
90 return 0;
91}
92
93static u16 auok190x_read_data(struct auok190xfb_par *par)
94{
95 u16 data;
96
97 par->board->set_ctl(par, AUOK190X_I80_OE, 0);
98 data = par->board->get_hdb(par);
99 par->board->set_ctl(par, AUOK190X_I80_OE, 1);
100
101 return data;
102}
103
104/*
105 * Command interface for the controller drivers
106 */
107
108void auok190x_send_command_nowait(struct auok190xfb_par *par, u16 data)
109{
110 par->board->set_ctl(par, AUOK190X_I80_CS, 0);
111 auok190x_issue_cmd(par, data);
112 par->board->set_ctl(par, AUOK190X_I80_CS, 1);
113}
114EXPORT_SYMBOL_GPL(auok190x_send_command_nowait);
115
116void auok190x_send_cmdargs_nowait(struct auok190xfb_par *par, u16 cmd,
117 int argc, u16 *argv)
118{
119 int i;
120
121 par->board->set_ctl(par, AUOK190X_I80_CS, 0);
122 auok190x_issue_cmd(par, cmd);
123
124 for (i = 0; i < argc; i++)
125 auok190x_issue_data(par, argv[i]);
126 par->board->set_ctl(par, AUOK190X_I80_CS, 1);
127}
128EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_nowait);
129
130int auok190x_send_command(struct auok190xfb_par *par, u16 data)
131{
132 int ret;
133
134 ret = par->board->wait_for_rdy(par);
135 if (ret)
136 return ret;
137
138 auok190x_send_command_nowait(par, data);
139 return 0;
140}
141EXPORT_SYMBOL_GPL(auok190x_send_command);
142
143int auok190x_send_cmdargs(struct auok190xfb_par *par, u16 cmd,
144 int argc, u16 *argv)
145{
146 int ret;
147
148 ret = par->board->wait_for_rdy(par);
149 if (ret)
150 return ret;
151
152 auok190x_send_cmdargs_nowait(par, cmd, argc, argv);
153 return 0;
154}
155EXPORT_SYMBOL_GPL(auok190x_send_cmdargs);
156
157int auok190x_read_cmdargs(struct auok190xfb_par *par, u16 cmd,
158 int argc, u16 *argv)
159{
160 int i, ret;
161
162 ret = par->board->wait_for_rdy(par);
163 if (ret)
164 return ret;
165
166 par->board->set_ctl(par, AUOK190X_I80_CS, 0);
167 auok190x_issue_cmd(par, cmd);
168
169 for (i = 0; i < argc; i++)
170 argv[i] = auok190x_read_data(par);
171 par->board->set_ctl(par, AUOK190X_I80_CS, 1);
172
173 return 0;
174}
175EXPORT_SYMBOL_GPL(auok190x_read_cmdargs);
176
177void auok190x_send_cmdargs_pixels_nowait(struct auok190xfb_par *par, u16 cmd,
178 int argc, u16 *argv, int size, u16 *data)
179{
180 int i;
181
182 par->board->set_ctl(par, AUOK190X_I80_CS, 0);
183
184 auok190x_issue_cmd(par, cmd);
185
186 for (i = 0; i < argc; i++)
187 auok190x_issue_data(par, argv[i]);
188
189 auok190x_issue_pixels(par, size, data);
190
191 par->board->set_ctl(par, AUOK190X_I80_CS, 1);
192}
193EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_pixels_nowait);
194
195int auok190x_send_cmdargs_pixels(struct auok190xfb_par *par, u16 cmd,
196 int argc, u16 *argv, int size, u16 *data)
197{
198 int ret;
199
200 ret = par->board->wait_for_rdy(par);
201 if (ret)
202 return ret;
203
204 auok190x_send_cmdargs_pixels_nowait(par, cmd, argc, argv, size, data);
205
206 return 0;
207}
208EXPORT_SYMBOL_GPL(auok190x_send_cmdargs_pixels);
209
210/*
211 * fbdefio callbacks - common on both controllers.
212 */
213
214static void auok190xfb_dpy_first_io(struct fb_info *info)
215{
216 /* tell runtime-pm that we wish to use the device in a short time */
217 pm_runtime_get(info->device);
218}
219
220/* this is called back from the deferred io workqueue */
221static void auok190xfb_dpy_deferred_io(struct fb_info *info,
222 struct list_head *pagelist)
223{
224 struct fb_deferred_io *fbdefio = info->fbdefio;
225 struct auok190xfb_par *par = info->par;
226 u16 yres = info->var.yres;
227 u16 xres = info->var.xres;
228 u16 y1 = 0, h = 0;
229 int prev_index = -1;
230 struct page *cur;
231 int h_inc;
232 int threshold;
233
234 if (!list_empty(pagelist))
235 /* the device resume should've been requested through first_io,
236 * if the resume did not finish until now, wait for it.
237 */
238 pm_runtime_barrier(info->device);
239 else
240 /* We reached this via the fsync or some other way.
241 * In either case the first_io function did not run,
242 * so we runtime_resume the device here synchronously.
243 */
244 pm_runtime_get_sync(info->device);
245
246 /* Do a full screen update every n updates to prevent
247 * excessive darkening of the Sipix display.
248 * If we do this, there is no need to walk the pages.
249 */
250 if (par->need_refresh(par)) {
251 par->update_all(par);
252 goto out;
253 }
254
255 /* height increment is fixed per page */
256 h_inc = DIV_ROUND_UP(PAGE_SIZE , xres);
257
258 /* calculate number of pages from pixel height */
259 threshold = par->consecutive_threshold / h_inc;
260 if (threshold < 1)
261 threshold = 1;
262
263 /* walk the written page list and swizzle the data */
264 list_for_each_entry(cur, &fbdefio->pagelist, lru) {
265 if (prev_index < 0) {
266 /* just starting so assign first page */
267 y1 = (cur->index << PAGE_SHIFT) / xres;
268 h = h_inc;
269 } else if ((cur->index - prev_index) <= threshold) {
270 /* page is within our threshold for single updates */
271 h += h_inc * (cur->index - prev_index);
272 } else {
273 /* page not consecutive, issue previous update first */
274 par->update_partial(par, y1, y1 + h);
275
276 /* start over with our non consecutive page */
277 y1 = (cur->index << PAGE_SHIFT) / xres;
278 h = h_inc;
279 }
280 prev_index = cur->index;
281 }
282
283 /* if we still have any pages to update we do so now */
284 if (h >= yres)
285 /* its a full screen update, just do it */
286 par->update_all(par);
287 else
288 par->update_partial(par, y1, min((u16) (y1 + h), yres));
289
290out:
291 pm_runtime_mark_last_busy(info->device);
292 pm_runtime_put_autosuspend(info->device);
293}
294
295/*
296 * framebuffer operations
297 */
298
299/*
300 * this is the slow path from userspace. they can seek and write to
301 * the fb. it's inefficient to do anything less than a full screen draw
302 */
303static ssize_t auok190xfb_write(struct fb_info *info, const char __user *buf,
304 size_t count, loff_t *ppos)
305{
306 struct auok190xfb_par *par = info->par;
307 unsigned long p = *ppos;
308 void *dst;
309 int err = 0;
310 unsigned long total_size;
311
312 if (info->state != FBINFO_STATE_RUNNING)
313 return -EPERM;
314
315 total_size = info->fix.smem_len;
316
317 if (p > total_size)
318 return -EFBIG;
319
320 if (count > total_size) {
321 err = -EFBIG;
322 count = total_size;
323 }
324
325 if (count + p > total_size) {
326 if (!err)
327 err = -ENOSPC;
328
329 count = total_size - p;
330 }
331
332 dst = (void *)(info->screen_base + p);
333
334 if (copy_from_user(dst, buf, count))
335 err = -EFAULT;
336
337 if (!err)
338 *ppos += count;
339
340 par->update_all(par);
341
342 return (err) ? err : count;
343}
344
345static void auok190xfb_fillrect(struct fb_info *info,
346 const struct fb_fillrect *rect)
347{
348 struct auok190xfb_par *par = info->par;
349
350 sys_fillrect(info, rect);
351
352 par->update_all(par);
353}
354
355static void auok190xfb_copyarea(struct fb_info *info,
356 const struct fb_copyarea *area)
357{
358 struct auok190xfb_par *par = info->par;
359
360 sys_copyarea(info, area);
361
362 par->update_all(par);
363}
364
365static void auok190xfb_imageblit(struct fb_info *info,
366 const struct fb_image *image)
367{
368 struct auok190xfb_par *par = info->par;
369
370 sys_imageblit(info, image);
371
372 par->update_all(par);
373}
374
375static int auok190xfb_check_var(struct fb_var_screeninfo *var,
376 struct fb_info *info)
377{
378 if (info->var.xres != var->xres || info->var.yres != var->yres ||
379 info->var.xres_virtual != var->xres_virtual ||
380 info->var.yres_virtual != var->yres_virtual) {
381 pr_info("%s: Resolution not supported: X%u x Y%u\n",
382 __func__, var->xres, var->yres);
383 return -EINVAL;
384 }
385
386 /*
387 * Memory limit
388 */
389
390 if ((info->fix.line_length * var->yres_virtual) > info->fix.smem_len) {
391 pr_info("%s: Memory Limit requested yres_virtual = %u\n",
392 __func__, var->yres_virtual);
393 return -ENOMEM;
394 }
395
396 return 0;
397}
398
399static struct fb_ops auok190xfb_ops = {
400 .owner = THIS_MODULE,
401 .fb_read = fb_sys_read,
402 .fb_write = auok190xfb_write,
403 .fb_fillrect = auok190xfb_fillrect,
404 .fb_copyarea = auok190xfb_copyarea,
405 .fb_imageblit = auok190xfb_imageblit,
406 .fb_check_var = auok190xfb_check_var,
407};
408
409/*
410 * Controller-functions common to both K1900 and K1901
411 */
412
413static int auok190x_read_temperature(struct auok190xfb_par *par)
414{
415 struct device *dev = par->info->device;
416 u16 data[4];
417 int temp;
418
419 pm_runtime_get_sync(dev);
420
421 mutex_lock(&(par->io_lock));
422
423 auok190x_read_cmdargs(par, AUOK190X_CMD_READ_VERSION, 4, data);
424
425 mutex_unlock(&(par->io_lock));
426
427 pm_runtime_mark_last_busy(dev);
428 pm_runtime_put_autosuspend(dev);
429
430 /* sanitize and split of half-degrees for now */
431 temp = ((data[0] & AUOK190X_VERSION_TEMP_MASK) >> 1);
432
433 /* handle positive and negative temperatures */
434 if (temp >= 201)
435 return (255 - temp + 1) * (-1);
436 else
437 return temp;
438}
439
440static void auok190x_identify(struct auok190xfb_par *par)
441{
442 struct device *dev = par->info->device;
443 u16 data[4];
444
445 pm_runtime_get_sync(dev);
446
447 mutex_lock(&(par->io_lock));
448
449 auok190x_read_cmdargs(par, AUOK190X_CMD_READ_VERSION, 4, data);
450
451 mutex_unlock(&(par->io_lock));
452
453 par->epd_type = data[1] & AUOK190X_VERSION_TEMP_MASK;
454
455 par->panel_size_int = AUOK190X_VERSION_SIZE_INT(data[2]);
456 par->panel_size_float = AUOK190X_VERSION_SIZE_FLOAT(data[2]);
457 par->panel_model = AUOK190X_VERSION_MODEL(data[2]);
458
459 par->tcon_version = AUOK190X_VERSION_TCON(data[3]);
460 par->lut_version = AUOK190X_VERSION_LUT(data[3]);
461
462 dev_dbg(dev, "panel %d.%din, model 0x%x, EPD 0x%x TCON-rev 0x%x, LUT-rev 0x%x",
463 par->panel_size_int, par->panel_size_float, par->panel_model,
464 par->epd_type, par->tcon_version, par->lut_version);
465
466 pm_runtime_mark_last_busy(dev);
467 pm_runtime_put_autosuspend(dev);
468}
469
470/*
471 * Sysfs functions
472 */
473
474static ssize_t update_mode_show(struct device *dev,
475 struct device_attribute *attr, char *buf)
476{
477 struct fb_info *info = dev_get_drvdata(dev);
478 struct auok190xfb_par *par = info->par;
479
480 return sprintf(buf, "%d\n", par->update_mode);
481}
482
483static ssize_t update_mode_store(struct device *dev,
484 struct device_attribute *attr,
485 const char *buf, size_t count)
486{
487 struct fb_info *info = dev_get_drvdata(dev);
488 struct auok190xfb_par *par = info->par;
489 int mode, ret;
490
491 ret = kstrtoint(buf, 10, &mode);
492 if (ret)
493 return ret;
494
495 par->update_mode = mode;
496
497 /* if we enter a better mode, do a full update */
498 if (par->last_mode > 1 && mode < par->last_mode)
499 par->update_all(par);
500
501 return count;
502}
503
504static ssize_t flash_show(struct device *dev, struct device_attribute *attr,
505 char *buf)
506{
507 struct fb_info *info = dev_get_drvdata(dev);
508 struct auok190xfb_par *par = info->par;
509
510 return sprintf(buf, "%d\n", par->flash);
511}
512
513static ssize_t flash_store(struct device *dev, struct device_attribute *attr,
514 const char *buf, size_t count)
515{
516 struct fb_info *info = dev_get_drvdata(dev);
517 struct auok190xfb_par *par = info->par;
518 int flash, ret;
519
520 ret = kstrtoint(buf, 10, &flash);
521 if (ret)
522 return ret;
523
524 if (flash > 0)
525 par->flash = 1;
526 else
527 par->flash = 0;
528
529 return count;
530}
531
532static ssize_t temp_show(struct device *dev, struct device_attribute *attr,
533 char *buf)
534{
535 struct fb_info *info = dev_get_drvdata(dev);
536 struct auok190xfb_par *par = info->par;
537 int temp;
538
539 temp = auok190x_read_temperature(par);
540 return sprintf(buf, "%d\n", temp);
541}
542
543static DEVICE_ATTR(update_mode, 0644, update_mode_show, update_mode_store);
544static DEVICE_ATTR(flash, 0644, flash_show, flash_store);
545static DEVICE_ATTR(temp, 0644, temp_show, NULL);
546
547static struct attribute *auok190x_attributes[] = {
548 &dev_attr_update_mode.attr,
549 &dev_attr_flash.attr,
550 &dev_attr_temp.attr,
551 NULL
552};
553
554static const struct attribute_group auok190x_attr_group = {
555 .attrs = auok190x_attributes,
556};
557
558static int auok190x_power(struct auok190xfb_par *par, bool on)
559{
560 struct auok190x_board *board = par->board;
561 int ret;
562
563 if (on) {
564 /* We should maintain POWER up for at least 80ms before set
565 * RST_N and SLP_N to high (TCON spec 20100803_v35 p59)
566 */
567 ret = regulator_enable(par->regulator);
568 if (ret)
569 return ret;
570
571 msleep(200);
572 gpio_set_value(board->gpio_nrst, 1);
573 gpio_set_value(board->gpio_nsleep, 1);
574 msleep(200);
575 } else {
576 regulator_disable(par->regulator);
577 gpio_set_value(board->gpio_nrst, 0);
578 gpio_set_value(board->gpio_nsleep, 0);
579 }
580
581 return 0;
582}
583
584/*
585 * Recovery - powercycle the controller
586 */
587
588static void auok190x_recover(struct auok190xfb_par *par)
589{
590 auok190x_power(par, 0);
591 msleep(100);
592 auok190x_power(par, 1);
593
594 par->init(par);
595
596 /* wait for init to complete */
597 par->board->wait_for_rdy(par);
598}
599
600/*
601 * Power-management
602 */
603
604#ifdef CONFIG_PM
605static int auok190x_runtime_suspend(struct device *dev)
606{
607 struct platform_device *pdev = to_platform_device(dev);
608 struct fb_info *info = platform_get_drvdata(pdev);
609 struct auok190xfb_par *par = info->par;
610 struct auok190x_board *board = par->board;
611 u16 standby_param;
612
613 /* take and keep the lock until we are resumed, as the controller
614 * will never reach the non-busy state when in standby mode
615 */
616 mutex_lock(&(par->io_lock));
617
618 if (par->standby) {
619 dev_warn(dev, "already in standby, runtime-pm pairing mismatch\n");
620 mutex_unlock(&(par->io_lock));
621 return 0;
622 }
623
624 /* according to runtime_pm.txt runtime_suspend only means, that the
625 * device will not process data and will not communicate with the CPU
626 * As we hold the lock, this stays true even without standby
627 */
628 if (board->quirks & AUOK190X_QUIRK_STANDBYBROKEN) {
629 dev_dbg(dev, "runtime suspend without standby\n");
630 goto finish;
631 } else if (board->quirks & AUOK190X_QUIRK_STANDBYPARAM) {
632 /* for some TCON versions STANDBY expects a parameter (0) but
633 * it seems the real tcon version has to be determined yet.
634 */
635 dev_dbg(dev, "runtime suspend with additional empty param\n");
636 standby_param = 0;
637 auok190x_send_cmdargs(par, AUOK190X_CMD_STANDBY, 1,
638 &standby_param);
639 } else {
640 dev_dbg(dev, "runtime suspend without param\n");
641 auok190x_send_command(par, AUOK190X_CMD_STANDBY);
642 }
643
644 msleep(64);
645
646finish:
647 par->standby = 1;
648
649 return 0;
650}
651
652static int auok190x_runtime_resume(struct device *dev)
653{
654 struct platform_device *pdev = to_platform_device(dev);
655 struct fb_info *info = platform_get_drvdata(pdev);
656 struct auok190xfb_par *par = info->par;
657 struct auok190x_board *board = par->board;
658
659 if (!par->standby) {
660 dev_warn(dev, "not in standby, runtime-pm pairing mismatch\n");
661 return 0;
662 }
663
664 if (board->quirks & AUOK190X_QUIRK_STANDBYBROKEN) {
665 dev_dbg(dev, "runtime resume without standby\n");
666 } else {
667 /* when in standby, controller is always busy
668 * and only accepts the wakeup command
669 */
670 dev_dbg(dev, "runtime resume from standby\n");
671 auok190x_send_command_nowait(par, AUOK190X_CMD_WAKEUP);
672
673 msleep(160);
674
675 /* wait for the controller to be ready and release the lock */
676 board->wait_for_rdy(par);
677 }
678
679 par->standby = 0;
680
681 mutex_unlock(&(par->io_lock));
682
683 return 0;
684}
685
686static int auok190x_suspend(struct device *dev)
687{
688 struct platform_device *pdev = to_platform_device(dev);
689 struct fb_info *info = platform_get_drvdata(pdev);
690 struct auok190xfb_par *par = info->par;
691 struct auok190x_board *board = par->board;
692 int ret;
693
694 dev_dbg(dev, "suspend\n");
695 if (board->quirks & AUOK190X_QUIRK_STANDBYBROKEN) {
696 /* suspend via powering off the ic */
697 dev_dbg(dev, "suspend with broken standby\n");
698
699 auok190x_power(par, 0);
700 } else {
701 dev_dbg(dev, "suspend using sleep\n");
702
703 /* the sleep state can only be entered from the standby state.
704 * pm_runtime_get_noresume gets called before the suspend call.
705 * So the devices usage count is >0 but it is not necessarily
706 * active.
707 */
708 if (!pm_runtime_status_suspended(dev)) {
709 ret = auok190x_runtime_suspend(dev);
710 if (ret < 0) {
711 dev_err(dev, "auok190x_runtime_suspend failed with %d\n",
712 ret);
713 return ret;
714 }
715 par->manual_standby = 1;
716 }
717
718 gpio_direction_output(board->gpio_nsleep, 0);
719 }
720
721 msleep(100);
722
723 return 0;
724}
725
726static int auok190x_resume(struct device *dev)
727{
728 struct platform_device *pdev = to_platform_device(dev);
729 struct fb_info *info = platform_get_drvdata(pdev);
730 struct auok190xfb_par *par = info->par;
731 struct auok190x_board *board = par->board;
732
733 dev_dbg(dev, "resume\n");
734 if (board->quirks & AUOK190X_QUIRK_STANDBYBROKEN) {
735 dev_dbg(dev, "resume with broken standby\n");
736
737 auok190x_power(par, 1);
738
739 par->init(par);
740 } else {
741 dev_dbg(dev, "resume from sleep\n");
742
743 /* device should be in runtime suspend when we were suspended
744 * and pm_runtime_put_sync gets called after this function.
745 * So there is no need to touch the standby mode here at all.
746 */
747 gpio_direction_output(board->gpio_nsleep, 1);
748 msleep(100);
749
750 /* an additional init call seems to be necessary after sleep */
751 auok190x_runtime_resume(dev);
752 par->init(par);
753
754 /* if we were runtime-suspended before, suspend again*/
755 if (!par->manual_standby)
756 auok190x_runtime_suspend(dev);
757 else
758 par->manual_standby = 0;
759 }
760
761 return 0;
762}
763#endif
764
765const struct dev_pm_ops auok190x_pm = {
766 SET_RUNTIME_PM_OPS(auok190x_runtime_suspend, auok190x_runtime_resume,
767 NULL)
768 SET_SYSTEM_SLEEP_PM_OPS(auok190x_suspend, auok190x_resume)
769};
770EXPORT_SYMBOL_GPL(auok190x_pm);
771
772/*
773 * Common probe and remove code
774 */
775
776int __devinit auok190x_common_probe(struct platform_device *pdev,
777 struct auok190x_init_data *init)
778{
779 struct auok190x_board *board = init->board;
780 struct auok190xfb_par *par;
781 struct fb_info *info;
782 struct panel_info *panel;
783 int videomemorysize, ret;
784 unsigned char *videomemory;
785
786 /* check board contents */
787 if (!board->init || !board->cleanup || !board->wait_for_rdy
788 || !board->set_ctl || !board->set_hdb || !board->get_hdb
789 || !board->setup_irq)
790 return -EINVAL;
791
792 info = framebuffer_alloc(sizeof(struct auok190xfb_par), &pdev->dev);
793 if (!info)
794 return -ENOMEM;
795
796 par = info->par;
797 par->info = info;
798 par->board = board;
799 par->recover = auok190x_recover;
800 par->update_partial = init->update_partial;
801 par->update_all = init->update_all;
802 par->need_refresh = init->need_refresh;
803 par->init = init->init;
804
805 /* init update modes */
806 par->update_cnt = 0;
807 par->update_mode = -1;
808 par->last_mode = -1;
809 par->flash = 0;
810
811 par->regulator = regulator_get(info->device, "vdd");
812 if (IS_ERR(par->regulator)) {
813 ret = PTR_ERR(par->regulator);
814 dev_err(info->device, "Failed to get regulator: %d\n", ret);
815 goto err_reg;
816 }
817
818 ret = board->init(par);
819 if (ret) {
820 dev_err(info->device, "board init failed, %d\n", ret);
821 goto err_board;
822 }
823
824 ret = gpio_request(board->gpio_nsleep, "AUOK190x sleep");
825 if (ret) {
826 dev_err(info->device, "could not request sleep gpio, %d\n",
827 ret);
828 goto err_gpio1;
829 }
830
831 ret = gpio_direction_output(board->gpio_nsleep, 0);
832 if (ret) {
833 dev_err(info->device, "could not set sleep gpio, %d\n", ret);
834 goto err_gpio2;
835 }
836
837 ret = gpio_request(board->gpio_nrst, "AUOK190x reset");
838 if (ret) {
839 dev_err(info->device, "could not request reset gpio, %d\n",
840 ret);
841 goto err_gpio2;
842 }
843
844 ret = gpio_direction_output(board->gpio_nrst, 0);
845 if (ret) {
846 dev_err(info->device, "could not set reset gpio, %d\n", ret);
847 goto err_gpio3;
848 }
849
850 ret = auok190x_power(par, 1);
851 if (ret) {
852 dev_err(info->device, "could not power on the device, %d\n",
853 ret);
854 goto err_gpio3;
855 }
856
857 mutex_init(&par->io_lock);
858
859 init_waitqueue_head(&par->waitq);
860
861 ret = par->board->setup_irq(par->info);
862 if (ret) {
863 dev_err(info->device, "could not setup ready-irq, %d\n", ret);
864 goto err_irq;
865 }
866
867 /* wait for init to complete */
868 par->board->wait_for_rdy(par);
869
870 /*
871 * From here on the controller can talk to us
872 */
873
874 /* initialise fix, var, resolution and rotation */
875
876 strlcpy(info->fix.id, init->id, 16);
877 info->fix.type = FB_TYPE_PACKED_PIXELS;
878 info->fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
879 info->fix.xpanstep = 0;
880 info->fix.ypanstep = 0;
881 info->fix.ywrapstep = 0;
882 info->fix.accel = FB_ACCEL_NONE;
883
884 info->var.bits_per_pixel = 8;
885 info->var.grayscale = 1;
886 info->var.red.length = 8;
887 info->var.green.length = 8;
888 info->var.blue.length = 8;
889
890 panel = &panel_table[board->resolution];
891
892 /* if 90 degree rotation, switch width and height */
893 if (board->rotation & 1) {
894 info->var.xres = panel->h;
895 info->var.yres = panel->w;
896 info->var.xres_virtual = panel->h;
897 info->var.yres_virtual = panel->w;
898 info->fix.line_length = panel->h;
899 } else {
900 info->var.xres = panel->w;
901 info->var.yres = panel->h;
902 info->var.xres_virtual = panel->w;
903 info->var.yres_virtual = panel->h;
904 info->fix.line_length = panel->w;
905 }
906
907 par->resolution = board->resolution;
908 par->rotation = board->rotation;
909
910 /* videomemory handling */
911
912 videomemorysize = roundup((panel->w * panel->h), PAGE_SIZE);
913 videomemory = vmalloc(videomemorysize);
914 if (!videomemory) {
915 ret = -ENOMEM;
916 goto err_irq;
917 }
918
919 memset(videomemory, 0, videomemorysize);
920 info->screen_base = (char *)videomemory;
921 info->fix.smem_len = videomemorysize;
922
923 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB;
924 info->fbops = &auok190xfb_ops;
925
926 /* deferred io init */
927
928 info->fbdefio = devm_kzalloc(info->device,
929 sizeof(struct fb_deferred_io),
930 GFP_KERNEL);
931 if (!info->fbdefio) {
932 dev_err(info->device, "Failed to allocate memory\n");
933 ret = -ENOMEM;
934 goto err_defio;
935 }
936
937 dev_dbg(info->device, "targetting %d frames per second\n", board->fps);
938 info->fbdefio->delay = HZ / board->fps;
939 info->fbdefio->first_io = auok190xfb_dpy_first_io,
940 info->fbdefio->deferred_io = auok190xfb_dpy_deferred_io,
941 fb_deferred_io_init(info);
942
943 /* color map */
944
945 ret = fb_alloc_cmap(&info->cmap, 256, 0);
946 if (ret < 0) {
947 dev_err(info->device, "Failed to allocate colormap\n");
948 goto err_cmap;
949 }
950
951 /* controller init */
952
953 par->consecutive_threshold = 100;
954 par->init(par);
955 auok190x_identify(par);
956
957 platform_set_drvdata(pdev, info);
958
959 ret = register_framebuffer(info);
960 if (ret < 0)
961 goto err_regfb;
962
963 ret = sysfs_create_group(&info->device->kobj, &auok190x_attr_group);
964 if (ret)
965 goto err_sysfs;
966
967 dev_info(info->device, "fb%d: %dx%d using %dK of video memory\n",
968 info->node, info->var.xres, info->var.yres,
969 videomemorysize >> 10);
970
971 /* increase autosuspend_delay when we use alternative methods
972 * for runtime_pm
973 */
974 par->autosuspend_delay = (board->quirks & AUOK190X_QUIRK_STANDBYBROKEN)
975 ? 1000 : 200;
976
977 pm_runtime_set_active(info->device);
978 pm_runtime_enable(info->device);
979 pm_runtime_set_autosuspend_delay(info->device, par->autosuspend_delay);
980 pm_runtime_use_autosuspend(info->device);
981
982 return 0;
983
984err_sysfs:
985 unregister_framebuffer(info);
986err_regfb:
987 fb_dealloc_cmap(&info->cmap);
988err_cmap:
989 fb_deferred_io_cleanup(info);
990 kfree(info->fbdefio);
991err_defio:
992 vfree((void *)info->screen_base);
993err_irq:
994 auok190x_power(par, 0);
995err_gpio3:
996 gpio_free(board->gpio_nrst);
997err_gpio2:
998 gpio_free(board->gpio_nsleep);
999err_gpio1:
1000 board->cleanup(par);
1001err_board:
1002 regulator_put(par->regulator);
1003err_reg:
1004 framebuffer_release(info);
1005
1006 return ret;
1007}
1008EXPORT_SYMBOL_GPL(auok190x_common_probe);
1009
1010int __devexit auok190x_common_remove(struct platform_device *pdev)
1011{
1012 struct fb_info *info = platform_get_drvdata(pdev);
1013 struct auok190xfb_par *par = info->par;
1014 struct auok190x_board *board = par->board;
1015
1016 pm_runtime_disable(info->device);
1017
1018 sysfs_remove_group(&info->device->kobj, &auok190x_attr_group);
1019
1020 unregister_framebuffer(info);
1021
1022 fb_dealloc_cmap(&info->cmap);
1023
1024 fb_deferred_io_cleanup(info);
1025 kfree(info->fbdefio);
1026
1027 vfree((void *)info->screen_base);
1028
1029 auok190x_power(par, 0);
1030
1031 gpio_free(board->gpio_nrst);
1032 gpio_free(board->gpio_nsleep);
1033
1034 board->cleanup(par);
1035
1036 regulator_put(par->regulator);
1037
1038 framebuffer_release(info);
1039
1040 return 0;
1041}
1042EXPORT_SYMBOL_GPL(auok190x_common_remove);
1043
1044MODULE_DESCRIPTION("Common code for AUO-K190X controllers");
1045MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
1046MODULE_LICENSE("GPL");
diff --git a/drivers/video/auo_k190x.h b/drivers/video/auo_k190x.h
new file mode 100644
index 000000000000..e35af1f51b28
--- /dev/null
+++ b/drivers/video/auo_k190x.h
@@ -0,0 +1,129 @@
1/*
2 * Private common definitions for AUO-K190X framebuffer drivers
3 *
4 * Copyright (C) 2012 Heiko Stuebner <heiko@sntech.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11/*
12 * I80 interface specific defines
13 */
14
15#define AUOK190X_I80_CS 0x01
16#define AUOK190X_I80_DC 0x02
17#define AUOK190X_I80_WR 0x03
18#define AUOK190X_I80_OE 0x04
19
20/*
21 * AUOK190x commands, common to both controllers
22 */
23
24#define AUOK190X_CMD_INIT 0x0000
25#define AUOK190X_CMD_STANDBY 0x0001
26#define AUOK190X_CMD_WAKEUP 0x0002
27#define AUOK190X_CMD_TCON_RESET 0x0003
28#define AUOK190X_CMD_DATA_STOP 0x1002
29#define AUOK190X_CMD_LUT_START 0x1003
30#define AUOK190X_CMD_DISP_REFRESH 0x1004
31#define AUOK190X_CMD_DISP_RESET 0x1005
32#define AUOK190X_CMD_PRE_DISPLAY_START 0x100D
33#define AUOK190X_CMD_PRE_DISPLAY_STOP 0x100F
34#define AUOK190X_CMD_FLASH_W 0x2000
35#define AUOK190X_CMD_FLASH_E 0x2001
36#define AUOK190X_CMD_FLASH_STS 0x2002
37#define AUOK190X_CMD_FRAMERATE 0x3000
38#define AUOK190X_CMD_READ_VERSION 0x4000
39#define AUOK190X_CMD_READ_STATUS 0x4001
40#define AUOK190X_CMD_READ_LUT 0x4003
41#define AUOK190X_CMD_DRIVERTIMING 0x5000
42#define AUOK190X_CMD_LBALANCE 0x5001
43#define AUOK190X_CMD_AGINGMODE 0x6000
44#define AUOK190X_CMD_AGINGEXIT 0x6001
45
46/*
47 * Common settings for AUOK190X_CMD_INIT
48 */
49
50#define AUOK190X_INIT_DATA_FILTER (0 << 12)
51#define AUOK190X_INIT_DATA_BYPASS (1 << 12)
52#define AUOK190X_INIT_INVERSE_WHITE (0 << 9)
53#define AUOK190X_INIT_INVERSE_BLACK (1 << 9)
54#define AUOK190X_INIT_SCAN_DOWN (0 << 1)
55#define AUOK190X_INIT_SCAN_UP (1 << 1)
56#define AUOK190X_INIT_SHIFT_LEFT (0 << 0)
57#define AUOK190X_INIT_SHIFT_RIGHT (1 << 0)
58
59/* Common bits to pixels
60 * Mode 15-12 11-8 7-4 3-0
61 * format0 4 3 2 1
62 * format1 3 4 1 2
63 */
64
65#define AUOK190X_INIT_FORMAT0 0
66#define AUOK190X_INIT_FORMAT1 (1 << 6)
67
68/*
69 * settings for AUOK190X_CMD_RESET
70 */
71
72#define AUOK190X_RESET_TCON (0 << 0)
73#define AUOK190X_RESET_NORMAL (1 << 0)
74#define AUOK190X_RESET_PON (1 << 1)
75
76/*
77 * AUOK190X_CMD_VERSION
78 */
79
80#define AUOK190X_VERSION_TEMP_MASK (0x1ff)
81#define AUOK190X_VERSION_EPD_MASK (0xff)
82#define AUOK190X_VERSION_SIZE_INT(_val) ((_val & 0xfc00) >> 10)
83#define AUOK190X_VERSION_SIZE_FLOAT(_val) ((_val & 0x3c0) >> 6)
84#define AUOK190X_VERSION_MODEL(_val) (_val & 0x3f)
85#define AUOK190X_VERSION_LUT(_val) (_val & 0xff)
86#define AUOK190X_VERSION_TCON(_val) ((_val & 0xff00) >> 8)
87
88/*
89 * update modes for CMD_PARTIALDISP on K1900 and CMD_DDMA on K1901
90 */
91
92#define AUOK190X_UPDATE_MODE(_res) ((_res & 0x7) << 12)
93#define AUOK190X_UPDATE_NONFLASH (1 << 15)
94
95/*
96 * track panel specific parameters for common init
97 */
98
99struct auok190x_init_data {
100 char *id;
101 struct auok190x_board *board;
102
103 void (*update_partial)(struct auok190xfb_par *par, u16 y1, u16 y2);
104 void (*update_all)(struct auok190xfb_par *par);
105 bool (*need_refresh)(struct auok190xfb_par *par);
106 void (*init)(struct auok190xfb_par *par);
107};
108
109
110extern void auok190x_send_command_nowait(struct auok190xfb_par *par, u16 data);
111extern int auok190x_send_command(struct auok190xfb_par *par, u16 data);
112extern void auok190x_send_cmdargs_nowait(struct auok190xfb_par *par, u16 cmd,
113 int argc, u16 *argv);
114extern int auok190x_send_cmdargs(struct auok190xfb_par *par, u16 cmd,
115 int argc, u16 *argv);
116extern void auok190x_send_cmdargs_pixels_nowait(struct auok190xfb_par *par,
117 u16 cmd, int argc, u16 *argv,
118 int size, u16 *data);
119extern int auok190x_send_cmdargs_pixels(struct auok190xfb_par *par, u16 cmd,
120 int argc, u16 *argv, int size,
121 u16 *data);
122extern int auok190x_read_cmdargs(struct auok190xfb_par *par, u16 cmd,
123 int argc, u16 *argv);
124
125extern int auok190x_common_probe(struct platform_device *pdev,
126 struct auok190x_init_data *init);
127extern int auok190x_common_remove(struct platform_device *pdev);
128
129extern const struct dev_pm_ops auok190x_pm;
diff --git a/drivers/video/bfin_adv7393fb.c b/drivers/video/bfin_adv7393fb.c
index 1a268a294478..33ea874c87d2 100644
--- a/drivers/video/bfin_adv7393fb.c
+++ b/drivers/video/bfin_adv7393fb.c
@@ -414,14 +414,14 @@ static int __devinit bfin_adv7393_fb_probe(struct i2c_client *client,
414 if (ret) { 414 if (ret) {
415 dev_err(&client->dev, "PPI0_FS3 GPIO request failed\n"); 415 dev_err(&client->dev, "PPI0_FS3 GPIO request failed\n");
416 ret = -EBUSY; 416 ret = -EBUSY;
417 goto out_8; 417 goto free_fbdev;
418 } 418 }
419 } 419 }
420 420
421 if (peripheral_request_list(ppi_pins, DRIVER_NAME)) { 421 if (peripheral_request_list(ppi_pins, DRIVER_NAME)) {
422 dev_err(&client->dev, "requesting PPI peripheral failed\n"); 422 dev_err(&client->dev, "requesting PPI peripheral failed\n");
423 ret = -EFAULT; 423 ret = -EFAULT;
424 goto out_8; 424 goto free_gpio;
425 } 425 }
426 426
427 fbdev->fb_mem = 427 fbdev->fb_mem =
@@ -432,7 +432,7 @@ static int __devinit bfin_adv7393_fb_probe(struct i2c_client *client,
432 dev_err(&client->dev, "couldn't allocate dma buffer (%d bytes)\n", 432 dev_err(&client->dev, "couldn't allocate dma buffer (%d bytes)\n",
433 (u32) fbdev->fb_len); 433 (u32) fbdev->fb_len);
434 ret = -ENOMEM; 434 ret = -ENOMEM;
435 goto out_7; 435 goto free_ppi_pins;
436 } 436 }
437 437
438 fbdev->info.screen_base = (void *)fbdev->fb_mem; 438 fbdev->info.screen_base = (void *)fbdev->fb_mem;
@@ -464,27 +464,27 @@ static int __devinit bfin_adv7393_fb_probe(struct i2c_client *client,
464 if (!fbdev->info.pseudo_palette) { 464 if (!fbdev->info.pseudo_palette) {
465 dev_err(&client->dev, "failed to allocate pseudo_palette\n"); 465 dev_err(&client->dev, "failed to allocate pseudo_palette\n");
466 ret = -ENOMEM; 466 ret = -ENOMEM;
467 goto out_6; 467 goto free_fb_mem;
468 } 468 }
469 469
470 if (fb_alloc_cmap(&fbdev->info.cmap, BFIN_LCD_NBR_PALETTE_ENTRIES, 0) < 0) { 470 if (fb_alloc_cmap(&fbdev->info.cmap, BFIN_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
471 dev_err(&client->dev, "failed to allocate colormap (%d entries)\n", 471 dev_err(&client->dev, "failed to allocate colormap (%d entries)\n",
472 BFIN_LCD_NBR_PALETTE_ENTRIES); 472 BFIN_LCD_NBR_PALETTE_ENTRIES);
473 ret = -EFAULT; 473 ret = -EFAULT;
474 goto out_5; 474 goto free_palette;
475 } 475 }
476 476
477 if (request_dma(CH_PPI, "BF5xx_PPI_DMA") < 0) { 477 if (request_dma(CH_PPI, "BF5xx_PPI_DMA") < 0) {
478 dev_err(&client->dev, "unable to request PPI DMA\n"); 478 dev_err(&client->dev, "unable to request PPI DMA\n");
479 ret = -EFAULT; 479 ret = -EFAULT;
480 goto out_4; 480 goto free_cmap;
481 } 481 }
482 482
483 if (request_irq(IRQ_PPI_ERROR, ppi_irq_error, 0, 483 if (request_irq(IRQ_PPI_ERROR, ppi_irq_error, 0,
484 "PPI ERROR", fbdev) < 0) { 484 "PPI ERROR", fbdev) < 0) {
485 dev_err(&client->dev, "unable to request PPI ERROR IRQ\n"); 485 dev_err(&client->dev, "unable to request PPI ERROR IRQ\n");
486 ret = -EFAULT; 486 ret = -EFAULT;
487 goto out_3; 487 goto free_ch_ppi;
488 } 488 }
489 489
490 fbdev->open = 0; 490 fbdev->open = 0;
@@ -494,14 +494,14 @@ static int __devinit bfin_adv7393_fb_probe(struct i2c_client *client,
494 494
495 if (ret) { 495 if (ret) {
496 dev_err(&client->dev, "i2c attach: init error\n"); 496 dev_err(&client->dev, "i2c attach: init error\n");
497 goto out_1; 497 goto free_irq_ppi;
498 } 498 }
499 499
500 500
501 if (register_framebuffer(&fbdev->info) < 0) { 501 if (register_framebuffer(&fbdev->info) < 0) {
502 dev_err(&client->dev, "unable to register framebuffer\n"); 502 dev_err(&client->dev, "unable to register framebuffer\n");
503 ret = -EFAULT; 503 ret = -EFAULT;
504 goto out_1; 504 goto free_irq_ppi;
505 } 505 }
506 506
507 dev_info(&client->dev, "fb%d: %s frame buffer device\n", 507 dev_info(&client->dev, "fb%d: %s frame buffer device\n",
@@ -512,7 +512,7 @@ static int __devinit bfin_adv7393_fb_probe(struct i2c_client *client,
512 if (!entry) { 512 if (!entry) {
513 dev_err(&client->dev, "unable to create /proc entry\n"); 513 dev_err(&client->dev, "unable to create /proc entry\n");
514 ret = -EFAULT; 514 ret = -EFAULT;
515 goto out_0; 515 goto free_fb;
516 } 516 }
517 517
518 entry->read_proc = adv7393_read_proc; 518 entry->read_proc = adv7393_read_proc;
@@ -521,22 +521,25 @@ static int __devinit bfin_adv7393_fb_probe(struct i2c_client *client,
521 521
522 return 0; 522 return 0;
523 523
524 out_0: 524free_fb:
525 unregister_framebuffer(&fbdev->info); 525 unregister_framebuffer(&fbdev->info);
526 out_1: 526free_irq_ppi:
527 free_irq(IRQ_PPI_ERROR, fbdev); 527 free_irq(IRQ_PPI_ERROR, fbdev);
528 out_3: 528free_ch_ppi:
529 free_dma(CH_PPI); 529 free_dma(CH_PPI);
530 out_4: 530free_cmap:
531 dma_free_coherent(NULL, fbdev->fb_len, fbdev->fb_mem,
532 fbdev->dma_handle);
533 out_5:
534 fb_dealloc_cmap(&fbdev->info.cmap); 531 fb_dealloc_cmap(&fbdev->info.cmap);
535 out_6: 532free_palette:
536 kfree(fbdev->info.pseudo_palette); 533 kfree(fbdev->info.pseudo_palette);
537 out_7: 534free_fb_mem:
535 dma_free_coherent(NULL, fbdev->fb_len, fbdev->fb_mem,
536 fbdev->dma_handle);
537free_ppi_pins:
538 peripheral_free_list(ppi_pins); 538 peripheral_free_list(ppi_pins);
539 out_8: 539free_gpio:
540 if (ANOMALY_05000400)
541 gpio_free(P_IDENT(P_PPI0_FS3));
542free_fbdev:
540 kfree(fbdev); 543 kfree(fbdev);
541 544
542 return ret; 545 return ret;
diff --git a/drivers/video/cobalt_lcdfb.c b/drivers/video/cobalt_lcdfb.c
index f56699d8122a..eae46f6457e2 100644
--- a/drivers/video/cobalt_lcdfb.c
+++ b/drivers/video/cobalt_lcdfb.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * Cobalt server LCD frame buffer driver. 2 * Cobalt/SEAD3 LCD frame buffer driver.
3 * 3 *
4 * Copyright (C) 2008 Yoichi Yuasa <yuasa@linux-mips.org> 4 * Copyright (C) 2008 Yoichi Yuasa <yuasa@linux-mips.org>
5 * Copyright (C) 2012 MIPS Technologies, Inc.
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -62,6 +63,7 @@
62#define LCD_CUR_POS(x) ((x) & LCD_CUR_POS_MASK) 63#define LCD_CUR_POS(x) ((x) & LCD_CUR_POS_MASK)
63#define LCD_TEXT_POS(x) ((x) | LCD_TEXT_MODE) 64#define LCD_TEXT_POS(x) ((x) | LCD_TEXT_MODE)
64 65
66#ifdef CONFIG_MIPS_COBALT
65static inline void lcd_write_control(struct fb_info *info, u8 control) 67static inline void lcd_write_control(struct fb_info *info, u8 control)
66{ 68{
67 writel((u32)control << 24, info->screen_base); 69 writel((u32)control << 24, info->screen_base);
@@ -81,6 +83,47 @@ static inline u8 lcd_read_data(struct fb_info *info)
81{ 83{
82 return readl(info->screen_base + LCD_DATA_REG_OFFSET) >> 24; 84 return readl(info->screen_base + LCD_DATA_REG_OFFSET) >> 24;
83} 85}
86#else
87
88#define LCD_CTL 0x00
89#define LCD_DATA 0x08
90#define CPLD_STATUS 0x10
91#define CPLD_DATA 0x18
92
93static inline void cpld_wait(struct fb_info *info)
94{
95 do {
96 } while (readl(info->screen_base + CPLD_STATUS) & 1);
97}
98
99static inline void lcd_write_control(struct fb_info *info, u8 control)
100{
101 cpld_wait(info);
102 writel(control, info->screen_base + LCD_CTL);
103}
104
105static inline u8 lcd_read_control(struct fb_info *info)
106{
107 cpld_wait(info);
108 readl(info->screen_base + LCD_CTL);
109 cpld_wait(info);
110 return readl(info->screen_base + CPLD_DATA) & 0xff;
111}
112
113static inline void lcd_write_data(struct fb_info *info, u8 data)
114{
115 cpld_wait(info);
116 writel(data, info->screen_base + LCD_DATA);
117}
118
119static inline u8 lcd_read_data(struct fb_info *info)
120{
121 cpld_wait(info);
122 readl(info->screen_base + LCD_DATA);
123 cpld_wait(info);
124 return readl(info->screen_base + CPLD_DATA) & 0xff;
125}
126#endif
84 127
85static int lcd_busy_wait(struct fb_info *info) 128static int lcd_busy_wait(struct fb_info *info)
86{ 129{
diff --git a/drivers/video/ep93xx-fb.c b/drivers/video/ep93xx-fb.c
index f8babbeee275..345d96230978 100644
--- a/drivers/video/ep93xx-fb.c
+++ b/drivers/video/ep93xx-fb.c
@@ -507,16 +507,16 @@ static int __devinit ep93xxfb_probe(struct platform_device *pdev)
507 507
508 err = fb_alloc_cmap(&info->cmap, 256, 0); 508 err = fb_alloc_cmap(&info->cmap, 256, 0);
509 if (err) 509 if (err)
510 goto failed; 510 goto failed_cmap;
511 511
512 err = ep93xxfb_alloc_videomem(info); 512 err = ep93xxfb_alloc_videomem(info);
513 if (err) 513 if (err)
514 goto failed; 514 goto failed_videomem;
515 515
516 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 516 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
517 if (!res) { 517 if (!res) {
518 err = -ENXIO; 518 err = -ENXIO;
519 goto failed; 519 goto failed_resource;
520 } 520 }
521 521
522 /* 522 /*
@@ -532,7 +532,7 @@ static int __devinit ep93xxfb_probe(struct platform_device *pdev)
532 fbi->mmio_base = ioremap(res->start, resource_size(res)); 532 fbi->mmio_base = ioremap(res->start, resource_size(res));
533 if (!fbi->mmio_base) { 533 if (!fbi->mmio_base) {
534 err = -ENXIO; 534 err = -ENXIO;
535 goto failed; 535 goto failed_resource;
536 } 536 }
537 537
538 strcpy(info->fix.id, pdev->name); 538 strcpy(info->fix.id, pdev->name);
@@ -553,24 +553,24 @@ static int __devinit ep93xxfb_probe(struct platform_device *pdev)
553 if (err == 0) { 553 if (err == 0) {
554 dev_err(info->dev, "No suitable video mode found\n"); 554 dev_err(info->dev, "No suitable video mode found\n");
555 err = -EINVAL; 555 err = -EINVAL;
556 goto failed; 556 goto failed_mode;
557 } 557 }
558 558
559 if (mach_info->setup) { 559 if (mach_info->setup) {
560 err = mach_info->setup(pdev); 560 err = mach_info->setup(pdev);
561 if (err) 561 if (err)
562 return err; 562 goto failed_mode;
563 } 563 }
564 564
565 err = ep93xxfb_check_var(&info->var, info); 565 err = ep93xxfb_check_var(&info->var, info);
566 if (err) 566 if (err)
567 goto failed; 567 goto failed_check;
568 568
569 fbi->clk = clk_get(info->dev, NULL); 569 fbi->clk = clk_get(info->dev, NULL);
570 if (IS_ERR(fbi->clk)) { 570 if (IS_ERR(fbi->clk)) {
571 err = PTR_ERR(fbi->clk); 571 err = PTR_ERR(fbi->clk);
572 fbi->clk = NULL; 572 fbi->clk = NULL;
573 goto failed; 573 goto failed_check;
574 } 574 }
575 575
576 ep93xxfb_set_par(info); 576 ep93xxfb_set_par(info);
@@ -585,15 +585,17 @@ static int __devinit ep93xxfb_probe(struct platform_device *pdev)
585 return 0; 585 return 0;
586 586
587failed: 587failed:
588 if (fbi->clk) 588 clk_put(fbi->clk);
589 clk_put(fbi->clk); 589failed_check:
590 if (fbi->mmio_base)
591 iounmap(fbi->mmio_base);
592 ep93xxfb_dealloc_videomem(info);
593 if (&info->cmap)
594 fb_dealloc_cmap(&info->cmap);
595 if (fbi->mach_info->teardown) 590 if (fbi->mach_info->teardown)
596 fbi->mach_info->teardown(pdev); 591 fbi->mach_info->teardown(pdev);
592failed_mode:
593 iounmap(fbi->mmio_base);
594failed_resource:
595 ep93xxfb_dealloc_videomem(info);
596failed_videomem:
597 fb_dealloc_cmap(&info->cmap);
598failed_cmap:
597 kfree(info); 599 kfree(info);
598 platform_set_drvdata(pdev, NULL); 600 platform_set_drvdata(pdev, NULL);
599 601
diff --git a/drivers/video/exynos/exynos_dp_core.c b/drivers/video/exynos/exynos_dp_core.c
index 2a4481cf260c..a36b2d28280e 100644
--- a/drivers/video/exynos/exynos_dp_core.c
+++ b/drivers/video/exynos/exynos_dp_core.c
@@ -21,14 +21,14 @@
21 21
22#include <video/exynos_dp.h> 22#include <video/exynos_dp.h>
23 23
24#include <plat/cpu.h>
25
26#include "exynos_dp_core.h" 24#include "exynos_dp_core.h"
27 25
28static int exynos_dp_init_dp(struct exynos_dp_device *dp) 26static int exynos_dp_init_dp(struct exynos_dp_device *dp)
29{ 27{
30 exynos_dp_reset(dp); 28 exynos_dp_reset(dp);
31 29
30 exynos_dp_swreset(dp);
31
32 /* SW defined function Normal operation */ 32 /* SW defined function Normal operation */
33 exynos_dp_enable_sw_function(dp); 33 exynos_dp_enable_sw_function(dp);
34 34
@@ -478,7 +478,7 @@ static int exynos_dp_process_clock_recovery(struct exynos_dp_device *dp)
478 int lane_count; 478 int lane_count;
479 u8 buf[5]; 479 u8 buf[5];
480 480
481 u8 *adjust_request; 481 u8 adjust_request[2];
482 u8 voltage_swing; 482 u8 voltage_swing;
483 u8 pre_emphasis; 483 u8 pre_emphasis;
484 u8 training_lane; 484 u8 training_lane;
@@ -493,8 +493,8 @@ static int exynos_dp_process_clock_recovery(struct exynos_dp_device *dp)
493 /* set training pattern 2 for EQ */ 493 /* set training pattern 2 for EQ */
494 exynos_dp_set_training_pattern(dp, TRAINING_PTN2); 494 exynos_dp_set_training_pattern(dp, TRAINING_PTN2);
495 495
496 adjust_request = link_status + (DPCD_ADDR_ADJUST_REQUEST_LANE0_1 496 adjust_request[0] = link_status[4];
497 - DPCD_ADDR_LANE0_1_STATUS); 497 adjust_request[1] = link_status[5];
498 498
499 exynos_dp_get_adjust_train(dp, adjust_request); 499 exynos_dp_get_adjust_train(dp, adjust_request);
500 500
@@ -566,7 +566,7 @@ static int exynos_dp_process_equalizer_training(struct exynos_dp_device *dp)
566 u8 buf[5]; 566 u8 buf[5];
567 u32 reg; 567 u32 reg;
568 568
569 u8 *adjust_request; 569 u8 adjust_request[2];
570 570
571 udelay(400); 571 udelay(400);
572 572
@@ -575,8 +575,8 @@ static int exynos_dp_process_equalizer_training(struct exynos_dp_device *dp)
575 lane_count = dp->link_train.lane_count; 575 lane_count = dp->link_train.lane_count;
576 576
577 if (exynos_dp_clock_recovery_ok(link_status, lane_count) == 0) { 577 if (exynos_dp_clock_recovery_ok(link_status, lane_count) == 0) {
578 adjust_request = link_status + (DPCD_ADDR_ADJUST_REQUEST_LANE0_1 578 adjust_request[0] = link_status[4];
579 - DPCD_ADDR_LANE0_1_STATUS); 579 adjust_request[1] = link_status[5];
580 580
581 if (exynos_dp_channel_eq_ok(link_status, lane_count) == 0) { 581 if (exynos_dp_channel_eq_ok(link_status, lane_count) == 0) {
582 /* traing pattern Set to Normal */ 582 /* traing pattern Set to Normal */
@@ -770,7 +770,7 @@ static int exynos_dp_config_video(struct exynos_dp_device *dp,
770 return -ETIMEDOUT; 770 return -ETIMEDOUT;
771 } 771 }
772 772
773 mdelay(100); 773 udelay(1);
774 } 774 }
775 775
776 /* Set to use the register calculated M/N video */ 776 /* Set to use the register calculated M/N video */
@@ -804,7 +804,7 @@ static int exynos_dp_config_video(struct exynos_dp_device *dp,
804 return -ETIMEDOUT; 804 return -ETIMEDOUT;
805 } 805 }
806 806
807 mdelay(100); 807 mdelay(1);
808 } 808 }
809 809
810 if (retval != 0) 810 if (retval != 0)
@@ -860,7 +860,8 @@ static int __devinit exynos_dp_probe(struct platform_device *pdev)
860 return -EINVAL; 860 return -EINVAL;
861 } 861 }
862 862
863 dp = kzalloc(sizeof(struct exynos_dp_device), GFP_KERNEL); 863 dp = devm_kzalloc(&pdev->dev, sizeof(struct exynos_dp_device),
864 GFP_KERNEL);
864 if (!dp) { 865 if (!dp) {
865 dev_err(&pdev->dev, "no memory for device data\n"); 866 dev_err(&pdev->dev, "no memory for device data\n");
866 return -ENOMEM; 867 return -ENOMEM;
@@ -871,8 +872,7 @@ static int __devinit exynos_dp_probe(struct platform_device *pdev)
871 dp->clock = clk_get(&pdev->dev, "dp"); 872 dp->clock = clk_get(&pdev->dev, "dp");
872 if (IS_ERR(dp->clock)) { 873 if (IS_ERR(dp->clock)) {
873 dev_err(&pdev->dev, "failed to get clock\n"); 874 dev_err(&pdev->dev, "failed to get clock\n");
874 ret = PTR_ERR(dp->clock); 875 return PTR_ERR(dp->clock);
875 goto err_dp;
876 } 876 }
877 877
878 clk_enable(dp->clock); 878 clk_enable(dp->clock);
@@ -884,35 +884,25 @@ static int __devinit exynos_dp_probe(struct platform_device *pdev)
884 goto err_clock; 884 goto err_clock;
885 } 885 }
886 886
887 res = request_mem_region(res->start, resource_size(res), 887 dp->reg_base = devm_request_and_ioremap(&pdev->dev, res);
888 dev_name(&pdev->dev));
889 if (!res) {
890 dev_err(&pdev->dev, "failed to request registers region\n");
891 ret = -EINVAL;
892 goto err_clock;
893 }
894
895 dp->res = res;
896
897 dp->reg_base = ioremap(res->start, resource_size(res));
898 if (!dp->reg_base) { 888 if (!dp->reg_base) {
899 dev_err(&pdev->dev, "failed to ioremap\n"); 889 dev_err(&pdev->dev, "failed to ioremap\n");
900 ret = -ENOMEM; 890 ret = -ENOMEM;
901 goto err_req_region; 891 goto err_clock;
902 } 892 }
903 893
904 dp->irq = platform_get_irq(pdev, 0); 894 dp->irq = platform_get_irq(pdev, 0);
905 if (!dp->irq) { 895 if (!dp->irq) {
906 dev_err(&pdev->dev, "failed to get irq\n"); 896 dev_err(&pdev->dev, "failed to get irq\n");
907 ret = -ENODEV; 897 ret = -ENODEV;
908 goto err_ioremap; 898 goto err_clock;
909 } 899 }
910 900
911 ret = request_irq(dp->irq, exynos_dp_irq_handler, 0, 901 ret = devm_request_irq(&pdev->dev, dp->irq, exynos_dp_irq_handler, 0,
912 "exynos-dp", dp); 902 "exynos-dp", dp);
913 if (ret) { 903 if (ret) {
914 dev_err(&pdev->dev, "failed to request irq\n"); 904 dev_err(&pdev->dev, "failed to request irq\n");
915 goto err_ioremap; 905 goto err_clock;
916 } 906 }
917 907
918 dp->video_info = pdata->video_info; 908 dp->video_info = pdata->video_info;
@@ -924,7 +914,7 @@ static int __devinit exynos_dp_probe(struct platform_device *pdev)
924 ret = exynos_dp_detect_hpd(dp); 914 ret = exynos_dp_detect_hpd(dp);
925 if (ret) { 915 if (ret) {
926 dev_err(&pdev->dev, "unable to detect hpd\n"); 916 dev_err(&pdev->dev, "unable to detect hpd\n");
927 goto err_irq; 917 goto err_clock;
928 } 918 }
929 919
930 exynos_dp_handle_edid(dp); 920 exynos_dp_handle_edid(dp);
@@ -933,7 +923,7 @@ static int __devinit exynos_dp_probe(struct platform_device *pdev)
933 dp->video_info->link_rate); 923 dp->video_info->link_rate);
934 if (ret) { 924 if (ret) {
935 dev_err(&pdev->dev, "unable to do link train\n"); 925 dev_err(&pdev->dev, "unable to do link train\n");
936 goto err_irq; 926 goto err_clock;
937 } 927 }
938 928
939 exynos_dp_enable_scramble(dp, 1); 929 exynos_dp_enable_scramble(dp, 1);
@@ -947,23 +937,15 @@ static int __devinit exynos_dp_probe(struct platform_device *pdev)
947 ret = exynos_dp_config_video(dp, dp->video_info); 937 ret = exynos_dp_config_video(dp, dp->video_info);
948 if (ret) { 938 if (ret) {
949 dev_err(&pdev->dev, "unable to config video\n"); 939 dev_err(&pdev->dev, "unable to config video\n");
950 goto err_irq; 940 goto err_clock;
951 } 941 }
952 942
953 platform_set_drvdata(pdev, dp); 943 platform_set_drvdata(pdev, dp);
954 944
955 return 0; 945 return 0;
956 946
957err_irq:
958 free_irq(dp->irq, dp);
959err_ioremap:
960 iounmap(dp->reg_base);
961err_req_region:
962 release_mem_region(res->start, resource_size(res));
963err_clock: 947err_clock:
964 clk_put(dp->clock); 948 clk_put(dp->clock);
965err_dp:
966 kfree(dp);
967 949
968 return ret; 950 return ret;
969} 951}
@@ -976,16 +958,9 @@ static int __devexit exynos_dp_remove(struct platform_device *pdev)
976 if (pdata && pdata->phy_exit) 958 if (pdata && pdata->phy_exit)
977 pdata->phy_exit(); 959 pdata->phy_exit();
978 960
979 free_irq(dp->irq, dp);
980 iounmap(dp->reg_base);
981
982 clk_disable(dp->clock); 961 clk_disable(dp->clock);
983 clk_put(dp->clock); 962 clk_put(dp->clock);
984 963
985 release_mem_region(dp->res->start, resource_size(dp->res));
986
987 kfree(dp);
988
989 return 0; 964 return 0;
990} 965}
991 966
diff --git a/drivers/video/exynos/exynos_dp_core.h b/drivers/video/exynos/exynos_dp_core.h
index 90ceaca0fa24..1e0f998e0c9f 100644
--- a/drivers/video/exynos/exynos_dp_core.h
+++ b/drivers/video/exynos/exynos_dp_core.h
@@ -26,7 +26,6 @@ struct link_train {
26 26
27struct exynos_dp_device { 27struct exynos_dp_device {
28 struct device *dev; 28 struct device *dev;
29 struct resource *res;
30 struct clk *clock; 29 struct clk *clock;
31 unsigned int irq; 30 unsigned int irq;
32 void __iomem *reg_base; 31 void __iomem *reg_base;
@@ -39,8 +38,10 @@ struct exynos_dp_device {
39void exynos_dp_enable_video_mute(struct exynos_dp_device *dp, bool enable); 38void exynos_dp_enable_video_mute(struct exynos_dp_device *dp, bool enable);
40void exynos_dp_stop_video(struct exynos_dp_device *dp); 39void exynos_dp_stop_video(struct exynos_dp_device *dp);
41void exynos_dp_lane_swap(struct exynos_dp_device *dp, bool enable); 40void exynos_dp_lane_swap(struct exynos_dp_device *dp, bool enable);
41void exynos_dp_init_analog_param(struct exynos_dp_device *dp);
42void exynos_dp_init_interrupt(struct exynos_dp_device *dp); 42void exynos_dp_init_interrupt(struct exynos_dp_device *dp);
43void exynos_dp_reset(struct exynos_dp_device *dp); 43void exynos_dp_reset(struct exynos_dp_device *dp);
44void exynos_dp_swreset(struct exynos_dp_device *dp);
44void exynos_dp_config_interrupt(struct exynos_dp_device *dp); 45void exynos_dp_config_interrupt(struct exynos_dp_device *dp);
45u32 exynos_dp_get_pll_lock_status(struct exynos_dp_device *dp); 46u32 exynos_dp_get_pll_lock_status(struct exynos_dp_device *dp);
46void exynos_dp_set_pll_power_down(struct exynos_dp_device *dp, bool enable); 47void exynos_dp_set_pll_power_down(struct exynos_dp_device *dp, bool enable);
diff --git a/drivers/video/exynos/exynos_dp_reg.c b/drivers/video/exynos/exynos_dp_reg.c
index 6548afa0e3d2..6ce76d56c3a1 100644
--- a/drivers/video/exynos/exynos_dp_reg.c
+++ b/drivers/video/exynos/exynos_dp_reg.c
@@ -16,8 +16,6 @@
16 16
17#include <video/exynos_dp.h> 17#include <video/exynos_dp.h>
18 18
19#include <plat/cpu.h>
20
21#include "exynos_dp_core.h" 19#include "exynos_dp_core.h"
22#include "exynos_dp_reg.h" 20#include "exynos_dp_reg.h"
23 21
@@ -65,6 +63,28 @@ void exynos_dp_lane_swap(struct exynos_dp_device *dp, bool enable)
65 writel(reg, dp->reg_base + EXYNOS_DP_LANE_MAP); 63 writel(reg, dp->reg_base + EXYNOS_DP_LANE_MAP);
66} 64}
67 65
66void exynos_dp_init_analog_param(struct exynos_dp_device *dp)
67{
68 u32 reg;
69
70 reg = TX_TERMINAL_CTRL_50_OHM;
71 writel(reg, dp->reg_base + EXYNOS_DP_ANALOG_CTL_1);
72
73 reg = SEL_24M | TX_DVDD_BIT_1_0625V;
74 writel(reg, dp->reg_base + EXYNOS_DP_ANALOG_CTL_2);
75
76 reg = DRIVE_DVDD_BIT_1_0625V | VCO_BIT_600_MICRO;
77 writel(reg, dp->reg_base + EXYNOS_DP_ANALOG_CTL_3);
78
79 reg = PD_RING_OSC | AUX_TERMINAL_CTRL_50_OHM |
80 TX_CUR1_2X | TX_CUR_8_MA;
81 writel(reg, dp->reg_base + EXYNOS_DP_PLL_FILTER_CTL_1);
82
83 reg = CH3_AMP_400_MV | CH2_AMP_400_MV |
84 CH1_AMP_400_MV | CH0_AMP_400_MV;
85 writel(reg, dp->reg_base + EXYNOS_DP_TX_AMP_TUNING_CTL);
86}
87
68void exynos_dp_init_interrupt(struct exynos_dp_device *dp) 88void exynos_dp_init_interrupt(struct exynos_dp_device *dp)
69{ 89{
70 /* Set interrupt pin assertion polarity as high */ 90 /* Set interrupt pin assertion polarity as high */
@@ -89,8 +109,6 @@ void exynos_dp_reset(struct exynos_dp_device *dp)
89{ 109{
90 u32 reg; 110 u32 reg;
91 111
92 writel(RESET_DP_TX, dp->reg_base + EXYNOS_DP_TX_SW_RESET);
93
94 exynos_dp_stop_video(dp); 112 exynos_dp_stop_video(dp);
95 exynos_dp_enable_video_mute(dp, 0); 113 exynos_dp_enable_video_mute(dp, 0);
96 114
@@ -131,9 +149,15 @@ void exynos_dp_reset(struct exynos_dp_device *dp)
131 149
132 writel(0x00000101, dp->reg_base + EXYNOS_DP_SOC_GENERAL_CTL); 150 writel(0x00000101, dp->reg_base + EXYNOS_DP_SOC_GENERAL_CTL);
133 151
152 exynos_dp_init_analog_param(dp);
134 exynos_dp_init_interrupt(dp); 153 exynos_dp_init_interrupt(dp);
135} 154}
136 155
156void exynos_dp_swreset(struct exynos_dp_device *dp)
157{
158 writel(RESET_DP_TX, dp->reg_base + EXYNOS_DP_TX_SW_RESET);
159}
160
137void exynos_dp_config_interrupt(struct exynos_dp_device *dp) 161void exynos_dp_config_interrupt(struct exynos_dp_device *dp)
138{ 162{
139 u32 reg; 163 u32 reg;
@@ -271,6 +295,7 @@ void exynos_dp_set_analog_power_down(struct exynos_dp_device *dp,
271void exynos_dp_init_analog_func(struct exynos_dp_device *dp) 295void exynos_dp_init_analog_func(struct exynos_dp_device *dp)
272{ 296{
273 u32 reg; 297 u32 reg;
298 int timeout_loop = 0;
274 299
275 exynos_dp_set_analog_power_down(dp, POWER_ALL, 0); 300 exynos_dp_set_analog_power_down(dp, POWER_ALL, 0);
276 301
@@ -282,9 +307,19 @@ void exynos_dp_init_analog_func(struct exynos_dp_device *dp)
282 writel(reg, dp->reg_base + EXYNOS_DP_DEBUG_CTL); 307 writel(reg, dp->reg_base + EXYNOS_DP_DEBUG_CTL);
283 308
284 /* Power up PLL */ 309 /* Power up PLL */
285 if (exynos_dp_get_pll_lock_status(dp) == PLL_UNLOCKED) 310 if (exynos_dp_get_pll_lock_status(dp) == PLL_UNLOCKED) {
286 exynos_dp_set_pll_power_down(dp, 0); 311 exynos_dp_set_pll_power_down(dp, 0);
287 312
313 while (exynos_dp_get_pll_lock_status(dp) == PLL_UNLOCKED) {
314 timeout_loop++;
315 if (DP_TIMEOUT_LOOP_COUNT < timeout_loop) {
316 dev_err(dp->dev, "failed to get pll lock status\n");
317 return;
318 }
319 usleep_range(10, 20);
320 }
321 }
322
288 /* Enable Serdes FIFO function and Link symbol clock domain module */ 323 /* Enable Serdes FIFO function and Link symbol clock domain module */
289 reg = readl(dp->reg_base + EXYNOS_DP_FUNC_EN_2); 324 reg = readl(dp->reg_base + EXYNOS_DP_FUNC_EN_2);
290 reg &= ~(SERDES_FIFO_FUNC_EN_N | LS_CLK_DOMAIN_FUNC_EN_N 325 reg &= ~(SERDES_FIFO_FUNC_EN_N | LS_CLK_DOMAIN_FUNC_EN_N
diff --git a/drivers/video/exynos/exynos_dp_reg.h b/drivers/video/exynos/exynos_dp_reg.h
index 42f608e2a43e..125b27cd57ae 100644
--- a/drivers/video/exynos/exynos_dp_reg.h
+++ b/drivers/video/exynos/exynos_dp_reg.h
@@ -24,6 +24,12 @@
24 24
25#define EXYNOS_DP_LANE_MAP 0x35C 25#define EXYNOS_DP_LANE_MAP 0x35C
26 26
27#define EXYNOS_DP_ANALOG_CTL_1 0x370
28#define EXYNOS_DP_ANALOG_CTL_2 0x374
29#define EXYNOS_DP_ANALOG_CTL_3 0x378
30#define EXYNOS_DP_PLL_FILTER_CTL_1 0x37C
31#define EXYNOS_DP_TX_AMP_TUNING_CTL 0x380
32
27#define EXYNOS_DP_AUX_HW_RETRY_CTL 0x390 33#define EXYNOS_DP_AUX_HW_RETRY_CTL 0x390
28 34
29#define EXYNOS_DP_COMMON_INT_STA_1 0x3C4 35#define EXYNOS_DP_COMMON_INT_STA_1 0x3C4
@@ -166,6 +172,29 @@
166#define LANE0_MAP_LOGIC_LANE_2 (0x2 << 0) 172#define LANE0_MAP_LOGIC_LANE_2 (0x2 << 0)
167#define LANE0_MAP_LOGIC_LANE_3 (0x3 << 0) 173#define LANE0_MAP_LOGIC_LANE_3 (0x3 << 0)
168 174
175/* EXYNOS_DP_ANALOG_CTL_1 */
176#define TX_TERMINAL_CTRL_50_OHM (0x1 << 4)
177
178/* EXYNOS_DP_ANALOG_CTL_2 */
179#define SEL_24M (0x1 << 3)
180#define TX_DVDD_BIT_1_0625V (0x4 << 0)
181
182/* EXYNOS_DP_ANALOG_CTL_3 */
183#define DRIVE_DVDD_BIT_1_0625V (0x4 << 5)
184#define VCO_BIT_600_MICRO (0x5 << 0)
185
186/* EXYNOS_DP_PLL_FILTER_CTL_1 */
187#define PD_RING_OSC (0x1 << 6)
188#define AUX_TERMINAL_CTRL_50_OHM (0x2 << 4)
189#define TX_CUR1_2X (0x1 << 2)
190#define TX_CUR_8_MA (0x2 << 0)
191
192/* EXYNOS_DP_TX_AMP_TUNING_CTL */
193#define CH3_AMP_400_MV (0x0 << 24)
194#define CH2_AMP_400_MV (0x0 << 16)
195#define CH1_AMP_400_MV (0x0 << 8)
196#define CH0_AMP_400_MV (0x0 << 0)
197
169/* EXYNOS_DP_AUX_HW_RETRY_CTL */ 198/* EXYNOS_DP_AUX_HW_RETRY_CTL */
170#define AUX_BIT_PERIOD_EXPECTED_DELAY(x) (((x) & 0x7) << 8) 199#define AUX_BIT_PERIOD_EXPECTED_DELAY(x) (((x) & 0x7) << 8)
171#define AUX_HW_RETRY_INTERVAL_MASK (0x3 << 3) 200#define AUX_HW_RETRY_INTERVAL_MASK (0x3 << 3)
diff --git a/drivers/video/exynos/exynos_mipi_dsi.c b/drivers/video/exynos/exynos_mipi_dsi.c
index 557091dc0e97..6c1f5c314a42 100644
--- a/drivers/video/exynos/exynos_mipi_dsi.c
+++ b/drivers/video/exynos/exynos_mipi_dsi.c
@@ -58,7 +58,7 @@ static struct mipi_dsim_platform_data *to_dsim_plat(struct platform_device
58} 58}
59 59
60static struct regulator_bulk_data supplies[] = { 60static struct regulator_bulk_data supplies[] = {
61 { .supply = "vdd10", }, 61 { .supply = "vdd11", },
62 { .supply = "vdd18", }, 62 { .supply = "vdd18", },
63}; 63};
64 64
@@ -102,6 +102,8 @@ static void exynos_mipi_update_cfg(struct mipi_dsim_device *dsim)
102 /* set display timing. */ 102 /* set display timing. */
103 exynos_mipi_dsi_set_display_mode(dsim, dsim->dsim_config); 103 exynos_mipi_dsi_set_display_mode(dsim, dsim->dsim_config);
104 104
105 exynos_mipi_dsi_init_interrupt(dsim);
106
105 /* 107 /*
106 * data from Display controller(FIMD) is transferred in video mode 108 * data from Display controller(FIMD) is transferred in video mode
107 * but in case of command mode, all settigs is updated to registers. 109 * but in case of command mode, all settigs is updated to registers.
@@ -413,27 +415,30 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev)
413 goto err_platform_get_irq; 415 goto err_platform_get_irq;
414 } 416 }
415 417
418 init_completion(&dsim_wr_comp);
419 init_completion(&dsim_rd_comp);
420 platform_set_drvdata(pdev, dsim);
421
416 ret = request_irq(dsim->irq, exynos_mipi_dsi_interrupt_handler, 422 ret = request_irq(dsim->irq, exynos_mipi_dsi_interrupt_handler,
417 IRQF_SHARED, pdev->name, dsim); 423 IRQF_SHARED, dev_name(&pdev->dev), dsim);
418 if (ret != 0) { 424 if (ret != 0) {
419 dev_err(&pdev->dev, "failed to request dsim irq\n"); 425 dev_err(&pdev->dev, "failed to request dsim irq\n");
420 ret = -EINVAL; 426 ret = -EINVAL;
421 goto err_bind; 427 goto err_bind;
422 } 428 }
423 429
424 init_completion(&dsim_wr_comp); 430 /* enable interrupts */
425 init_completion(&dsim_rd_comp);
426
427 /* enable interrupt */
428 exynos_mipi_dsi_init_interrupt(dsim); 431 exynos_mipi_dsi_init_interrupt(dsim);
429 432
430 /* initialize mipi-dsi client(lcd panel). */ 433 /* initialize mipi-dsi client(lcd panel). */
431 if (dsim_ddi->dsim_lcd_drv && dsim_ddi->dsim_lcd_drv->probe) 434 if (dsim_ddi->dsim_lcd_drv && dsim_ddi->dsim_lcd_drv->probe)
432 dsim_ddi->dsim_lcd_drv->probe(dsim_ddi->dsim_lcd_dev); 435 dsim_ddi->dsim_lcd_drv->probe(dsim_ddi->dsim_lcd_dev);
433 436
434 /* in case that mipi got enabled at bootloader. */ 437 /* in case mipi-dsi has been enabled by bootloader */
435 if (dsim_pd->enabled) 438 if (dsim_pd->enabled) {
436 goto out; 439 exynos_mipi_regulator_enable(dsim);
440 goto done;
441 }
437 442
438 /* lcd panel power on. */ 443 /* lcd panel power on. */
439 if (dsim_ddi->dsim_lcd_drv && dsim_ddi->dsim_lcd_drv->power_on) 444 if (dsim_ddi->dsim_lcd_drv && dsim_ddi->dsim_lcd_drv->power_on)
@@ -453,12 +458,11 @@ static int exynos_mipi_dsi_probe(struct platform_device *pdev)
453 458
454 dsim->suspended = false; 459 dsim->suspended = false;
455 460
456out: 461done:
457 platform_set_drvdata(pdev, dsim); 462 platform_set_drvdata(pdev, dsim);
458 463
459 dev_dbg(&pdev->dev, "mipi-dsi driver(%s mode) has been probed.\n", 464 dev_dbg(&pdev->dev, "%s() completed sucessfuly (%s mode)\n", __func__,
460 (dsim_config->e_interface == DSIM_COMMAND) ? 465 dsim_config->e_interface == DSIM_COMMAND ? "CPU" : "RGB");
461 "CPU" : "RGB");
462 466
463 return 0; 467 return 0;
464 468
@@ -515,10 +519,10 @@ static int __devexit exynos_mipi_dsi_remove(struct platform_device *pdev)
515 return 0; 519 return 0;
516} 520}
517 521
518#ifdef CONFIG_PM 522#ifdef CONFIG_PM_SLEEP
519static int exynos_mipi_dsi_suspend(struct platform_device *pdev, 523static int exynos_mipi_dsi_suspend(struct device *dev)
520 pm_message_t state)
521{ 524{
525 struct platform_device *pdev = to_platform_device(dev);
522 struct mipi_dsim_device *dsim = platform_get_drvdata(pdev); 526 struct mipi_dsim_device *dsim = platform_get_drvdata(pdev);
523 struct mipi_dsim_lcd_driver *client_drv = dsim->dsim_lcd_drv; 527 struct mipi_dsim_lcd_driver *client_drv = dsim->dsim_lcd_drv;
524 struct mipi_dsim_lcd_device *client_dev = dsim->dsim_lcd_dev; 528 struct mipi_dsim_lcd_device *client_dev = dsim->dsim_lcd_dev;
@@ -544,8 +548,9 @@ static int exynos_mipi_dsi_suspend(struct platform_device *pdev,
544 return 0; 548 return 0;
545} 549}
546 550
547static int exynos_mipi_dsi_resume(struct platform_device *pdev) 551static int exynos_mipi_dsi_resume(struct device *dev)
548{ 552{
553 struct platform_device *pdev = to_platform_device(dev);
549 struct mipi_dsim_device *dsim = platform_get_drvdata(pdev); 554 struct mipi_dsim_device *dsim = platform_get_drvdata(pdev);
550 struct mipi_dsim_lcd_driver *client_drv = dsim->dsim_lcd_drv; 555 struct mipi_dsim_lcd_driver *client_drv = dsim->dsim_lcd_drv;
551 struct mipi_dsim_lcd_device *client_dev = dsim->dsim_lcd_dev; 556 struct mipi_dsim_lcd_device *client_dev = dsim->dsim_lcd_dev;
@@ -577,19 +582,19 @@ static int exynos_mipi_dsi_resume(struct platform_device *pdev)
577 582
578 return 0; 583 return 0;
579} 584}
580#else
581#define exynos_mipi_dsi_suspend NULL
582#define exynos_mipi_dsi_resume NULL
583#endif 585#endif
584 586
587static const struct dev_pm_ops exynos_mipi_dsi_pm_ops = {
588 SET_SYSTEM_SLEEP_PM_OPS(exynos_mipi_dsi_suspend, exynos_mipi_dsi_resume)
589};
590
585static struct platform_driver exynos_mipi_dsi_driver = { 591static struct platform_driver exynos_mipi_dsi_driver = {
586 .probe = exynos_mipi_dsi_probe, 592 .probe = exynos_mipi_dsi_probe,
587 .remove = __devexit_p(exynos_mipi_dsi_remove), 593 .remove = __devexit_p(exynos_mipi_dsi_remove),
588 .suspend = exynos_mipi_dsi_suspend,
589 .resume = exynos_mipi_dsi_resume,
590 .driver = { 594 .driver = {
591 .name = "exynos-mipi-dsim", 595 .name = "exynos-mipi-dsim",
592 .owner = THIS_MODULE, 596 .owner = THIS_MODULE,
597 .pm = &exynos_mipi_dsi_pm_ops,
593 }, 598 },
594}; 599};
595 600
diff --git a/drivers/video/exynos/exynos_mipi_dsi_common.c b/drivers/video/exynos/exynos_mipi_dsi_common.c
index 14909c1d3832..47b533a183be 100644
--- a/drivers/video/exynos/exynos_mipi_dsi_common.c
+++ b/drivers/video/exynos/exynos_mipi_dsi_common.c
@@ -76,33 +76,25 @@ static unsigned int dpll_table[15] = {
76 76
77irqreturn_t exynos_mipi_dsi_interrupt_handler(int irq, void *dev_id) 77irqreturn_t exynos_mipi_dsi_interrupt_handler(int irq, void *dev_id)
78{ 78{
79 unsigned int intsrc = 0; 79 struct mipi_dsim_device *dsim = dev_id;
80 unsigned int intmsk = 0; 80 unsigned int intsrc, intmsk;
81 struct mipi_dsim_device *dsim = NULL; 81
82 82 if (dsim == NULL) {
83 dsim = dev_id; 83 dev_err(dsim->dev, "%s: wrong parameter\n", __func__);
84 if (!dsim) { 84 return IRQ_NONE;
85 dev_dbg(dsim->dev, KERN_ERR "%s:error: wrong parameter\n",
86 __func__);
87 return IRQ_HANDLED;
88 } 85 }
89 86
90 intsrc = exynos_mipi_dsi_read_interrupt(dsim); 87 intsrc = exynos_mipi_dsi_read_interrupt(dsim);
91 intmsk = exynos_mipi_dsi_read_interrupt_mask(dsim); 88 intmsk = exynos_mipi_dsi_read_interrupt_mask(dsim);
89 intmsk = ~intmsk & intsrc;
92 90
93 intmsk = ~(intmsk) & intsrc; 91 if (intsrc & INTMSK_RX_DONE) {
94
95 switch (intmsk) {
96 case INTMSK_RX_DONE:
97 complete(&dsim_rd_comp); 92 complete(&dsim_rd_comp);
98 dev_dbg(dsim->dev, "MIPI INTMSK_RX_DONE\n"); 93 dev_dbg(dsim->dev, "MIPI INTMSK_RX_DONE\n");
99 break; 94 }
100 case INTMSK_FIFO_EMPTY: 95 if (intsrc & INTMSK_FIFO_EMPTY) {
101 complete(&dsim_wr_comp); 96 complete(&dsim_wr_comp);
102 dev_dbg(dsim->dev, "MIPI INTMSK_FIFO_EMPTY\n"); 97 dev_dbg(dsim->dev, "MIPI INTMSK_FIFO_EMPTY\n");
103 break;
104 default:
105 break;
106 } 98 }
107 99
108 exynos_mipi_dsi_clear_interrupt(dsim, intmsk); 100 exynos_mipi_dsi_clear_interrupt(dsim, intmsk);
@@ -738,11 +730,11 @@ int exynos_mipi_dsi_set_display_mode(struct mipi_dsim_device *dsim,
738 if (dsim_config->auto_vertical_cnt == 0) { 730 if (dsim_config->auto_vertical_cnt == 0) {
739 exynos_mipi_dsi_set_main_disp_vporch(dsim, 731 exynos_mipi_dsi_set_main_disp_vporch(dsim,
740 dsim_config->cmd_allow, 732 dsim_config->cmd_allow,
741 timing->upper_margin, 733 timing->lower_margin,
742 timing->lower_margin); 734 timing->upper_margin);
743 exynos_mipi_dsi_set_main_disp_hporch(dsim, 735 exynos_mipi_dsi_set_main_disp_hporch(dsim,
744 timing->left_margin, 736 timing->right_margin,
745 timing->right_margin); 737 timing->left_margin);
746 exynos_mipi_dsi_set_main_disp_sync_area(dsim, 738 exynos_mipi_dsi_set_main_disp_sync_area(dsim,
747 timing->vsync_len, 739 timing->vsync_len,
748 timing->hsync_len); 740 timing->hsync_len);
diff --git a/drivers/video/exynos/s6e8ax0.c b/drivers/video/exynos/s6e8ax0.c
index 4aa9ac6218bf..05d080b63bc0 100644
--- a/drivers/video/exynos/s6e8ax0.c
+++ b/drivers/video/exynos/s6e8ax0.c
@@ -293,9 +293,20 @@ static void s6e8ax0_panel_cond(struct s6e8ax0 *lcd)
293 0x6e, 0x00, 0x00, 0x00, 0x02, 0x08, 0x08, 0x23, 0x23, 0xc0, 293 0x6e, 0x00, 0x00, 0x00, 0x02, 0x08, 0x08, 0x23, 0x23, 0xc0,
294 0xc8, 0x08, 0x48, 0xc1, 0x00, 0xc1, 0xff, 0xff, 0xc8 294 0xc8, 0x08, 0x48, 0xc1, 0x00, 0xc1, 0xff, 0xff, 0xc8
295 }; 295 };
296 static const unsigned char data_to_send_panel_reverse[] = {
297 0xf8, 0x19, 0x35, 0x00, 0x00, 0x00, 0x93, 0x00, 0x3c, 0x7d,
298 0x08, 0x27, 0x7d, 0x3f, 0x00, 0x00, 0x00, 0x20, 0x04, 0x08,
299 0x6e, 0x00, 0x00, 0x00, 0x02, 0x08, 0x08, 0x23, 0x23, 0xc0,
300 0xc1, 0x01, 0x41, 0xc1, 0x00, 0xc1, 0xf6, 0xf6, 0xc1
301 };
296 302
297 ops->cmd_write(lcd_to_master(lcd), MIPI_DSI_DCS_LONG_WRITE, 303 if (lcd->dsim_dev->panel_reverse)
298 data_to_send, ARRAY_SIZE(data_to_send)); 304 ops->cmd_write(lcd_to_master(lcd), MIPI_DSI_DCS_LONG_WRITE,
305 data_to_send_panel_reverse,
306 ARRAY_SIZE(data_to_send_panel_reverse));
307 else
308 ops->cmd_write(lcd_to_master(lcd), MIPI_DSI_DCS_LONG_WRITE,
309 data_to_send, ARRAY_SIZE(data_to_send));
299} 310}
300 311
301static void s6e8ax0_display_cond(struct s6e8ax0 *lcd) 312static void s6e8ax0_display_cond(struct s6e8ax0 *lcd)
diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
index c27e153d8882..1ddeb11659d4 100644
--- a/drivers/video/fb_defio.c
+++ b/drivers/video/fb_defio.c
@@ -23,7 +23,7 @@
23#include <linux/rmap.h> 23#include <linux/rmap.h>
24#include <linux/pagemap.h> 24#include <linux/pagemap.h>
25 25
26struct page *fb_deferred_io_page(struct fb_info *info, unsigned long offs) 26static struct page *fb_deferred_io_page(struct fb_info *info, unsigned long offs)
27{ 27{
28 void *screen_base = (void __force *) info->screen_base; 28 void *screen_base = (void __force *) info->screen_base;
29 struct page *page; 29 struct page *page;
@@ -107,6 +107,10 @@ static int fb_deferred_io_mkwrite(struct vm_area_struct *vma,
107 /* protect against the workqueue changing the page list */ 107 /* protect against the workqueue changing the page list */
108 mutex_lock(&fbdefio->lock); 108 mutex_lock(&fbdefio->lock);
109 109
110 /* first write in this cycle, notify the driver */
111 if (fbdefio->first_io && list_empty(&fbdefio->pagelist))
112 fbdefio->first_io(info);
113
110 /* 114 /*
111 * We want the page to remain locked from ->page_mkwrite until 115 * We want the page to remain locked from ->page_mkwrite until
112 * the PTE is marked dirty to avoid page_mkclean() being called 116 * the PTE is marked dirty to avoid page_mkclean() being called
diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
index 67afa9c2289d..a55e3669d135 100644
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -80,6 +80,8 @@ EXPORT_SYMBOL(framebuffer_alloc);
80 */ 80 */
81void framebuffer_release(struct fb_info *info) 81void framebuffer_release(struct fb_info *info)
82{ 82{
83 if (!info)
84 return;
83 kfree(info->apertures); 85 kfree(info->apertures);
84 kfree(info); 86 kfree(info);
85} 87}
diff --git a/drivers/video/fsl-diu-fb.c b/drivers/video/fsl-diu-fb.c
index 6af3f16754f0..458c00664ade 100644
--- a/drivers/video/fsl-diu-fb.c
+++ b/drivers/video/fsl-diu-fb.c
@@ -834,7 +834,6 @@ static void update_lcdc(struct fb_info *info)
834 diu_ops.set_pixel_clock(var->pixclock); 834 diu_ops.set_pixel_clock(var->pixclock);
835 835
836 out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */ 836 out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */
837 out_be32(&hw->thresholds, 0x00037800); /* The Thresholds */
838 out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */ 837 out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */
839 out_be32(&hw->plut, 0x01F5F666); 838 out_be32(&hw->plut, 0x01F5F666);
840 839
diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c
index 02fd2263610c..bdcbfbae2777 100644
--- a/drivers/video/intelfb/intelfbdrv.c
+++ b/drivers/video/intelfb/intelfbdrv.c
@@ -680,6 +680,7 @@ static int __devinit intelfb_pci_register(struct pci_dev *pdev,
680 + dinfo->fb.size); 680 + dinfo->fb.size);
681 if (!dinfo->aperture.virtual) { 681 if (!dinfo->aperture.virtual) {
682 ERR_MSG("Cannot remap FB region.\n"); 682 ERR_MSG("Cannot remap FB region.\n");
683 agp_backend_release(bridge);
683 cleanup(dinfo); 684 cleanup(dinfo);
684 return -ENODEV; 685 return -ENODEV;
685 } 686 }
@@ -689,6 +690,7 @@ static int __devinit intelfb_pci_register(struct pci_dev *pdev,
689 INTEL_REG_SIZE); 690 INTEL_REG_SIZE);
690 if (!dinfo->mmio_base) { 691 if (!dinfo->mmio_base) {
691 ERR_MSG("Cannot remap MMIO region.\n"); 692 ERR_MSG("Cannot remap MMIO region.\n");
693 agp_backend_release(bridge);
692 cleanup(dinfo); 694 cleanup(dinfo);
693 return -ENODEV; 695 return -ENODEV;
694 } 696 }
diff --git a/drivers/video/mb862xx/mb862xx-i2c.c b/drivers/video/mb862xx/mb862xx-i2c.c
index 273769bb8deb..c87e17afb3e2 100644
--- a/drivers/video/mb862xx/mb862xx-i2c.c
+++ b/drivers/video/mb862xx/mb862xx-i2c.c
@@ -68,7 +68,7 @@ static int mb862xx_i2c_read_byte(struct i2c_adapter *adap, u8 *byte, int last)
68 return 1; 68 return 1;
69} 69}
70 70
71void mb862xx_i2c_stop(struct i2c_adapter *adap) 71static void mb862xx_i2c_stop(struct i2c_adapter *adap)
72{ 72{
73 struct mb862xxfb_par *par = adap->algo_data; 73 struct mb862xxfb_par *par = adap->algo_data;
74 74
diff --git a/drivers/video/mb862xx/mb862xxfbdrv.c b/drivers/video/mb862xx/mb862xxfbdrv.c
index 11a7a333701d..00ce1f34b496 100644
--- a/drivers/video/mb862xx/mb862xxfbdrv.c
+++ b/drivers/video/mb862xx/mb862xxfbdrv.c
@@ -579,7 +579,7 @@ static ssize_t mb862xxfb_show_dispregs(struct device *dev,
579 579
580static DEVICE_ATTR(dispregs, 0444, mb862xxfb_show_dispregs, NULL); 580static DEVICE_ATTR(dispregs, 0444, mb862xxfb_show_dispregs, NULL);
581 581
582irqreturn_t mb862xx_intr(int irq, void *dev_id) 582static irqreturn_t mb862xx_intr(int irq, void *dev_id)
583{ 583{
584 struct mb862xxfb_par *par = (struct mb862xxfb_par *) dev_id; 584 struct mb862xxfb_par *par = (struct mb862xxfb_par *) dev_id;
585 unsigned long reg_ist, mask; 585 unsigned long reg_ist, mask;
diff --git a/drivers/video/mbx/mbxfb.c b/drivers/video/mbx/mbxfb.c
index 55bf6196b7a0..ab0a8e527333 100644
--- a/drivers/video/mbx/mbxfb.c
+++ b/drivers/video/mbx/mbxfb.c
@@ -950,7 +950,7 @@ static int __devinit mbxfb_probe(struct platform_device *dev)
950 950
951 mfbi->fb_virt_addr = ioremap_nocache(mfbi->fb_phys_addr, 951 mfbi->fb_virt_addr = ioremap_nocache(mfbi->fb_phys_addr,
952 res_size(mfbi->fb_req)); 952 res_size(mfbi->fb_req));
953 if (!mfbi->reg_virt_addr) { 953 if (!mfbi->fb_virt_addr) {
954 dev_err(&dev->dev, "failed to ioremap frame buffer\n"); 954 dev_err(&dev->dev, "failed to ioremap frame buffer\n");
955 ret = -EINVAL; 955 ret = -EINVAL;
956 goto err4; 956 goto err4;
diff --git a/drivers/video/mxsfb.c b/drivers/video/mxsfb.c
index 6c6bc578d0fc..abbe691047bd 100644
--- a/drivers/video/mxsfb.c
+++ b/drivers/video/mxsfb.c
@@ -889,6 +889,18 @@ static int __devexit mxsfb_remove(struct platform_device *pdev)
889 return 0; 889 return 0;
890} 890}
891 891
892static void mxsfb_shutdown(struct platform_device *pdev)
893{
894 struct fb_info *fb_info = platform_get_drvdata(pdev);
895 struct mxsfb_info *host = to_imxfb_host(fb_info);
896
897 /*
898 * Force stop the LCD controller as keeping it running during reboot
899 * might interfere with the BootROM's boot mode pads sampling.
900 */
901 writel(CTRL_RUN, host->base + LCDC_CTRL + REG_CLR);
902}
903
892static struct platform_device_id mxsfb_devtype[] = { 904static struct platform_device_id mxsfb_devtype[] = {
893 { 905 {
894 .name = "imx23-fb", 906 .name = "imx23-fb",
@@ -905,6 +917,7 @@ MODULE_DEVICE_TABLE(platform, mxsfb_devtype);
905static struct platform_driver mxsfb_driver = { 917static struct platform_driver mxsfb_driver = {
906 .probe = mxsfb_probe, 918 .probe = mxsfb_probe,
907 .remove = __devexit_p(mxsfb_remove), 919 .remove = __devexit_p(mxsfb_remove),
920 .shutdown = mxsfb_shutdown,
908 .id_table = mxsfb_devtype, 921 .id_table = mxsfb_devtype,
909 .driver = { 922 .driver = {
910 .name = DRIVER_NAME, 923 .name = DRIVER_NAME,
diff --git a/drivers/video/omap/Kconfig b/drivers/video/omap/Kconfig
index 1e7536d9a8fc..b48f95f0dfe2 100644
--- a/drivers/video/omap/Kconfig
+++ b/drivers/video/omap/Kconfig
@@ -39,14 +39,6 @@ config FB_OMAP_LCD_MIPID
39 the Mobile Industry Processor Interface DBI-C/DCS 39 the Mobile Industry Processor Interface DBI-C/DCS
40 specification. (Supported LCDs: Philips LPH8923, Sharp LS041Y3) 40 specification. (Supported LCDs: Philips LPH8923, Sharp LS041Y3)
41 41
42config FB_OMAP_BOOTLOADER_INIT
43 bool "Check bootloader initialization"
44 depends on FB_OMAP
45 help
46 Say Y here if you want to enable checking if the bootloader has
47 already initialized the display controller. In this case the
48 driver will skip the initialization.
49
50config FB_OMAP_CONSISTENT_DMA_SIZE 42config FB_OMAP_CONSISTENT_DMA_SIZE
51 int "Consistent DMA memory size (MB)" 43 int "Consistent DMA memory size (MB)"
52 depends on FB_OMAP 44 depends on FB_OMAP
diff --git a/drivers/video/omap2/displays/panel-acx565akm.c b/drivers/video/omap2/displays/panel-acx565akm.c
index 74e7cf078505..ad741c3d1ae1 100644
--- a/drivers/video/omap2/displays/panel-acx565akm.c
+++ b/drivers/video/omap2/displays/panel-acx565akm.c
@@ -739,12 +739,6 @@ static void acx_panel_set_timings(struct omap_dss_device *dssdev,
739 } 739 }
740} 740}
741 741
742static void acx_panel_get_timings(struct omap_dss_device *dssdev,
743 struct omap_video_timings *timings)
744{
745 *timings = dssdev->panel.timings;
746}
747
748static int acx_panel_check_timings(struct omap_dss_device *dssdev, 742static int acx_panel_check_timings(struct omap_dss_device *dssdev,
749 struct omap_video_timings *timings) 743 struct omap_video_timings *timings)
750{ 744{
@@ -762,7 +756,6 @@ static struct omap_dss_driver acx_panel_driver = {
762 .resume = acx_panel_resume, 756 .resume = acx_panel_resume,
763 757
764 .set_timings = acx_panel_set_timings, 758 .set_timings = acx_panel_set_timings,
765 .get_timings = acx_panel_get_timings,
766 .check_timings = acx_panel_check_timings, 759 .check_timings = acx_panel_check_timings,
767 760
768 .get_recommended_bpp = acx_get_recommended_bpp, 761 .get_recommended_bpp = acx_get_recommended_bpp,
diff --git a/drivers/video/omap2/displays/panel-generic-dpi.c b/drivers/video/omap2/displays/panel-generic-dpi.c
index 30fe4dfeb227..e42f9dc22123 100644
--- a/drivers/video/omap2/displays/panel-generic-dpi.c
+++ b/drivers/video/omap2/displays/panel-generic-dpi.c
@@ -386,6 +386,106 @@ static struct panel_config generic_dpi_panels[] = {
386 386
387 .name = "innolux_at080tn52", 387 .name = "innolux_at080tn52",
388 }, 388 },
389
390 /* Mitsubishi AA084SB01 */
391 {
392 {
393 .x_res = 800,
394 .y_res = 600,
395 .pixel_clock = 40000,
396
397 .hsw = 1,
398 .hfp = 254,
399 .hbp = 1,
400
401 .vsw = 1,
402 .vfp = 26,
403 .vbp = 1,
404 },
405 .config = OMAP_DSS_LCD_TFT,
406 .name = "mitsubishi_aa084sb01",
407 },
408 /* EDT ET0500G0DH6 */
409 {
410 {
411 .x_res = 800,
412 .y_res = 480,
413 .pixel_clock = 33260,
414
415 .hsw = 128,
416 .hfp = 216,
417 .hbp = 40,
418
419 .vsw = 2,
420 .vfp = 35,
421 .vbp = 10,
422 },
423 .config = OMAP_DSS_LCD_TFT,
424 .name = "edt_et0500g0dh6",
425 },
426
427 /* Prime-View PD050VL1 */
428 {
429 {
430 .x_res = 640,
431 .y_res = 480,
432
433 .pixel_clock = 25000,
434
435 .hsw = 96,
436 .hfp = 18,
437 .hbp = 46,
438
439 .vsw = 2,
440 .vfp = 10,
441 .vbp = 33,
442 },
443 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
444 OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IPC,
445 .name = "primeview_pd050vl1",
446 },
447
448 /* Prime-View PM070WL4 */
449 {
450 {
451 .x_res = 800,
452 .y_res = 480,
453
454 .pixel_clock = 32000,
455
456 .hsw = 128,
457 .hfp = 42,
458 .hbp = 86,
459
460 .vsw = 2,
461 .vfp = 10,
462 .vbp = 33,
463 },
464 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
465 OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IPC,
466 .name = "primeview_pm070wl4",
467 },
468
469 /* Prime-View PD104SLF */
470 {
471 {
472 .x_res = 800,
473 .y_res = 600,
474
475 .pixel_clock = 40000,
476
477 .hsw = 128,
478 .hfp = 42,
479 .hbp = 86,
480
481 .vsw = 4,
482 .vfp = 1,
483 .vbp = 23,
484 },
485 .config = OMAP_DSS_LCD_TFT | OMAP_DSS_LCD_IVS |
486 OMAP_DSS_LCD_IHS | OMAP_DSS_LCD_IPC,
487 .name = "primeview_pd104slf",
488 },
389}; 489};
390 490
391struct panel_drv_data { 491struct panel_drv_data {
@@ -549,12 +649,6 @@ static void generic_dpi_panel_set_timings(struct omap_dss_device *dssdev,
549 dpi_set_timings(dssdev, timings); 649 dpi_set_timings(dssdev, timings);
550} 650}
551 651
552static void generic_dpi_panel_get_timings(struct omap_dss_device *dssdev,
553 struct omap_video_timings *timings)
554{
555 *timings = dssdev->panel.timings;
556}
557
558static int generic_dpi_panel_check_timings(struct omap_dss_device *dssdev, 652static int generic_dpi_panel_check_timings(struct omap_dss_device *dssdev,
559 struct omap_video_timings *timings) 653 struct omap_video_timings *timings)
560{ 654{
@@ -571,7 +665,6 @@ static struct omap_dss_driver dpi_driver = {
571 .resume = generic_dpi_panel_resume, 665 .resume = generic_dpi_panel_resume,
572 666
573 .set_timings = generic_dpi_panel_set_timings, 667 .set_timings = generic_dpi_panel_set_timings,
574 .get_timings = generic_dpi_panel_get_timings,
575 .check_timings = generic_dpi_panel_check_timings, 668 .check_timings = generic_dpi_panel_check_timings,
576 669
577 .driver = { 670 .driver = {
diff --git a/drivers/video/omap2/displays/panel-n8x0.c b/drivers/video/omap2/displays/panel-n8x0.c
index dc9408dc93d1..4a34cdc1371b 100644
--- a/drivers/video/omap2/displays/panel-n8x0.c
+++ b/drivers/video/omap2/displays/panel-n8x0.c
@@ -610,12 +610,6 @@ static int n8x0_panel_resume(struct omap_dss_device *dssdev)
610 return 0; 610 return 0;
611} 611}
612 612
613static void n8x0_panel_get_timings(struct omap_dss_device *dssdev,
614 struct omap_video_timings *timings)
615{
616 *timings = dssdev->panel.timings;
617}
618
619static void n8x0_panel_get_resolution(struct omap_dss_device *dssdev, 613static void n8x0_panel_get_resolution(struct omap_dss_device *dssdev,
620 u16 *xres, u16 *yres) 614 u16 *xres, u16 *yres)
621{ 615{
@@ -678,8 +672,6 @@ static struct omap_dss_driver n8x0_panel_driver = {
678 .get_resolution = n8x0_panel_get_resolution, 672 .get_resolution = n8x0_panel_get_resolution,
679 .get_recommended_bpp = omapdss_default_get_recommended_bpp, 673 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
680 674
681 .get_timings = n8x0_panel_get_timings,
682
683 .driver = { 675 .driver = {
684 .name = "n8x0_panel", 676 .name = "n8x0_panel",
685 .owner = THIS_MODULE, 677 .owner = THIS_MODULE,
diff --git a/drivers/video/omap2/displays/panel-taal.c b/drivers/video/omap2/displays/panel-taal.c
index b2dd88b48420..2ce9992f403b 100644
--- a/drivers/video/omap2/displays/panel-taal.c
+++ b/drivers/video/omap2/displays/panel-taal.c
@@ -30,7 +30,6 @@
30#include <linux/gpio.h> 30#include <linux/gpio.h>
31#include <linux/workqueue.h> 31#include <linux/workqueue.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/regulator/consumer.h>
34#include <linux/mutex.h> 33#include <linux/mutex.h>
35 34
36#include <video/omapdss.h> 35#include <video/omapdss.h>
@@ -55,73 +54,6 @@ static int _taal_enable_te(struct omap_dss_device *dssdev, bool enable);
55 54
56static int taal_panel_reset(struct omap_dss_device *dssdev); 55static int taal_panel_reset(struct omap_dss_device *dssdev);
57 56
58struct panel_regulator {
59 struct regulator *regulator;
60 const char *name;
61 int min_uV;
62 int max_uV;
63};
64
65static void free_regulators(struct panel_regulator *regulators, int n)
66{
67 int i;
68
69 for (i = 0; i < n; i++) {
70 /* disable/put in reverse order */
71 regulator_disable(regulators[n - i - 1].regulator);
72 regulator_put(regulators[n - i - 1].regulator);
73 }
74}
75
76static int init_regulators(struct omap_dss_device *dssdev,
77 struct panel_regulator *regulators, int n)
78{
79 int r, i, v;
80
81 for (i = 0; i < n; i++) {
82 struct regulator *reg;
83
84 reg = regulator_get(&dssdev->dev, regulators[i].name);
85 if (IS_ERR(reg)) {
86 dev_err(&dssdev->dev, "failed to get regulator %s\n",
87 regulators[i].name);
88 r = PTR_ERR(reg);
89 goto err;
90 }
91
92 /* FIXME: better handling of fixed vs. variable regulators */
93 v = regulator_get_voltage(reg);
94 if (v < regulators[i].min_uV || v > regulators[i].max_uV) {
95 r = regulator_set_voltage(reg, regulators[i].min_uV,
96 regulators[i].max_uV);
97 if (r) {
98 dev_err(&dssdev->dev,
99 "failed to set regulator %s voltage\n",
100 regulators[i].name);
101 regulator_put(reg);
102 goto err;
103 }
104 }
105
106 r = regulator_enable(reg);
107 if (r) {
108 dev_err(&dssdev->dev, "failed to enable regulator %s\n",
109 regulators[i].name);
110 regulator_put(reg);
111 goto err;
112 }
113
114 regulators[i].regulator = reg;
115 }
116
117 return 0;
118
119err:
120 free_regulators(regulators, i);
121
122 return r;
123}
124
125/** 57/**
126 * struct panel_config - panel configuration 58 * struct panel_config - panel configuration
127 * @name: panel name 59 * @name: panel name
@@ -150,8 +82,6 @@ struct panel_config {
150 unsigned int low; 82 unsigned int low;
151 } reset_sequence; 83 } reset_sequence;
152 84
153 struct panel_regulator *regulators;
154 int num_regulators;
155}; 85};
156 86
157enum { 87enum {
@@ -577,12 +507,6 @@ static const struct backlight_ops taal_bl_ops = {
577 .update_status = taal_bl_update_status, 507 .update_status = taal_bl_update_status,
578}; 508};
579 509
580static void taal_get_timings(struct omap_dss_device *dssdev,
581 struct omap_video_timings *timings)
582{
583 *timings = dssdev->panel.timings;
584}
585
586static void taal_get_resolution(struct omap_dss_device *dssdev, 510static void taal_get_resolution(struct omap_dss_device *dssdev,
587 u16 *xres, u16 *yres) 511 u16 *xres, u16 *yres)
588{ 512{
@@ -977,11 +901,6 @@ static int taal_probe(struct omap_dss_device *dssdev)
977 901
978 atomic_set(&td->do_update, 0); 902 atomic_set(&td->do_update, 0);
979 903
980 r = init_regulators(dssdev, panel_config->regulators,
981 panel_config->num_regulators);
982 if (r)
983 goto err_reg;
984
985 td->workqueue = create_singlethread_workqueue("taal_esd"); 904 td->workqueue = create_singlethread_workqueue("taal_esd");
986 if (td->workqueue == NULL) { 905 if (td->workqueue == NULL) {
987 dev_err(&dssdev->dev, "can't create ESD workqueue\n"); 906 dev_err(&dssdev->dev, "can't create ESD workqueue\n");
@@ -1087,8 +1006,6 @@ err_bl:
1087err_rst_gpio: 1006err_rst_gpio:
1088 destroy_workqueue(td->workqueue); 1007 destroy_workqueue(td->workqueue);
1089err_wq: 1008err_wq:
1090 free_regulators(panel_config->regulators, panel_config->num_regulators);
1091err_reg:
1092 kfree(td); 1009 kfree(td);
1093err: 1010err:
1094 return r; 1011 return r;
@@ -1125,9 +1042,6 @@ static void __exit taal_remove(struct omap_dss_device *dssdev)
1125 /* reset, to be sure that the panel is in a valid state */ 1042 /* reset, to be sure that the panel is in a valid state */
1126 taal_hw_reset(dssdev); 1043 taal_hw_reset(dssdev);
1127 1044
1128 free_regulators(td->panel_config->regulators,
1129 td->panel_config->num_regulators);
1130
1131 if (gpio_is_valid(panel_data->reset_gpio)) 1045 if (gpio_is_valid(panel_data->reset_gpio))
1132 gpio_free(panel_data->reset_gpio); 1046 gpio_free(panel_data->reset_gpio);
1133 1047
@@ -1909,8 +1823,6 @@ static struct omap_dss_driver taal_driver = {
1909 .run_test = taal_run_test, 1823 .run_test = taal_run_test,
1910 .memory_read = taal_memory_read, 1824 .memory_read = taal_memory_read,
1911 1825
1912 .get_timings = taal_get_timings,
1913
1914 .driver = { 1826 .driver = {
1915 .name = "taal", 1827 .name = "taal",
1916 .owner = THIS_MODULE, 1828 .owner = THIS_MODULE,
diff --git a/drivers/video/omap2/displays/panel-tfp410.c b/drivers/video/omap2/displays/panel-tfp410.c
index 52637fa8fda8..bff306e041ca 100644
--- a/drivers/video/omap2/displays/panel-tfp410.c
+++ b/drivers/video/omap2/displays/panel-tfp410.c
@@ -47,13 +47,9 @@ struct panel_drv_data {
47 struct mutex lock; 47 struct mutex lock;
48 48
49 int pd_gpio; 49 int pd_gpio;
50};
51 50
52static inline struct tfp410_platform_data 51 struct i2c_adapter *i2c_adapter;
53*get_pdata(const struct omap_dss_device *dssdev) 52};
54{
55 return dssdev->data;
56}
57 53
58static int tfp410_power_on(struct omap_dss_device *dssdev) 54static int tfp410_power_on(struct omap_dss_device *dssdev)
59{ 55{
@@ -68,7 +64,7 @@ static int tfp410_power_on(struct omap_dss_device *dssdev)
68 goto err0; 64 goto err0;
69 65
70 if (gpio_is_valid(ddata->pd_gpio)) 66 if (gpio_is_valid(ddata->pd_gpio))
71 gpio_set_value(ddata->pd_gpio, 1); 67 gpio_set_value_cansleep(ddata->pd_gpio, 1);
72 68
73 return 0; 69 return 0;
74err0: 70err0:
@@ -83,18 +79,18 @@ static void tfp410_power_off(struct omap_dss_device *dssdev)
83 return; 79 return;
84 80
85 if (gpio_is_valid(ddata->pd_gpio)) 81 if (gpio_is_valid(ddata->pd_gpio))
86 gpio_set_value(ddata->pd_gpio, 0); 82 gpio_set_value_cansleep(ddata->pd_gpio, 0);
87 83
88 omapdss_dpi_display_disable(dssdev); 84 omapdss_dpi_display_disable(dssdev);
89} 85}
90 86
91static int tfp410_probe(struct omap_dss_device *dssdev) 87static int tfp410_probe(struct omap_dss_device *dssdev)
92{ 88{
93 struct tfp410_platform_data *pdata = get_pdata(dssdev);
94 struct panel_drv_data *ddata; 89 struct panel_drv_data *ddata;
95 int r; 90 int r;
91 int i2c_bus_num;
96 92
97 ddata = kzalloc(sizeof(*ddata), GFP_KERNEL); 93 ddata = devm_kzalloc(&dssdev->dev, sizeof(*ddata), GFP_KERNEL);
98 if (!ddata) 94 if (!ddata)
99 return -ENOMEM; 95 return -ENOMEM;
100 96
@@ -104,10 +100,15 @@ static int tfp410_probe(struct omap_dss_device *dssdev)
104 ddata->dssdev = dssdev; 100 ddata->dssdev = dssdev;
105 mutex_init(&ddata->lock); 101 mutex_init(&ddata->lock);
106 102
107 if (pdata) 103 if (dssdev->data) {
104 struct tfp410_platform_data *pdata = dssdev->data;
105
108 ddata->pd_gpio = pdata->power_down_gpio; 106 ddata->pd_gpio = pdata->power_down_gpio;
109 else 107 i2c_bus_num = pdata->i2c_bus_num;
108 } else {
110 ddata->pd_gpio = -1; 109 ddata->pd_gpio = -1;
110 i2c_bus_num = -1;
111 }
111 112
112 if (gpio_is_valid(ddata->pd_gpio)) { 113 if (gpio_is_valid(ddata->pd_gpio)) {
113 r = gpio_request_one(ddata->pd_gpio, GPIOF_OUT_INIT_LOW, 114 r = gpio_request_one(ddata->pd_gpio, GPIOF_OUT_INIT_LOW,
@@ -115,13 +116,31 @@ static int tfp410_probe(struct omap_dss_device *dssdev)
115 if (r) { 116 if (r) {
116 dev_err(&dssdev->dev, "Failed to request PD GPIO %d\n", 117 dev_err(&dssdev->dev, "Failed to request PD GPIO %d\n",
117 ddata->pd_gpio); 118 ddata->pd_gpio);
118 ddata->pd_gpio = -1; 119 return r;
119 } 120 }
120 } 121 }
121 122
123 if (i2c_bus_num != -1) {
124 struct i2c_adapter *adapter;
125
126 adapter = i2c_get_adapter(i2c_bus_num);
127 if (!adapter) {
128 dev_err(&dssdev->dev, "Failed to get I2C adapter, bus %d\n",
129 i2c_bus_num);
130 r = -EINVAL;
131 goto err_i2c;
132 }
133
134 ddata->i2c_adapter = adapter;
135 }
136
122 dev_set_drvdata(&dssdev->dev, ddata); 137 dev_set_drvdata(&dssdev->dev, ddata);
123 138
124 return 0; 139 return 0;
140err_i2c:
141 if (gpio_is_valid(ddata->pd_gpio))
142 gpio_free(ddata->pd_gpio);
143 return r;
125} 144}
126 145
127static void __exit tfp410_remove(struct omap_dss_device *dssdev) 146static void __exit tfp410_remove(struct omap_dss_device *dssdev)
@@ -130,14 +149,15 @@ static void __exit tfp410_remove(struct omap_dss_device *dssdev)
130 149
131 mutex_lock(&ddata->lock); 150 mutex_lock(&ddata->lock);
132 151
152 if (ddata->i2c_adapter)
153 i2c_put_adapter(ddata->i2c_adapter);
154
133 if (gpio_is_valid(ddata->pd_gpio)) 155 if (gpio_is_valid(ddata->pd_gpio))
134 gpio_free(ddata->pd_gpio); 156 gpio_free(ddata->pd_gpio);
135 157
136 dev_set_drvdata(&dssdev->dev, NULL); 158 dev_set_drvdata(&dssdev->dev, NULL);
137 159
138 mutex_unlock(&ddata->lock); 160 mutex_unlock(&ddata->lock);
139
140 kfree(ddata);
141} 161}
142 162
143static int tfp410_enable(struct omap_dss_device *dssdev) 163static int tfp410_enable(struct omap_dss_device *dssdev)
@@ -269,27 +289,17 @@ static int tfp410_read_edid(struct omap_dss_device *dssdev,
269 u8 *edid, int len) 289 u8 *edid, int len)
270{ 290{
271 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev); 291 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
272 struct tfp410_platform_data *pdata = get_pdata(dssdev);
273 struct i2c_adapter *adapter;
274 int r, l, bytes_read; 292 int r, l, bytes_read;
275 293
276 mutex_lock(&ddata->lock); 294 mutex_lock(&ddata->lock);
277 295
278 if (pdata->i2c_bus_num == 0) { 296 if (!ddata->i2c_adapter) {
279 r = -ENODEV; 297 r = -ENODEV;
280 goto err; 298 goto err;
281 } 299 }
282 300
283 adapter = i2c_get_adapter(pdata->i2c_bus_num);
284 if (!adapter) {
285 dev_err(&dssdev->dev, "Failed to get I2C adapter, bus %d\n",
286 pdata->i2c_bus_num);
287 r = -EINVAL;
288 goto err;
289 }
290
291 l = min(EDID_LENGTH, len); 301 l = min(EDID_LENGTH, len);
292 r = tfp410_ddc_read(adapter, edid, l, 0); 302 r = tfp410_ddc_read(ddata->i2c_adapter, edid, l, 0);
293 if (r) 303 if (r)
294 goto err; 304 goto err;
295 305
@@ -299,7 +309,7 @@ static int tfp410_read_edid(struct omap_dss_device *dssdev,
299 if (len > EDID_LENGTH && edid[0x7e] > 0) { 309 if (len > EDID_LENGTH && edid[0x7e] > 0) {
300 l = min(EDID_LENGTH, len - EDID_LENGTH); 310 l = min(EDID_LENGTH, len - EDID_LENGTH);
301 311
302 r = tfp410_ddc_read(adapter, edid + EDID_LENGTH, 312 r = tfp410_ddc_read(ddata->i2c_adapter, edid + EDID_LENGTH,
303 l, EDID_LENGTH); 313 l, EDID_LENGTH);
304 if (r) 314 if (r)
305 goto err; 315 goto err;
@@ -319,21 +329,15 @@ err:
319static bool tfp410_detect(struct omap_dss_device *dssdev) 329static bool tfp410_detect(struct omap_dss_device *dssdev)
320{ 330{
321 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev); 331 struct panel_drv_data *ddata = dev_get_drvdata(&dssdev->dev);
322 struct tfp410_platform_data *pdata = get_pdata(dssdev);
323 struct i2c_adapter *adapter;
324 unsigned char out; 332 unsigned char out;
325 int r; 333 int r;
326 334
327 mutex_lock(&ddata->lock); 335 mutex_lock(&ddata->lock);
328 336
329 if (pdata->i2c_bus_num == 0) 337 if (!ddata->i2c_adapter)
330 goto out;
331
332 adapter = i2c_get_adapter(pdata->i2c_bus_num);
333 if (!adapter)
334 goto out; 338 goto out;
335 339
336 r = tfp410_ddc_read(adapter, &out, 1, 0); 340 r = tfp410_ddc_read(ddata->i2c_adapter, &out, 1, 0);
337 341
338 mutex_unlock(&ddata->lock); 342 mutex_unlock(&ddata->lock);
339 343
diff --git a/drivers/video/omap2/displays/panel-tpo-td043mtea1.c b/drivers/video/omap2/displays/panel-tpo-td043mtea1.c
index 32f3fcd7f0f0..4b6448b3c31f 100644
--- a/drivers/video/omap2/displays/panel-tpo-td043mtea1.c
+++ b/drivers/video/omap2/displays/panel-tpo-td043mtea1.c
@@ -272,13 +272,16 @@ static const struct omap_video_timings tpo_td043_timings = {
272static int tpo_td043_power_on(struct tpo_td043_device *tpo_td043) 272static int tpo_td043_power_on(struct tpo_td043_device *tpo_td043)
273{ 273{
274 int nreset_gpio = tpo_td043->nreset_gpio; 274 int nreset_gpio = tpo_td043->nreset_gpio;
275 int r;
275 276
276 if (tpo_td043->powered_on) 277 if (tpo_td043->powered_on)
277 return 0; 278 return 0;
278 279
279 regulator_enable(tpo_td043->vcc_reg); 280 r = regulator_enable(tpo_td043->vcc_reg);
281 if (r != 0)
282 return r;
280 283
281 /* wait for regulator to stabilize */ 284 /* wait for panel to stabilize */
282 msleep(160); 285 msleep(160);
283 286
284 if (gpio_is_valid(nreset_gpio)) 287 if (gpio_is_valid(nreset_gpio))
@@ -470,6 +473,18 @@ static void tpo_td043_remove(struct omap_dss_device *dssdev)
470 gpio_free(nreset_gpio); 473 gpio_free(nreset_gpio);
471} 474}
472 475
476static void tpo_td043_set_timings(struct omap_dss_device *dssdev,
477 struct omap_video_timings *timings)
478{
479 dpi_set_timings(dssdev, timings);
480}
481
482static int tpo_td043_check_timings(struct omap_dss_device *dssdev,
483 struct omap_video_timings *timings)
484{
485 return dpi_check_timings(dssdev, timings);
486}
487
473static struct omap_dss_driver tpo_td043_driver = { 488static struct omap_dss_driver tpo_td043_driver = {
474 .probe = tpo_td043_probe, 489 .probe = tpo_td043_probe,
475 .remove = tpo_td043_remove, 490 .remove = tpo_td043_remove,
@@ -481,6 +496,9 @@ static struct omap_dss_driver tpo_td043_driver = {
481 .set_mirror = tpo_td043_set_hmirror, 496 .set_mirror = tpo_td043_set_hmirror,
482 .get_mirror = tpo_td043_get_hmirror, 497 .get_mirror = tpo_td043_get_hmirror,
483 498
499 .set_timings = tpo_td043_set_timings,
500 .check_timings = tpo_td043_check_timings,
501
484 .driver = { 502 .driver = {
485 .name = "tpo_td043mtea1_panel", 503 .name = "tpo_td043mtea1_panel",
486 .owner = THIS_MODULE, 504 .owner = THIS_MODULE,
diff --git a/drivers/video/omap2/dss/Kconfig b/drivers/video/omap2/dss/Kconfig
index 7be7c06a249e..43324e5ed25f 100644
--- a/drivers/video/omap2/dss/Kconfig
+++ b/drivers/video/omap2/dss/Kconfig
@@ -68,6 +68,10 @@ config OMAP4_DSS_HDMI
68 HDMI Interface. This adds the High Definition Multimedia Interface. 68 HDMI Interface. This adds the High Definition Multimedia Interface.
69 See http://www.hdmi.org/ for HDMI specification. 69 See http://www.hdmi.org/ for HDMI specification.
70 70
71config OMAP4_DSS_HDMI_AUDIO
72 bool
73 depends on OMAP4_DSS_HDMI
74
71config OMAP2_DSS_SDI 75config OMAP2_DSS_SDI
72 bool "SDI support" 76 bool "SDI support"
73 depends on ARCH_OMAP3 77 depends on ARCH_OMAP3
@@ -90,15 +94,6 @@ config OMAP2_DSS_DSI
90 94
91 See http://www.mipi.org/ for DSI spesifications. 95 See http://www.mipi.org/ for DSI spesifications.
92 96
93config OMAP2_DSS_FAKE_VSYNC
94 bool "Fake VSYNC irq from manual update displays"
95 default n
96 help
97 If this is selected, DSI will generate a fake DISPC VSYNC interrupt
98 when DSI has sent a frame. This is only needed with DSI or RFBI
99 displays using manual mode, and you want VSYNC to, for example,
100 time animation.
101
102config OMAP2_DSS_MIN_FCK_PER_PCK 97config OMAP2_DSS_MIN_FCK_PER_PCK
103 int "Minimum FCK/PCK ratio (for scaling)" 98 int "Minimum FCK/PCK ratio (for scaling)"
104 range 0 32 99 range 0 32
diff --git a/drivers/video/omap2/dss/apply.c b/drivers/video/omap2/dss/apply.c
index b10b3bc1931e..ab22cc224f3e 100644
--- a/drivers/video/omap2/dss/apply.c
+++ b/drivers/video/omap2/dss/apply.c
@@ -99,6 +99,11 @@ struct mgr_priv_data {
99 99
100 /* If true, a display is enabled using this manager */ 100 /* If true, a display is enabled using this manager */
101 bool enabled; 101 bool enabled;
102
103 bool extra_info_dirty;
104 bool shadow_extra_info_dirty;
105
106 struct omap_video_timings timings;
102}; 107};
103 108
104static struct { 109static struct {
@@ -176,7 +181,7 @@ static bool mgr_manual_update(struct omap_overlay_manager *mgr)
176} 181}
177 182
178static int dss_check_settings_low(struct omap_overlay_manager *mgr, 183static int dss_check_settings_low(struct omap_overlay_manager *mgr,
179 struct omap_dss_device *dssdev, bool applying) 184 bool applying)
180{ 185{
181 struct omap_overlay_info *oi; 186 struct omap_overlay_info *oi;
182 struct omap_overlay_manager_info *mi; 187 struct omap_overlay_manager_info *mi;
@@ -187,6 +192,9 @@ static int dss_check_settings_low(struct omap_overlay_manager *mgr,
187 192
188 mp = get_mgr_priv(mgr); 193 mp = get_mgr_priv(mgr);
189 194
195 if (!mp->enabled)
196 return 0;
197
190 if (applying && mp->user_info_dirty) 198 if (applying && mp->user_info_dirty)
191 mi = &mp->user_info; 199 mi = &mp->user_info;
192 else 200 else
@@ -206,26 +214,24 @@ static int dss_check_settings_low(struct omap_overlay_manager *mgr,
206 ois[ovl->id] = oi; 214 ois[ovl->id] = oi;
207 } 215 }
208 216
209 return dss_mgr_check(mgr, dssdev, mi, ois); 217 return dss_mgr_check(mgr, mi, &mp->timings, ois);
210} 218}
211 219
212/* 220/*
213 * check manager and overlay settings using overlay_info from data->info 221 * check manager and overlay settings using overlay_info from data->info
214 */ 222 */
215static int dss_check_settings(struct omap_overlay_manager *mgr, 223static int dss_check_settings(struct omap_overlay_manager *mgr)
216 struct omap_dss_device *dssdev)
217{ 224{
218 return dss_check_settings_low(mgr, dssdev, false); 225 return dss_check_settings_low(mgr, false);
219} 226}
220 227
221/* 228/*
222 * check manager and overlay settings using overlay_info from ovl->info if 229 * check manager and overlay settings using overlay_info from ovl->info if
223 * dirty and from data->info otherwise 230 * dirty and from data->info otherwise
224 */ 231 */
225static int dss_check_settings_apply(struct omap_overlay_manager *mgr, 232static int dss_check_settings_apply(struct omap_overlay_manager *mgr)
226 struct omap_dss_device *dssdev)
227{ 233{
228 return dss_check_settings_low(mgr, dssdev, true); 234 return dss_check_settings_low(mgr, true);
229} 235}
230 236
231static bool need_isr(void) 237static bool need_isr(void)
@@ -261,6 +267,20 @@ static bool need_isr(void)
261 if (mp->shadow_info_dirty) 267 if (mp->shadow_info_dirty)
262 return true; 268 return true;
263 269
270 /*
271 * NOTE: we don't check extra_info flags for disabled
272 * managers, once the manager is enabled, the extra_info
273 * related manager changes will be taken in by HW.
274 */
275
276 /* to write new values to registers */
277 if (mp->extra_info_dirty)
278 return true;
279
280 /* to set GO bit */
281 if (mp->shadow_extra_info_dirty)
282 return true;
283
264 list_for_each_entry(ovl, &mgr->overlays, list) { 284 list_for_each_entry(ovl, &mgr->overlays, list) {
265 struct ovl_priv_data *op; 285 struct ovl_priv_data *op;
266 286
@@ -305,7 +325,7 @@ static bool need_go(struct omap_overlay_manager *mgr)
305 325
306 mp = get_mgr_priv(mgr); 326 mp = get_mgr_priv(mgr);
307 327
308 if (mp->shadow_info_dirty) 328 if (mp->shadow_info_dirty || mp->shadow_extra_info_dirty)
309 return true; 329 return true;
310 330
311 list_for_each_entry(ovl, &mgr->overlays, list) { 331 list_for_each_entry(ovl, &mgr->overlays, list) {
@@ -320,20 +340,16 @@ static bool need_go(struct omap_overlay_manager *mgr)
320/* returns true if an extra_info field is currently being updated */ 340/* returns true if an extra_info field is currently being updated */
321static bool extra_info_update_ongoing(void) 341static bool extra_info_update_ongoing(void)
322{ 342{
323 const int num_ovls = omap_dss_get_num_overlays(); 343 const int num_mgrs = dss_feat_get_num_mgrs();
324 struct ovl_priv_data *op;
325 struct omap_overlay *ovl;
326 struct mgr_priv_data *mp;
327 int i; 344 int i;
328 345
329 for (i = 0; i < num_ovls; ++i) { 346 for (i = 0; i < num_mgrs; ++i) {
330 ovl = omap_dss_get_overlay(i); 347 struct omap_overlay_manager *mgr;
331 op = get_ovl_priv(ovl); 348 struct omap_overlay *ovl;
332 349 struct mgr_priv_data *mp;
333 if (!ovl->manager)
334 continue;
335 350
336 mp = get_mgr_priv(ovl->manager); 351 mgr = omap_dss_get_overlay_manager(i);
352 mp = get_mgr_priv(mgr);
337 353
338 if (!mp->enabled) 354 if (!mp->enabled)
339 continue; 355 continue;
@@ -341,8 +357,15 @@ static bool extra_info_update_ongoing(void)
341 if (!mp->updating) 357 if (!mp->updating)
342 continue; 358 continue;
343 359
344 if (op->extra_info_dirty || op->shadow_extra_info_dirty) 360 if (mp->extra_info_dirty || mp->shadow_extra_info_dirty)
345 return true; 361 return true;
362
363 list_for_each_entry(ovl, &mgr->overlays, list) {
364 struct ovl_priv_data *op = get_ovl_priv(ovl);
365
366 if (op->extra_info_dirty || op->shadow_extra_info_dirty)
367 return true;
368 }
346 } 369 }
347 370
348 return false; 371 return false;
@@ -525,11 +548,13 @@ static void dss_ovl_write_regs(struct omap_overlay *ovl)
525 548
526 oi = &op->info; 549 oi = &op->info;
527 550
551 mp = get_mgr_priv(ovl->manager);
552
528 replication = dss_use_replication(ovl->manager->device, oi->color_mode); 553 replication = dss_use_replication(ovl->manager->device, oi->color_mode);
529 554
530 ilace = ovl->manager->device->type == OMAP_DISPLAY_TYPE_VENC; 555 ilace = ovl->manager->device->type == OMAP_DISPLAY_TYPE_VENC;
531 556
532 r = dispc_ovl_setup(ovl->id, oi, ilace, replication); 557 r = dispc_ovl_setup(ovl->id, oi, ilace, replication, &mp->timings);
533 if (r) { 558 if (r) {
534 /* 559 /*
535 * We can't do much here, as this function can be called from 560 * We can't do much here, as this function can be called from
@@ -543,8 +568,6 @@ static void dss_ovl_write_regs(struct omap_overlay *ovl)
543 return; 568 return;
544 } 569 }
545 570
546 mp = get_mgr_priv(ovl->manager);
547
548 op->info_dirty = false; 571 op->info_dirty = false;
549 if (mp->updating) 572 if (mp->updating)
550 op->shadow_info_dirty = true; 573 op->shadow_info_dirty = true;
@@ -601,6 +624,22 @@ static void dss_mgr_write_regs(struct omap_overlay_manager *mgr)
601 } 624 }
602} 625}
603 626
627static void dss_mgr_write_regs_extra(struct omap_overlay_manager *mgr)
628{
629 struct mgr_priv_data *mp = get_mgr_priv(mgr);
630
631 DSSDBGF("%d", mgr->id);
632
633 if (!mp->extra_info_dirty)
634 return;
635
636 dispc_mgr_set_timings(mgr->id, &mp->timings);
637
638 mp->extra_info_dirty = false;
639 if (mp->updating)
640 mp->shadow_extra_info_dirty = true;
641}
642
604static void dss_write_regs_common(void) 643static void dss_write_regs_common(void)
605{ 644{
606 const int num_mgrs = omap_dss_get_num_overlay_managers(); 645 const int num_mgrs = omap_dss_get_num_overlay_managers();
@@ -646,7 +685,7 @@ static void dss_write_regs(void)
646 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy) 685 if (!mp->enabled || mgr_manual_update(mgr) || mp->busy)
647 continue; 686 continue;
648 687
649 r = dss_check_settings(mgr, mgr->device); 688 r = dss_check_settings(mgr);
650 if (r) { 689 if (r) {
651 DSSERR("cannot write registers for manager %s: " 690 DSSERR("cannot write registers for manager %s: "
652 "illegal configuration\n", mgr->name); 691 "illegal configuration\n", mgr->name);
@@ -654,6 +693,7 @@ static void dss_write_regs(void)
654 } 693 }
655 694
656 dss_mgr_write_regs(mgr); 695 dss_mgr_write_regs(mgr);
696 dss_mgr_write_regs_extra(mgr);
657 } 697 }
658} 698}
659 699
@@ -693,6 +733,7 @@ static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
693 733
694 mp = get_mgr_priv(mgr); 734 mp = get_mgr_priv(mgr);
695 mp->shadow_info_dirty = false; 735 mp->shadow_info_dirty = false;
736 mp->shadow_extra_info_dirty = false;
696 737
697 list_for_each_entry(ovl, &mgr->overlays, list) { 738 list_for_each_entry(ovl, &mgr->overlays, list) {
698 op = get_ovl_priv(ovl); 739 op = get_ovl_priv(ovl);
@@ -711,7 +752,7 @@ void dss_mgr_start_update(struct omap_overlay_manager *mgr)
711 752
712 WARN_ON(mp->updating); 753 WARN_ON(mp->updating);
713 754
714 r = dss_check_settings(mgr, mgr->device); 755 r = dss_check_settings(mgr);
715 if (r) { 756 if (r) {
716 DSSERR("cannot start manual update: illegal configuration\n"); 757 DSSERR("cannot start manual update: illegal configuration\n");
717 spin_unlock_irqrestore(&data_lock, flags); 758 spin_unlock_irqrestore(&data_lock, flags);
@@ -719,6 +760,7 @@ void dss_mgr_start_update(struct omap_overlay_manager *mgr)
719 } 760 }
720 761
721 dss_mgr_write_regs(mgr); 762 dss_mgr_write_regs(mgr);
763 dss_mgr_write_regs_extra(mgr);
722 764
723 dss_write_regs_common(); 765 dss_write_regs_common();
724 766
@@ -857,7 +899,7 @@ int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
857 899
858 spin_lock_irqsave(&data_lock, flags); 900 spin_lock_irqsave(&data_lock, flags);
859 901
860 r = dss_check_settings_apply(mgr, mgr->device); 902 r = dss_check_settings_apply(mgr);
861 if (r) { 903 if (r) {
862 spin_unlock_irqrestore(&data_lock, flags); 904 spin_unlock_irqrestore(&data_lock, flags);
863 DSSERR("failed to apply settings: illegal configuration.\n"); 905 DSSERR("failed to apply settings: illegal configuration.\n");
@@ -918,16 +960,13 @@ static void dss_ovl_setup_fifo(struct omap_overlay *ovl,
918 bool use_fifo_merge) 960 bool use_fifo_merge)
919{ 961{
920 struct ovl_priv_data *op = get_ovl_priv(ovl); 962 struct ovl_priv_data *op = get_ovl_priv(ovl);
921 struct omap_dss_device *dssdev;
922 u32 fifo_low, fifo_high; 963 u32 fifo_low, fifo_high;
923 964
924 if (!op->enabled && !op->enabling) 965 if (!op->enabled && !op->enabling)
925 return; 966 return;
926 967
927 dssdev = ovl->manager->device;
928
929 dispc_ovl_compute_fifo_thresholds(ovl->id, &fifo_low, &fifo_high, 968 dispc_ovl_compute_fifo_thresholds(ovl->id, &fifo_low, &fifo_high,
930 use_fifo_merge); 969 use_fifo_merge, ovl_manual_update(ovl));
931 970
932 dss_apply_ovl_fifo_thresholds(ovl, fifo_low, fifo_high); 971 dss_apply_ovl_fifo_thresholds(ovl, fifo_low, fifo_high);
933} 972}
@@ -1050,7 +1089,7 @@ int dss_mgr_enable(struct omap_overlay_manager *mgr)
1050 1089
1051 mp->enabled = true; 1090 mp->enabled = true;
1052 1091
1053 r = dss_check_settings(mgr, mgr->device); 1092 r = dss_check_settings(mgr);
1054 if (r) { 1093 if (r) {
1055 DSSERR("failed to enable manager %d: check_settings failed\n", 1094 DSSERR("failed to enable manager %d: check_settings failed\n",
1056 mgr->id); 1095 mgr->id);
@@ -1225,6 +1264,35 @@ err:
1225 return r; 1264 return r;
1226} 1265}
1227 1266
1267static void dss_apply_mgr_timings(struct omap_overlay_manager *mgr,
1268 struct omap_video_timings *timings)
1269{
1270 struct mgr_priv_data *mp = get_mgr_priv(mgr);
1271
1272 mp->timings = *timings;
1273 mp->extra_info_dirty = true;
1274}
1275
1276void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
1277 struct omap_video_timings *timings)
1278{
1279 unsigned long flags;
1280
1281 mutex_lock(&apply_lock);
1282
1283 spin_lock_irqsave(&data_lock, flags);
1284
1285 dss_apply_mgr_timings(mgr, timings);
1286
1287 dss_write_regs();
1288 dss_set_go_bits();
1289
1290 spin_unlock_irqrestore(&data_lock, flags);
1291
1292 wait_pending_extra_info_updates();
1293
1294 mutex_unlock(&apply_lock);
1295}
1228 1296
1229int dss_ovl_set_info(struct omap_overlay *ovl, 1297int dss_ovl_set_info(struct omap_overlay *ovl,
1230 struct omap_overlay_info *info) 1298 struct omap_overlay_info *info)
@@ -1393,7 +1461,7 @@ int dss_ovl_enable(struct omap_overlay *ovl)
1393 1461
1394 op->enabling = true; 1462 op->enabling = true;
1395 1463
1396 r = dss_check_settings(ovl->manager, ovl->manager->device); 1464 r = dss_check_settings(ovl->manager);
1397 if (r) { 1465 if (r) {
1398 DSSERR("failed to enable overlay %d: check_settings failed\n", 1466 DSSERR("failed to enable overlay %d: check_settings failed\n",
1399 ovl->id); 1467 ovl->id);
diff --git a/drivers/video/omap2/dss/core.c b/drivers/video/omap2/dss/core.c
index e8a120771ac6..72ded9cd2cb0 100644
--- a/drivers/video/omap2/dss/core.c
+++ b/drivers/video/omap2/dss/core.c
@@ -43,6 +43,8 @@ static struct {
43 43
44 struct regulator *vdds_dsi_reg; 44 struct regulator *vdds_dsi_reg;
45 struct regulator *vdds_sdi_reg; 45 struct regulator *vdds_sdi_reg;
46
47 const char *default_display_name;
46} core; 48} core;
47 49
48static char *def_disp_name; 50static char *def_disp_name;
@@ -54,9 +56,6 @@ bool dss_debug;
54module_param_named(debug, dss_debug, bool, 0644); 56module_param_named(debug, dss_debug, bool, 0644);
55#endif 57#endif
56 58
57static int omap_dss_register_device(struct omap_dss_device *);
58static void omap_dss_unregister_device(struct omap_dss_device *);
59
60/* REGULATORS */ 59/* REGULATORS */
61 60
62struct regulator *dss_get_vdds_dsi(void) 61struct regulator *dss_get_vdds_dsi(void)
@@ -87,6 +86,51 @@ struct regulator *dss_get_vdds_sdi(void)
87 return reg; 86 return reg;
88} 87}
89 88
89int dss_get_ctx_loss_count(struct device *dev)
90{
91 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
92 int cnt;
93
94 if (!board_data->get_context_loss_count)
95 return -ENOENT;
96
97 cnt = board_data->get_context_loss_count(dev);
98
99 WARN_ONCE(cnt < 0, "get_context_loss_count failed: %d\n", cnt);
100
101 return cnt;
102}
103
104int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask)
105{
106 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
107
108 if (!board_data->dsi_enable_pads)
109 return -ENOENT;
110
111 return board_data->dsi_enable_pads(dsi_id, lane_mask);
112}
113
114void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask)
115{
116 struct omap_dss_board_info *board_data = core.pdev->dev.platform_data;
117
118 if (!board_data->dsi_enable_pads)
119 return;
120
121 return board_data->dsi_disable_pads(dsi_id, lane_mask);
122}
123
124int dss_set_min_bus_tput(struct device *dev, unsigned long tput)
125{
126 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
127
128 if (pdata->set_min_bus_tput)
129 return pdata->set_min_bus_tput(dev, tput);
130 else
131 return 0;
132}
133
90#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT) 134#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
91static int dss_debug_show(struct seq_file *s, void *unused) 135static int dss_debug_show(struct seq_file *s, void *unused)
92{ 136{
@@ -121,34 +165,6 @@ static int dss_initialize_debugfs(void)
121 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir, 165 debugfs_create_file("clk", S_IRUGO, dss_debugfs_dir,
122 &dss_debug_dump_clocks, &dss_debug_fops); 166 &dss_debug_dump_clocks, &dss_debug_fops);
123 167
124#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
125 debugfs_create_file("dispc_irq", S_IRUGO, dss_debugfs_dir,
126 &dispc_dump_irqs, &dss_debug_fops);
127#endif
128
129#if defined(CONFIG_OMAP2_DSS_DSI) && defined(CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS)
130 dsi_create_debugfs_files_irq(dss_debugfs_dir, &dss_debug_fops);
131#endif
132
133 debugfs_create_file("dss", S_IRUGO, dss_debugfs_dir,
134 &dss_dump_regs, &dss_debug_fops);
135 debugfs_create_file("dispc", S_IRUGO, dss_debugfs_dir,
136 &dispc_dump_regs, &dss_debug_fops);
137#ifdef CONFIG_OMAP2_DSS_RFBI
138 debugfs_create_file("rfbi", S_IRUGO, dss_debugfs_dir,
139 &rfbi_dump_regs, &dss_debug_fops);
140#endif
141#ifdef CONFIG_OMAP2_DSS_DSI
142 dsi_create_debugfs_files_reg(dss_debugfs_dir, &dss_debug_fops);
143#endif
144#ifdef CONFIG_OMAP2_DSS_VENC
145 debugfs_create_file("venc", S_IRUGO, dss_debugfs_dir,
146 &venc_dump_regs, &dss_debug_fops);
147#endif
148#ifdef CONFIG_OMAP4_DSS_HDMI
149 debugfs_create_file("hdmi", S_IRUGO, dss_debugfs_dir,
150 &hdmi_dump_regs, &dss_debug_fops);
151#endif
152 return 0; 168 return 0;
153} 169}
154 170
@@ -157,6 +173,19 @@ static void dss_uninitialize_debugfs(void)
157 if (dss_debugfs_dir) 173 if (dss_debugfs_dir)
158 debugfs_remove_recursive(dss_debugfs_dir); 174 debugfs_remove_recursive(dss_debugfs_dir);
159} 175}
176
177int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
178{
179 struct dentry *d;
180
181 d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
182 write, &dss_debug_fops);
183
184 if (IS_ERR(d))
185 return PTR_ERR(d);
186
187 return 0;
188}
160#else /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */ 189#else /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
161static inline int dss_initialize_debugfs(void) 190static inline int dss_initialize_debugfs(void)
162{ 191{
@@ -165,14 +194,18 @@ static inline int dss_initialize_debugfs(void)
165static inline void dss_uninitialize_debugfs(void) 194static inline void dss_uninitialize_debugfs(void)
166{ 195{
167} 196}
197static inline int dss_debugfs_create_file(const char *name,
198 void (*write)(struct seq_file *))
199{
200 return 0;
201}
168#endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */ 202#endif /* CONFIG_DEBUG_FS && CONFIG_OMAP2_DSS_DEBUG_SUPPORT */
169 203
170/* PLATFORM DEVICE */ 204/* PLATFORM DEVICE */
171static int omap_dss_probe(struct platform_device *pdev) 205static int __init omap_dss_probe(struct platform_device *pdev)
172{ 206{
173 struct omap_dss_board_info *pdata = pdev->dev.platform_data; 207 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
174 int r; 208 int r;
175 int i;
176 209
177 core.pdev = pdev; 210 core.pdev = pdev;
178 211
@@ -187,28 +220,13 @@ static int omap_dss_probe(struct platform_device *pdev)
187 if (r) 220 if (r)
188 goto err_debugfs; 221 goto err_debugfs;
189 222
190 for (i = 0; i < pdata->num_devices; ++i) { 223 if (def_disp_name)
191 struct omap_dss_device *dssdev = pdata->devices[i]; 224 core.default_display_name = def_disp_name;
192 225 else if (pdata->default_device)
193 r = omap_dss_register_device(dssdev); 226 core.default_display_name = pdata->default_device->name;
194 if (r) {
195 DSSERR("device %d %s register failed %d\n", i,
196 dssdev->name ?: "unnamed", r);
197
198 while (--i >= 0)
199 omap_dss_unregister_device(pdata->devices[i]);
200
201 goto err_register;
202 }
203
204 if (def_disp_name && strcmp(def_disp_name, dssdev->name) == 0)
205 pdata->default_device = dssdev;
206 }
207 227
208 return 0; 228 return 0;
209 229
210err_register:
211 dss_uninitialize_debugfs();
212err_debugfs: 230err_debugfs:
213 231
214 return r; 232 return r;
@@ -216,17 +234,11 @@ err_debugfs:
216 234
217static int omap_dss_remove(struct platform_device *pdev) 235static int omap_dss_remove(struct platform_device *pdev)
218{ 236{
219 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
220 int i;
221
222 dss_uninitialize_debugfs(); 237 dss_uninitialize_debugfs();
223 238
224 dss_uninit_overlays(pdev); 239 dss_uninit_overlays(pdev);
225 dss_uninit_overlay_managers(pdev); 240 dss_uninit_overlay_managers(pdev);
226 241
227 for (i = 0; i < pdata->num_devices; ++i)
228 omap_dss_unregister_device(pdata->devices[i]);
229
230 return 0; 242 return 0;
231} 243}
232 244
@@ -251,7 +263,6 @@ static int omap_dss_resume(struct platform_device *pdev)
251} 263}
252 264
253static struct platform_driver omap_dss_driver = { 265static struct platform_driver omap_dss_driver = {
254 .probe = omap_dss_probe,
255 .remove = omap_dss_remove, 266 .remove = omap_dss_remove,
256 .shutdown = omap_dss_shutdown, 267 .shutdown = omap_dss_shutdown,
257 .suspend = omap_dss_suspend, 268 .suspend = omap_dss_suspend,
@@ -326,7 +337,6 @@ static int dss_driver_probe(struct device *dev)
326 int r; 337 int r;
327 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver); 338 struct omap_dss_driver *dssdrv = to_dss_driver(dev->driver);
328 struct omap_dss_device *dssdev = to_dss_device(dev); 339 struct omap_dss_device *dssdev = to_dss_device(dev);
329 struct omap_dss_board_info *pdata = core.pdev->dev.platform_data;
330 bool force; 340 bool force;
331 341
332 DSSDBG("driver_probe: dev %s/%s, drv %s\n", 342 DSSDBG("driver_probe: dev %s/%s, drv %s\n",
@@ -335,7 +345,8 @@ static int dss_driver_probe(struct device *dev)
335 345
336 dss_init_device(core.pdev, dssdev); 346 dss_init_device(core.pdev, dssdev);
337 347
338 force = pdata->default_device == dssdev; 348 force = core.default_display_name &&
349 strcmp(core.default_display_name, dssdev->name) == 0;
339 dss_recheck_connections(dssdev, force); 350 dss_recheck_connections(dssdev, force);
340 351
341 r = dssdrv->probe(dssdev); 352 r = dssdrv->probe(dssdev);
@@ -381,6 +392,8 @@ int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
381 if (dssdriver->get_recommended_bpp == NULL) 392 if (dssdriver->get_recommended_bpp == NULL)
382 dssdriver->get_recommended_bpp = 393 dssdriver->get_recommended_bpp =
383 omapdss_default_get_recommended_bpp; 394 omapdss_default_get_recommended_bpp;
395 if (dssdriver->get_timings == NULL)
396 dssdriver->get_timings = omapdss_default_get_timings;
384 397
385 return driver_register(&dssdriver->driver); 398 return driver_register(&dssdriver->driver);
386} 399}
@@ -427,27 +440,38 @@ static void omap_dss_dev_release(struct device *dev)
427 reset_device(dev, 0); 440 reset_device(dev, 0);
428} 441}
429 442
430static int omap_dss_register_device(struct omap_dss_device *dssdev) 443int omap_dss_register_device(struct omap_dss_device *dssdev,
444 struct device *parent, int disp_num)
431{ 445{
432 static int dev_num;
433
434 WARN_ON(!dssdev->driver_name); 446 WARN_ON(!dssdev->driver_name);
435 447
436 reset_device(&dssdev->dev, 1); 448 reset_device(&dssdev->dev, 1);
437 dssdev->dev.bus = &dss_bus_type; 449 dssdev->dev.bus = &dss_bus_type;
438 dssdev->dev.parent = &dss_bus; 450 dssdev->dev.parent = parent;
439 dssdev->dev.release = omap_dss_dev_release; 451 dssdev->dev.release = omap_dss_dev_release;
440 dev_set_name(&dssdev->dev, "display%d", dev_num++); 452 dev_set_name(&dssdev->dev, "display%d", disp_num);
441 return device_register(&dssdev->dev); 453 return device_register(&dssdev->dev);
442} 454}
443 455
444static void omap_dss_unregister_device(struct omap_dss_device *dssdev) 456void omap_dss_unregister_device(struct omap_dss_device *dssdev)
445{ 457{
446 device_unregister(&dssdev->dev); 458 device_unregister(&dssdev->dev);
447} 459}
448 460
461static int dss_unregister_dss_dev(struct device *dev, void *data)
462{
463 struct omap_dss_device *dssdev = to_dss_device(dev);
464 omap_dss_unregister_device(dssdev);
465 return 0;
466}
467
468void omap_dss_unregister_child_devices(struct device *parent)
469{
470 device_for_each_child(parent, NULL, dss_unregister_dss_dev);
471}
472
449/* BUS */ 473/* BUS */
450static int omap_dss_bus_register(void) 474static int __init omap_dss_bus_register(void)
451{ 475{
452 int r; 476 int r;
453 477
@@ -469,12 +493,56 @@ static int omap_dss_bus_register(void)
469} 493}
470 494
471/* INIT */ 495/* INIT */
496static int (*dss_output_drv_reg_funcs[])(void) __initdata = {
497#ifdef CONFIG_OMAP2_DSS_DPI
498 dpi_init_platform_driver,
499#endif
500#ifdef CONFIG_OMAP2_DSS_SDI
501 sdi_init_platform_driver,
502#endif
503#ifdef CONFIG_OMAP2_DSS_RFBI
504 rfbi_init_platform_driver,
505#endif
506#ifdef CONFIG_OMAP2_DSS_VENC
507 venc_init_platform_driver,
508#endif
509#ifdef CONFIG_OMAP2_DSS_DSI
510 dsi_init_platform_driver,
511#endif
512#ifdef CONFIG_OMAP4_DSS_HDMI
513 hdmi_init_platform_driver,
514#endif
515};
516
517static void (*dss_output_drv_unreg_funcs[])(void) __exitdata = {
518#ifdef CONFIG_OMAP2_DSS_DPI
519 dpi_uninit_platform_driver,
520#endif
521#ifdef CONFIG_OMAP2_DSS_SDI
522 sdi_uninit_platform_driver,
523#endif
524#ifdef CONFIG_OMAP2_DSS_RFBI
525 rfbi_uninit_platform_driver,
526#endif
527#ifdef CONFIG_OMAP2_DSS_VENC
528 venc_uninit_platform_driver,
529#endif
530#ifdef CONFIG_OMAP2_DSS_DSI
531 dsi_uninit_platform_driver,
532#endif
533#ifdef CONFIG_OMAP4_DSS_HDMI
534 hdmi_uninit_platform_driver,
535#endif
536};
537
538static bool dss_output_drv_loaded[ARRAY_SIZE(dss_output_drv_reg_funcs)];
472 539
473static int __init omap_dss_register_drivers(void) 540static int __init omap_dss_register_drivers(void)
474{ 541{
475 int r; 542 int r;
543 int i;
476 544
477 r = platform_driver_register(&omap_dss_driver); 545 r = platform_driver_probe(&omap_dss_driver, omap_dss_probe);
478 if (r) 546 if (r)
479 return r; 547 return r;
480 548
@@ -490,40 +558,18 @@ static int __init omap_dss_register_drivers(void)
490 goto err_dispc; 558 goto err_dispc;
491 } 559 }
492 560
493 r = rfbi_init_platform_driver(); 561 /*
494 if (r) { 562 * It's ok if the output-driver register fails. It happens, for example,
495 DSSERR("Failed to initialize rfbi platform driver\n"); 563 * when there is no output-device (e.g. SDI for OMAP4).
496 goto err_rfbi; 564 */
497 } 565 for (i = 0; i < ARRAY_SIZE(dss_output_drv_reg_funcs); ++i) {
498 566 r = dss_output_drv_reg_funcs[i]();
499 r = venc_init_platform_driver(); 567 if (r == 0)
500 if (r) { 568 dss_output_drv_loaded[i] = true;
501 DSSERR("Failed to initialize venc platform driver\n");
502 goto err_venc;
503 }
504
505 r = dsi_init_platform_driver();
506 if (r) {
507 DSSERR("Failed to initialize DSI platform driver\n");
508 goto err_dsi;
509 }
510
511 r = hdmi_init_platform_driver();
512 if (r) {
513 DSSERR("Failed to initialize hdmi\n");
514 goto err_hdmi;
515 } 569 }
516 570
517 return 0; 571 return 0;
518 572
519err_hdmi:
520 dsi_uninit_platform_driver();
521err_dsi:
522 venc_uninit_platform_driver();
523err_venc:
524 rfbi_uninit_platform_driver();
525err_rfbi:
526 dispc_uninit_platform_driver();
527err_dispc: 573err_dispc:
528 dss_uninit_platform_driver(); 574 dss_uninit_platform_driver();
529err_dss: 575err_dss:
@@ -534,10 +580,13 @@ err_dss:
534 580
535static void __exit omap_dss_unregister_drivers(void) 581static void __exit omap_dss_unregister_drivers(void)
536{ 582{
537 hdmi_uninit_platform_driver(); 583 int i;
538 dsi_uninit_platform_driver(); 584
539 venc_uninit_platform_driver(); 585 for (i = 0; i < ARRAY_SIZE(dss_output_drv_unreg_funcs); ++i) {
540 rfbi_uninit_platform_driver(); 586 if (dss_output_drv_loaded[i])
587 dss_output_drv_unreg_funcs[i]();
588 }
589
541 dispc_uninit_platform_driver(); 590 dispc_uninit_platform_driver();
542 dss_uninit_platform_driver(); 591 dss_uninit_platform_driver();
543 592
diff --git a/drivers/video/omap2/dss/dispc.c b/drivers/video/omap2/dss/dispc.c
index ee30937482e1..4749ac356469 100644
--- a/drivers/video/omap2/dss/dispc.c
+++ b/drivers/video/omap2/dss/dispc.c
@@ -131,23 +131,6 @@ static inline u32 dispc_read_reg(const u16 idx)
131 return __raw_readl(dispc.base + idx); 131 return __raw_readl(dispc.base + idx);
132} 132}
133 133
134static int dispc_get_ctx_loss_count(void)
135{
136 struct device *dev = &dispc.pdev->dev;
137 struct omap_display_platform_data *pdata = dev->platform_data;
138 struct omap_dss_board_info *board_data = pdata->board_data;
139 int cnt;
140
141 if (!board_data->get_context_loss_count)
142 return -ENOENT;
143
144 cnt = board_data->get_context_loss_count(dev);
145
146 WARN_ONCE(cnt < 0, "get_context_loss_count failed: %d\n", cnt);
147
148 return cnt;
149}
150
151#define SR(reg) \ 134#define SR(reg) \
152 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg) 135 dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg)
153#define RR(reg) \ 136#define RR(reg) \
@@ -251,7 +234,7 @@ static void dispc_save_context(void)
251 if (dss_has_feature(FEAT_CORE_CLK_DIV)) 234 if (dss_has_feature(FEAT_CORE_CLK_DIV))
252 SR(DIVISOR); 235 SR(DIVISOR);
253 236
254 dispc.ctx_loss_cnt = dispc_get_ctx_loss_count(); 237 dispc.ctx_loss_cnt = dss_get_ctx_loss_count(&dispc.pdev->dev);
255 dispc.ctx_valid = true; 238 dispc.ctx_valid = true;
256 239
257 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt); 240 DSSDBG("context saved, ctx_loss_count %d\n", dispc.ctx_loss_cnt);
@@ -266,7 +249,7 @@ static void dispc_restore_context(void)
266 if (!dispc.ctx_valid) 249 if (!dispc.ctx_valid)
267 return; 250 return;
268 251
269 ctx = dispc_get_ctx_loss_count(); 252 ctx = dss_get_ctx_loss_count(&dispc.pdev->dev);
270 253
271 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt) 254 if (ctx >= 0 && ctx == dispc.ctx_loss_cnt)
272 return; 255 return;
@@ -413,14 +396,6 @@ static inline bool dispc_mgr_is_lcd(enum omap_channel channel)
413 return false; 396 return false;
414} 397}
415 398
416static struct omap_dss_device *dispc_mgr_get_device(enum omap_channel channel)
417{
418 struct omap_overlay_manager *mgr =
419 omap_dss_get_overlay_manager(channel);
420
421 return mgr ? mgr->device : NULL;
422}
423
424u32 dispc_mgr_get_vsync_irq(enum omap_channel channel) 399u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
425{ 400{
426 switch (channel) { 401 switch (channel) {
@@ -432,6 +407,7 @@ u32 dispc_mgr_get_vsync_irq(enum omap_channel channel)
432 return DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN; 407 return DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
433 default: 408 default:
434 BUG(); 409 BUG();
410 return 0;
435 } 411 }
436} 412}
437 413
@@ -446,6 +422,7 @@ u32 dispc_mgr_get_framedone_irq(enum omap_channel channel)
446 return 0; 422 return 0;
447 default: 423 default:
448 BUG(); 424 BUG();
425 return 0;
449 } 426 }
450} 427}
451 428
@@ -764,7 +741,7 @@ static void dispc_ovl_set_color_mode(enum omap_plane plane,
764 case OMAP_DSS_COLOR_XRGB16_1555: 741 case OMAP_DSS_COLOR_XRGB16_1555:
765 m = 0xf; break; 742 m = 0xf; break;
766 default: 743 default:
767 BUG(); break; 744 BUG(); return;
768 } 745 }
769 } else { 746 } else {
770 switch (color_mode) { 747 switch (color_mode) {
@@ -801,13 +778,25 @@ static void dispc_ovl_set_color_mode(enum omap_plane plane,
801 case OMAP_DSS_COLOR_XRGB16_1555: 778 case OMAP_DSS_COLOR_XRGB16_1555:
802 m = 0xf; break; 779 m = 0xf; break;
803 default: 780 default:
804 BUG(); break; 781 BUG(); return;
805 } 782 }
806 } 783 }
807 784
808 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1); 785 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1);
809} 786}
810 787
788static void dispc_ovl_configure_burst_type(enum omap_plane plane,
789 enum omap_dss_rotation_type rotation_type)
790{
791 if (dss_has_feature(FEAT_BURST_2D) == 0)
792 return;
793
794 if (rotation_type == OMAP_DSS_ROT_TILER)
795 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29);
796 else
797 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29);
798}
799
811void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel) 800void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
812{ 801{
813 int shift; 802 int shift;
@@ -845,6 +834,7 @@ void dispc_ovl_set_channel_out(enum omap_plane plane, enum omap_channel channel)
845 break; 834 break;
846 default: 835 default:
847 BUG(); 836 BUG();
837 return;
848 } 838 }
849 839
850 val = FLD_MOD(val, chan, shift, shift); 840 val = FLD_MOD(val, chan, shift, shift);
@@ -872,6 +862,7 @@ static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane plane)
872 break; 862 break;
873 default: 863 default:
874 BUG(); 864 BUG();
865 return 0;
875 } 866 }
876 867
877 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane)); 868 val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane));
@@ -983,20 +974,13 @@ static void dispc_ovl_enable_replication(enum omap_plane plane, bool enable)
983 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift); 974 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift);
984} 975}
985 976
986void dispc_mgr_set_lcd_size(enum omap_channel channel, u16 width, u16 height) 977static void dispc_mgr_set_size(enum omap_channel channel, u16 width,
978 u16 height)
987{ 979{
988 u32 val; 980 u32 val;
989 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
990 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
991 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
992}
993 981
994void dispc_set_digit_size(u16 width, u16 height)
995{
996 u32 val;
997 BUG_ON((width > (1 << 11)) || (height > (1 << 11)));
998 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0); 982 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0);
999 dispc_write_reg(DISPC_SIZE_MGR(OMAP_DSS_CHANNEL_DIGIT), val); 983 dispc_write_reg(DISPC_SIZE_MGR(channel), val);
1000} 984}
1001 985
1002static void dispc_read_plane_fifo_sizes(void) 986static void dispc_read_plane_fifo_sizes(void)
@@ -1063,7 +1047,8 @@ void dispc_enable_fifomerge(bool enable)
1063} 1047}
1064 1048
1065void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane, 1049void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1066 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge) 1050 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
1051 bool manual_update)
1067{ 1052{
1068 /* 1053 /*
1069 * All sizes are in bytes. Both the buffer and burst are made of 1054 * All sizes are in bytes. Both the buffer and burst are made of
@@ -1091,7 +1076,7 @@ void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
1091 * combined fifo size 1076 * combined fifo size
1092 */ 1077 */
1093 1078
1094 if (dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) { 1079 if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) {
1095 *fifo_low = ovl_fifo_size - burst_size * 2; 1080 *fifo_low = ovl_fifo_size - burst_size * 2;
1096 *fifo_high = total_fifo_size - burst_size; 1081 *fifo_high = total_fifo_size - burst_size;
1097 } else { 1082 } else {
@@ -1185,6 +1170,94 @@ static void dispc_ovl_set_scale_param(enum omap_plane plane,
1185 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp); 1170 dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp);
1186} 1171}
1187 1172
1173static void dispc_ovl_set_accu_uv(enum omap_plane plane,
1174 u16 orig_width, u16 orig_height, u16 out_width, u16 out_height,
1175 bool ilace, enum omap_color_mode color_mode, u8 rotation)
1176{
1177 int h_accu2_0, h_accu2_1;
1178 int v_accu2_0, v_accu2_1;
1179 int chroma_hinc, chroma_vinc;
1180 int idx;
1181
1182 struct accu {
1183 s8 h0_m, h0_n;
1184 s8 h1_m, h1_n;
1185 s8 v0_m, v0_n;
1186 s8 v1_m, v1_n;
1187 };
1188
1189 const struct accu *accu_table;
1190 const struct accu *accu_val;
1191
1192 static const struct accu accu_nv12[4] = {
1193 { 0, 1, 0, 1 , -1, 2, 0, 1 },
1194 { 1, 2, -3, 4 , 0, 1, 0, 1 },
1195 { -1, 1, 0, 1 , -1, 2, 0, 1 },
1196 { -1, 2, -1, 2 , -1, 1, 0, 1 },
1197 };
1198
1199 static const struct accu accu_nv12_ilace[4] = {
1200 { 0, 1, 0, 1 , -3, 4, -1, 4 },
1201 { -1, 4, -3, 4 , 0, 1, 0, 1 },
1202 { -1, 1, 0, 1 , -1, 4, -3, 4 },
1203 { -3, 4, -3, 4 , -1, 1, 0, 1 },
1204 };
1205
1206 static const struct accu accu_yuv[4] = {
1207 { 0, 1, 0, 1, 0, 1, 0, 1 },
1208 { 0, 1, 0, 1, 0, 1, 0, 1 },
1209 { -1, 1, 0, 1, 0, 1, 0, 1 },
1210 { 0, 1, 0, 1, -1, 1, 0, 1 },
1211 };
1212
1213 switch (rotation) {
1214 case OMAP_DSS_ROT_0:
1215 idx = 0;
1216 break;
1217 case OMAP_DSS_ROT_90:
1218 idx = 1;
1219 break;
1220 case OMAP_DSS_ROT_180:
1221 idx = 2;
1222 break;
1223 case OMAP_DSS_ROT_270:
1224 idx = 3;
1225 break;
1226 default:
1227 BUG();
1228 return;
1229 }
1230
1231 switch (color_mode) {
1232 case OMAP_DSS_COLOR_NV12:
1233 if (ilace)
1234 accu_table = accu_nv12_ilace;
1235 else
1236 accu_table = accu_nv12;
1237 break;
1238 case OMAP_DSS_COLOR_YUV2:
1239 case OMAP_DSS_COLOR_UYVY:
1240 accu_table = accu_yuv;
1241 break;
1242 default:
1243 BUG();
1244 return;
1245 }
1246
1247 accu_val = &accu_table[idx];
1248
1249 chroma_hinc = 1024 * orig_width / out_width;
1250 chroma_vinc = 1024 * orig_height / out_height;
1251
1252 h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024;
1253 h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024;
1254 v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024;
1255 v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024;
1256
1257 dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0);
1258 dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1);
1259}
1260
1188static void dispc_ovl_set_scaling_common(enum omap_plane plane, 1261static void dispc_ovl_set_scaling_common(enum omap_plane plane,
1189 u16 orig_width, u16 orig_height, 1262 u16 orig_width, u16 orig_height,
1190 u16 out_width, u16 out_height, 1263 u16 out_width, u16 out_height,
@@ -1258,6 +1331,10 @@ static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1258 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8); 1331 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8);
1259 return; 1332 return;
1260 } 1333 }
1334
1335 dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width,
1336 out_height, ilace, color_mode, rotation);
1337
1261 switch (color_mode) { 1338 switch (color_mode) {
1262 case OMAP_DSS_COLOR_NV12: 1339 case OMAP_DSS_COLOR_NV12:
1263 /* UV is subsampled by 2 vertically*/ 1340 /* UV is subsampled by 2 vertically*/
@@ -1280,6 +1357,7 @@ static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1280 break; 1357 break;
1281 default: 1358 default:
1282 BUG(); 1359 BUG();
1360 return;
1283 } 1361 }
1284 1362
1285 if (out_width != orig_width) 1363 if (out_width != orig_width)
@@ -1297,9 +1375,6 @@ static void dispc_ovl_set_scaling_uv(enum omap_plane plane,
1297 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5); 1375 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5);
1298 /* set V scaling */ 1376 /* set V scaling */
1299 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6); 1377 REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6);
1300
1301 dispc_ovl_set_vid_accu2_0(plane, 0x80, 0);
1302 dispc_ovl_set_vid_accu2_1(plane, 0x80, 0);
1303} 1378}
1304 1379
1305static void dispc_ovl_set_scaling(enum omap_plane plane, 1380static void dispc_ovl_set_scaling(enum omap_plane plane,
@@ -1410,6 +1485,7 @@ static int color_mode_to_bpp(enum omap_color_mode color_mode)
1410 return 32; 1485 return 32;
1411 default: 1486 default:
1412 BUG(); 1487 BUG();
1488 return 0;
1413 } 1489 }
1414} 1490}
1415 1491
@@ -1423,6 +1499,7 @@ static s32 pixinc(int pixels, u8 ps)
1423 return 1 - (-pixels + 1) * ps; 1499 return 1 - (-pixels + 1) * ps;
1424 else 1500 else
1425 BUG(); 1501 BUG();
1502 return 0;
1426} 1503}
1427 1504
1428static void calc_vrfb_rotation_offset(u8 rotation, bool mirror, 1505static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
@@ -1431,7 +1508,7 @@ static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1431 enum omap_color_mode color_mode, bool fieldmode, 1508 enum omap_color_mode color_mode, bool fieldmode,
1432 unsigned int field_offset, 1509 unsigned int field_offset,
1433 unsigned *offset0, unsigned *offset1, 1510 unsigned *offset0, unsigned *offset1,
1434 s32 *row_inc, s32 *pix_inc) 1511 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1435{ 1512{
1436 u8 ps; 1513 u8 ps;
1437 1514
@@ -1477,10 +1554,10 @@ static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1477 else 1554 else
1478 *offset0 = 0; 1555 *offset0 = 0;
1479 1556
1480 *row_inc = pixinc(1 + (screen_width - width) + 1557 *row_inc = pixinc(1 +
1481 (fieldmode ? screen_width : 0), 1558 (y_predecim * screen_width - x_predecim * width) +
1482 ps); 1559 (fieldmode ? screen_width : 0), ps);
1483 *pix_inc = pixinc(1, ps); 1560 *pix_inc = pixinc(x_predecim, ps);
1484 break; 1561 break;
1485 1562
1486 case OMAP_DSS_ROT_0 + 4: 1563 case OMAP_DSS_ROT_0 + 4:
@@ -1498,14 +1575,15 @@ static void calc_vrfb_rotation_offset(u8 rotation, bool mirror,
1498 *offset0 = field_offset * screen_width * ps; 1575 *offset0 = field_offset * screen_width * ps;
1499 else 1576 else
1500 *offset0 = 0; 1577 *offset0 = 0;
1501 *row_inc = pixinc(1 - (screen_width + width) - 1578 *row_inc = pixinc(1 -
1502 (fieldmode ? screen_width : 0), 1579 (y_predecim * screen_width + x_predecim * width) -
1503 ps); 1580 (fieldmode ? screen_width : 0), ps);
1504 *pix_inc = pixinc(1, ps); 1581 *pix_inc = pixinc(x_predecim, ps);
1505 break; 1582 break;
1506 1583
1507 default: 1584 default:
1508 BUG(); 1585 BUG();
1586 return;
1509 } 1587 }
1510} 1588}
1511 1589
@@ -1515,7 +1593,7 @@ static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1515 enum omap_color_mode color_mode, bool fieldmode, 1593 enum omap_color_mode color_mode, bool fieldmode,
1516 unsigned int field_offset, 1594 unsigned int field_offset,
1517 unsigned *offset0, unsigned *offset1, 1595 unsigned *offset0, unsigned *offset1,
1518 s32 *row_inc, s32 *pix_inc) 1596 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1519{ 1597{
1520 u8 ps; 1598 u8 ps;
1521 u16 fbw, fbh; 1599 u16 fbw, fbh;
@@ -1557,10 +1635,14 @@ static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1557 *offset0 = *offset1 + field_offset * screen_width * ps; 1635 *offset0 = *offset1 + field_offset * screen_width * ps;
1558 else 1636 else
1559 *offset0 = *offset1; 1637 *offset0 = *offset1;
1560 *row_inc = pixinc(1 + (screen_width - fbw) + 1638 *row_inc = pixinc(1 +
1561 (fieldmode ? screen_width : 0), 1639 (y_predecim * screen_width - fbw * x_predecim) +
1562 ps); 1640 (fieldmode ? screen_width : 0), ps);
1563 *pix_inc = pixinc(1, ps); 1641 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1642 color_mode == OMAP_DSS_COLOR_UYVY)
1643 *pix_inc = pixinc(x_predecim, 2 * ps);
1644 else
1645 *pix_inc = pixinc(x_predecim, ps);
1564 break; 1646 break;
1565 case OMAP_DSS_ROT_90: 1647 case OMAP_DSS_ROT_90:
1566 *offset1 = screen_width * (fbh - 1) * ps; 1648 *offset1 = screen_width * (fbh - 1) * ps;
@@ -1568,9 +1650,9 @@ static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1568 *offset0 = *offset1 + field_offset * ps; 1650 *offset0 = *offset1 + field_offset * ps;
1569 else 1651 else
1570 *offset0 = *offset1; 1652 *offset0 = *offset1;
1571 *row_inc = pixinc(screen_width * (fbh - 1) + 1 + 1653 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) +
1572 (fieldmode ? 1 : 0), ps); 1654 y_predecim + (fieldmode ? 1 : 0), ps);
1573 *pix_inc = pixinc(-screen_width, ps); 1655 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1574 break; 1656 break;
1575 case OMAP_DSS_ROT_180: 1657 case OMAP_DSS_ROT_180:
1576 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps; 1658 *offset1 = (screen_width * (fbh - 1) + fbw - 1) * ps;
@@ -1579,10 +1661,13 @@ static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1579 else 1661 else
1580 *offset0 = *offset1; 1662 *offset0 = *offset1;
1581 *row_inc = pixinc(-1 - 1663 *row_inc = pixinc(-1 -
1582 (screen_width - fbw) - 1664 (y_predecim * screen_width - fbw * x_predecim) -
1583 (fieldmode ? screen_width : 0), 1665 (fieldmode ? screen_width : 0), ps);
1584 ps); 1666 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1585 *pix_inc = pixinc(-1, ps); 1667 color_mode == OMAP_DSS_COLOR_UYVY)
1668 *pix_inc = pixinc(-x_predecim, 2 * ps);
1669 else
1670 *pix_inc = pixinc(-x_predecim, ps);
1586 break; 1671 break;
1587 case OMAP_DSS_ROT_270: 1672 case OMAP_DSS_ROT_270:
1588 *offset1 = (fbw - 1) * ps; 1673 *offset1 = (fbw - 1) * ps;
@@ -1590,9 +1675,9 @@ static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1590 *offset0 = *offset1 - field_offset * ps; 1675 *offset0 = *offset1 - field_offset * ps;
1591 else 1676 else
1592 *offset0 = *offset1; 1677 *offset0 = *offset1;
1593 *row_inc = pixinc(-screen_width * (fbh - 1) - 1 - 1678 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) -
1594 (fieldmode ? 1 : 0), ps); 1679 y_predecim - (fieldmode ? 1 : 0), ps);
1595 *pix_inc = pixinc(screen_width, ps); 1680 *pix_inc = pixinc(x_predecim * screen_width, ps);
1596 break; 1681 break;
1597 1682
1598 /* mirroring */ 1683 /* mirroring */
@@ -1602,10 +1687,14 @@ static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1602 *offset0 = *offset1 + field_offset * screen_width * ps; 1687 *offset0 = *offset1 + field_offset * screen_width * ps;
1603 else 1688 else
1604 *offset0 = *offset1; 1689 *offset0 = *offset1;
1605 *row_inc = pixinc(screen_width * 2 - 1 + 1690 *row_inc = pixinc(y_predecim * screen_width * 2 - 1 +
1606 (fieldmode ? screen_width : 0), 1691 (fieldmode ? screen_width : 0),
1607 ps); 1692 ps);
1608 *pix_inc = pixinc(-1, ps); 1693 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1694 color_mode == OMAP_DSS_COLOR_UYVY)
1695 *pix_inc = pixinc(-x_predecim, 2 * ps);
1696 else
1697 *pix_inc = pixinc(-x_predecim, ps);
1609 break; 1698 break;
1610 1699
1611 case OMAP_DSS_ROT_90 + 4: 1700 case OMAP_DSS_ROT_90 + 4:
@@ -1614,10 +1703,10 @@ static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1614 *offset0 = *offset1 + field_offset * ps; 1703 *offset0 = *offset1 + field_offset * ps;
1615 else 1704 else
1616 *offset0 = *offset1; 1705 *offset0 = *offset1;
1617 *row_inc = pixinc(-screen_width * (fbh - 1) + 1 + 1706 *row_inc = pixinc(-screen_width * (fbh * x_predecim - 1) +
1618 (fieldmode ? 1 : 0), 1707 y_predecim + (fieldmode ? 1 : 0),
1619 ps); 1708 ps);
1620 *pix_inc = pixinc(screen_width, ps); 1709 *pix_inc = pixinc(x_predecim * screen_width, ps);
1621 break; 1710 break;
1622 1711
1623 case OMAP_DSS_ROT_180 + 4: 1712 case OMAP_DSS_ROT_180 + 4:
@@ -1626,10 +1715,14 @@ static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1626 *offset0 = *offset1 - field_offset * screen_width * ps; 1715 *offset0 = *offset1 - field_offset * screen_width * ps;
1627 else 1716 else
1628 *offset0 = *offset1; 1717 *offset0 = *offset1;
1629 *row_inc = pixinc(1 - screen_width * 2 - 1718 *row_inc = pixinc(1 - y_predecim * screen_width * 2 -
1630 (fieldmode ? screen_width : 0), 1719 (fieldmode ? screen_width : 0),
1631 ps); 1720 ps);
1632 *pix_inc = pixinc(1, ps); 1721 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1722 color_mode == OMAP_DSS_COLOR_UYVY)
1723 *pix_inc = pixinc(x_predecim, 2 * ps);
1724 else
1725 *pix_inc = pixinc(x_predecim, ps);
1633 break; 1726 break;
1634 1727
1635 case OMAP_DSS_ROT_270 + 4: 1728 case OMAP_DSS_ROT_270 + 4:
@@ -1638,34 +1731,130 @@ static void calc_dma_rotation_offset(u8 rotation, bool mirror,
1638 *offset0 = *offset1 - field_offset * ps; 1731 *offset0 = *offset1 - field_offset * ps;
1639 else 1732 else
1640 *offset0 = *offset1; 1733 *offset0 = *offset1;
1641 *row_inc = pixinc(screen_width * (fbh - 1) - 1 - 1734 *row_inc = pixinc(screen_width * (fbh * x_predecim - 1) -
1642 (fieldmode ? 1 : 0), 1735 y_predecim - (fieldmode ? 1 : 0),
1643 ps); 1736 ps);
1644 *pix_inc = pixinc(-screen_width, ps); 1737 *pix_inc = pixinc(-x_predecim * screen_width, ps);
1645 break; 1738 break;
1646 1739
1647 default: 1740 default:
1648 BUG(); 1741 BUG();
1742 return;
1743 }
1744}
1745
1746static void calc_tiler_rotation_offset(u16 screen_width, u16 width,
1747 enum omap_color_mode color_mode, bool fieldmode,
1748 unsigned int field_offset, unsigned *offset0, unsigned *offset1,
1749 s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim)
1750{
1751 u8 ps;
1752
1753 switch (color_mode) {
1754 case OMAP_DSS_COLOR_CLUT1:
1755 case OMAP_DSS_COLOR_CLUT2:
1756 case OMAP_DSS_COLOR_CLUT4:
1757 case OMAP_DSS_COLOR_CLUT8:
1758 BUG();
1759 return;
1760 default:
1761 ps = color_mode_to_bpp(color_mode) / 8;
1762 break;
1649 } 1763 }
1764
1765 DSSDBG("scrw %d, width %d\n", screen_width, width);
1766
1767 /*
1768 * field 0 = even field = bottom field
1769 * field 1 = odd field = top field
1770 */
1771 *offset1 = 0;
1772 if (field_offset)
1773 *offset0 = *offset1 + field_offset * screen_width * ps;
1774 else
1775 *offset0 = *offset1;
1776 *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) +
1777 (fieldmode ? screen_width : 0), ps);
1778 if (color_mode == OMAP_DSS_COLOR_YUV2 ||
1779 color_mode == OMAP_DSS_COLOR_UYVY)
1780 *pix_inc = pixinc(x_predecim, 2 * ps);
1781 else
1782 *pix_inc = pixinc(x_predecim, ps);
1650} 1783}
1651 1784
1652static unsigned long calc_fclk_five_taps(enum omap_channel channel, u16 width, 1785/*
1786 * This function is used to avoid synclosts in OMAP3, because of some
1787 * undocumented horizontal position and timing related limitations.
1788 */
1789static int check_horiz_timing_omap3(enum omap_channel channel,
1790 const struct omap_video_timings *t, u16 pos_x,
1791 u16 width, u16 height, u16 out_width, u16 out_height)
1792{
1793 int DS = DIV_ROUND_UP(height, out_height);
1794 unsigned long nonactive, lclk, pclk;
1795 static const u8 limits[3] = { 8, 10, 20 };
1796 u64 val, blank;
1797 int i;
1798
1799 nonactive = t->x_res + t->hfp + t->hsw + t->hbp - out_width;
1800 pclk = dispc_mgr_pclk_rate(channel);
1801 if (dispc_mgr_is_lcd(channel))
1802 lclk = dispc_mgr_lclk_rate(channel);
1803 else
1804 lclk = dispc_fclk_rate();
1805
1806 i = 0;
1807 if (out_height < height)
1808 i++;
1809 if (out_width < width)
1810 i++;
1811 blank = div_u64((u64)(t->hbp + t->hsw + t->hfp) * lclk, pclk);
1812 DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]);
1813 if (blank <= limits[i])
1814 return -EINVAL;
1815
1816 /*
1817 * Pixel data should be prepared before visible display point starts.
1818 * So, atleast DS-2 lines must have already been fetched by DISPC
1819 * during nonactive - pos_x period.
1820 */
1821 val = div_u64((u64)(nonactive - pos_x) * lclk, pclk);
1822 DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n",
1823 val, max(0, DS - 2) * width);
1824 if (val < max(0, DS - 2) * width)
1825 return -EINVAL;
1826
1827 /*
1828 * All lines need to be refilled during the nonactive period of which
1829 * only one line can be loaded during the active period. So, atleast
1830 * DS - 1 lines should be loaded during nonactive period.
1831 */
1832 val = div_u64((u64)nonactive * lclk, pclk);
1833 DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n",
1834 val, max(0, DS - 1) * width);
1835 if (val < max(0, DS - 1) * width)
1836 return -EINVAL;
1837
1838 return 0;
1839}
1840
1841static unsigned long calc_core_clk_five_taps(enum omap_channel channel,
1842 const struct omap_video_timings *mgr_timings, u16 width,
1653 u16 height, u16 out_width, u16 out_height, 1843 u16 height, u16 out_width, u16 out_height,
1654 enum omap_color_mode color_mode) 1844 enum omap_color_mode color_mode)
1655{ 1845{
1656 u32 fclk = 0; 1846 u32 core_clk = 0;
1657 u64 tmp, pclk = dispc_mgr_pclk_rate(channel); 1847 u64 tmp, pclk = dispc_mgr_pclk_rate(channel);
1658 1848
1659 if (height <= out_height && width <= out_width) 1849 if (height <= out_height && width <= out_width)
1660 return (unsigned long) pclk; 1850 return (unsigned long) pclk;
1661 1851
1662 if (height > out_height) { 1852 if (height > out_height) {
1663 struct omap_dss_device *dssdev = dispc_mgr_get_device(channel); 1853 unsigned int ppl = mgr_timings->x_res;
1664 unsigned int ppl = dssdev->panel.timings.x_res;
1665 1854
1666 tmp = pclk * height * out_width; 1855 tmp = pclk * height * out_width;
1667 do_div(tmp, 2 * out_height * ppl); 1856 do_div(tmp, 2 * out_height * ppl);
1668 fclk = tmp; 1857 core_clk = tmp;
1669 1858
1670 if (height > 2 * out_height) { 1859 if (height > 2 * out_height) {
1671 if (ppl == out_width) 1860 if (ppl == out_width)
@@ -1673,23 +1862,23 @@ static unsigned long calc_fclk_five_taps(enum omap_channel channel, u16 width,
1673 1862
1674 tmp = pclk * (height - 2 * out_height) * out_width; 1863 tmp = pclk * (height - 2 * out_height) * out_width;
1675 do_div(tmp, 2 * out_height * (ppl - out_width)); 1864 do_div(tmp, 2 * out_height * (ppl - out_width));
1676 fclk = max(fclk, (u32) tmp); 1865 core_clk = max_t(u32, core_clk, tmp);
1677 } 1866 }
1678 } 1867 }
1679 1868
1680 if (width > out_width) { 1869 if (width > out_width) {
1681 tmp = pclk * width; 1870 tmp = pclk * width;
1682 do_div(tmp, out_width); 1871 do_div(tmp, out_width);
1683 fclk = max(fclk, (u32) tmp); 1872 core_clk = max_t(u32, core_clk, tmp);
1684 1873
1685 if (color_mode == OMAP_DSS_COLOR_RGB24U) 1874 if (color_mode == OMAP_DSS_COLOR_RGB24U)
1686 fclk <<= 1; 1875 core_clk <<= 1;
1687 } 1876 }
1688 1877
1689 return fclk; 1878 return core_clk;
1690} 1879}
1691 1880
1692static unsigned long calc_fclk(enum omap_channel channel, u16 width, 1881static unsigned long calc_core_clk(enum omap_channel channel, u16 width,
1693 u16 height, u16 out_width, u16 out_height) 1882 u16 height, u16 out_width, u16 out_height)
1694{ 1883{
1695 unsigned int hf, vf; 1884 unsigned int hf, vf;
@@ -1730,15 +1919,20 @@ static unsigned long calc_fclk(enum omap_channel channel, u16 width,
1730} 1919}
1731 1920
1732static int dispc_ovl_calc_scaling(enum omap_plane plane, 1921static int dispc_ovl_calc_scaling(enum omap_plane plane,
1733 enum omap_channel channel, u16 width, u16 height, 1922 enum omap_channel channel,
1734 u16 out_width, u16 out_height, 1923 const struct omap_video_timings *mgr_timings,
1735 enum omap_color_mode color_mode, bool *five_taps) 1924 u16 width, u16 height, u16 out_width, u16 out_height,
1925 enum omap_color_mode color_mode, bool *five_taps,
1926 int *x_predecim, int *y_predecim, u16 pos_x)
1736{ 1927{
1737 struct omap_overlay *ovl = omap_dss_get_overlay(plane); 1928 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
1738 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE); 1929 const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE);
1739 const int maxsinglelinewidth = 1930 const int maxsinglelinewidth =
1740 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH); 1931 dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH);
1741 unsigned long fclk = 0; 1932 const int max_decim_limit = 16;
1933 unsigned long core_clk = 0;
1934 int decim_x, decim_y, error, min_factor;
1935 u16 in_width, in_height, in_width_max = 0;
1742 1936
1743 if (width == out_width && height == out_height) 1937 if (width == out_width && height == out_height)
1744 return 0; 1938 return 0;
@@ -1746,64 +1940,154 @@ static int dispc_ovl_calc_scaling(enum omap_plane plane,
1746 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) 1940 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0)
1747 return -EINVAL; 1941 return -EINVAL;
1748 1942
1749 if (out_width < width / maxdownscale || 1943 *x_predecim = max_decim_limit;
1750 out_width > width * 8) 1944 *y_predecim = max_decim_limit;
1945
1946 if (color_mode == OMAP_DSS_COLOR_CLUT1 ||
1947 color_mode == OMAP_DSS_COLOR_CLUT2 ||
1948 color_mode == OMAP_DSS_COLOR_CLUT4 ||
1949 color_mode == OMAP_DSS_COLOR_CLUT8) {
1950 *x_predecim = 1;
1951 *y_predecim = 1;
1952 *five_taps = false;
1953 return 0;
1954 }
1955
1956 decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale);
1957 decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale);
1958
1959 min_factor = min(decim_x, decim_y);
1960
1961 if (decim_x > *x_predecim || out_width > width * 8)
1751 return -EINVAL; 1962 return -EINVAL;
1752 1963
1753 if (out_height < height / maxdownscale || 1964 if (decim_y > *y_predecim || out_height > height * 8)
1754 out_height > height * 8)
1755 return -EINVAL; 1965 return -EINVAL;
1756 1966
1757 if (cpu_is_omap24xx()) { 1967 if (cpu_is_omap24xx()) {
1758 if (width > maxsinglelinewidth)
1759 DSSERR("Cannot scale max input width exceeded");
1760 *five_taps = false; 1968 *five_taps = false;
1761 fclk = calc_fclk(channel, width, height, out_width, 1969
1762 out_height); 1970 do {
1971 in_height = DIV_ROUND_UP(height, decim_y);
1972 in_width = DIV_ROUND_UP(width, decim_x);
1973 core_clk = calc_core_clk(channel, in_width, in_height,
1974 out_width, out_height);
1975 error = (in_width > maxsinglelinewidth || !core_clk ||
1976 core_clk > dispc_core_clk_rate());
1977 if (error) {
1978 if (decim_x == decim_y) {
1979 decim_x = min_factor;
1980 decim_y++;
1981 } else {
1982 swap(decim_x, decim_y);
1983 if (decim_x < decim_y)
1984 decim_x++;
1985 }
1986 }
1987 } while (decim_x <= *x_predecim && decim_y <= *y_predecim &&
1988 error);
1989
1990 if (in_width > maxsinglelinewidth) {
1991 DSSERR("Cannot scale max input width exceeded");
1992 return -EINVAL;
1993 }
1763 } else if (cpu_is_omap34xx()) { 1994 } else if (cpu_is_omap34xx()) {
1764 if (width > (maxsinglelinewidth * 2)) { 1995
1996 do {
1997 in_height = DIV_ROUND_UP(height, decim_y);
1998 in_width = DIV_ROUND_UP(width, decim_x);
1999 core_clk = calc_core_clk_five_taps(channel, mgr_timings,
2000 in_width, in_height, out_width, out_height,
2001 color_mode);
2002
2003 error = check_horiz_timing_omap3(channel, mgr_timings,
2004 pos_x, in_width, in_height, out_width,
2005 out_height);
2006
2007 if (in_width > maxsinglelinewidth)
2008 if (in_height > out_height &&
2009 in_height < out_height * 2)
2010 *five_taps = false;
2011 if (!*five_taps)
2012 core_clk = calc_core_clk(channel, in_width,
2013 in_height, out_width, out_height);
2014 error = (error || in_width > maxsinglelinewidth * 2 ||
2015 (in_width > maxsinglelinewidth && *five_taps) ||
2016 !core_clk || core_clk > dispc_core_clk_rate());
2017 if (error) {
2018 if (decim_x == decim_y) {
2019 decim_x = min_factor;
2020 decim_y++;
2021 } else {
2022 swap(decim_x, decim_y);
2023 if (decim_x < decim_y)
2024 decim_x++;
2025 }
2026 }
2027 } while (decim_x <= *x_predecim && decim_y <= *y_predecim
2028 && error);
2029
2030 if (check_horiz_timing_omap3(channel, mgr_timings, pos_x, width,
2031 height, out_width, out_height)){
2032 DSSERR("horizontal timing too tight\n");
2033 return -EINVAL;
2034 }
2035
2036 if (in_width > (maxsinglelinewidth * 2)) {
1765 DSSERR("Cannot setup scaling"); 2037 DSSERR("Cannot setup scaling");
1766 DSSERR("width exceeds maximum width possible"); 2038 DSSERR("width exceeds maximum width possible");
1767 return -EINVAL; 2039 return -EINVAL;
1768 } 2040 }
1769 fclk = calc_fclk_five_taps(channel, width, height, out_width, 2041
1770 out_height, color_mode); 2042 if (in_width > maxsinglelinewidth && *five_taps) {
1771 if (width > maxsinglelinewidth) { 2043 DSSERR("cannot setup scaling with five taps");
1772 if (height > out_height && height < out_height * 2) 2044 return -EINVAL;
1773 *five_taps = false;
1774 else {
1775 DSSERR("cannot setup scaling with five taps");
1776 return -EINVAL;
1777 }
1778 } 2045 }
1779 if (!*five_taps)
1780 fclk = calc_fclk(channel, width, height, out_width,
1781 out_height);
1782 } else { 2046 } else {
1783 if (width > maxsinglelinewidth) { 2047 int decim_x_min = decim_x;
2048 in_height = DIV_ROUND_UP(height, decim_y);
2049 in_width_max = dispc_core_clk_rate() /
2050 DIV_ROUND_UP(dispc_mgr_pclk_rate(channel),
2051 out_width);
2052 decim_x = DIV_ROUND_UP(width, in_width_max);
2053
2054 decim_x = decim_x > decim_x_min ? decim_x : decim_x_min;
2055 if (decim_x > *x_predecim)
2056 return -EINVAL;
2057
2058 do {
2059 in_width = DIV_ROUND_UP(width, decim_x);
2060 } while (decim_x <= *x_predecim &&
2061 in_width > maxsinglelinewidth && decim_x++);
2062
2063 if (in_width > maxsinglelinewidth) {
1784 DSSERR("Cannot scale width exceeds max line width"); 2064 DSSERR("Cannot scale width exceeds max line width");
1785 return -EINVAL; 2065 return -EINVAL;
1786 } 2066 }
1787 fclk = calc_fclk(channel, width, height, out_width, 2067
1788 out_height); 2068 core_clk = calc_core_clk(channel, in_width, in_height,
2069 out_width, out_height);
1789 } 2070 }
1790 2071
1791 DSSDBG("required fclk rate = %lu Hz\n", fclk); 2072 DSSDBG("required core clk rate = %lu Hz\n", core_clk);
1792 DSSDBG("current fclk rate = %lu Hz\n", dispc_fclk_rate()); 2073 DSSDBG("current core clk rate = %lu Hz\n", dispc_core_clk_rate());
1793 2074
1794 if (!fclk || fclk > dispc_fclk_rate()) { 2075 if (!core_clk || core_clk > dispc_core_clk_rate()) {
1795 DSSERR("failed to set up scaling, " 2076 DSSERR("failed to set up scaling, "
1796 "required fclk rate = %lu Hz, " 2077 "required core clk rate = %lu Hz, "
1797 "current fclk rate = %lu Hz\n", 2078 "current core clk rate = %lu Hz\n",
1798 fclk, dispc_fclk_rate()); 2079 core_clk, dispc_core_clk_rate());
1799 return -EINVAL; 2080 return -EINVAL;
1800 } 2081 }
1801 2082
2083 *x_predecim = decim_x;
2084 *y_predecim = decim_y;
1802 return 0; 2085 return 0;
1803} 2086}
1804 2087
1805int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi, 2088int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
1806 bool ilace, bool replication) 2089 bool ilace, bool replication,
2090 const struct omap_video_timings *mgr_timings)
1807{ 2091{
1808 struct omap_overlay *ovl = omap_dss_get_overlay(plane); 2092 struct omap_overlay *ovl = omap_dss_get_overlay(plane);
1809 bool five_taps = true; 2093 bool five_taps = true;
@@ -1814,8 +2098,11 @@ int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
1814 s32 pix_inc; 2098 s32 pix_inc;
1815 u16 frame_height = oi->height; 2099 u16 frame_height = oi->height;
1816 unsigned int field_offset = 0; 2100 unsigned int field_offset = 0;
1817 u16 outw, outh; 2101 u16 in_height = oi->height;
2102 u16 in_width = oi->width;
2103 u16 out_width, out_height;
1818 enum omap_channel channel; 2104 enum omap_channel channel;
2105 int x_predecim = 1, y_predecim = 1;
1819 2106
1820 channel = dispc_ovl_get_channel_out(plane); 2107 channel = dispc_ovl_get_channel_out(plane);
1821 2108
@@ -1829,32 +2116,35 @@ int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
1829 if (oi->paddr == 0) 2116 if (oi->paddr == 0)
1830 return -EINVAL; 2117 return -EINVAL;
1831 2118
1832 outw = oi->out_width == 0 ? oi->width : oi->out_width; 2119 out_width = oi->out_width == 0 ? oi->width : oi->out_width;
1833 outh = oi->out_height == 0 ? oi->height : oi->out_height; 2120 out_height = oi->out_height == 0 ? oi->height : oi->out_height;
1834 2121
1835 if (ilace && oi->height == outh) 2122 if (ilace && oi->height == out_height)
1836 fieldmode = 1; 2123 fieldmode = 1;
1837 2124
1838 if (ilace) { 2125 if (ilace) {
1839 if (fieldmode) 2126 if (fieldmode)
1840 oi->height /= 2; 2127 in_height /= 2;
1841 oi->pos_y /= 2; 2128 oi->pos_y /= 2;
1842 outh /= 2; 2129 out_height /= 2;
1843 2130
1844 DSSDBG("adjusting for ilace: height %d, pos_y %d, " 2131 DSSDBG("adjusting for ilace: height %d, pos_y %d, "
1845 "out_height %d\n", 2132 "out_height %d\n",
1846 oi->height, oi->pos_y, outh); 2133 in_height, oi->pos_y, out_height);
1847 } 2134 }
1848 2135
1849 if (!dss_feat_color_mode_supported(plane, oi->color_mode)) 2136 if (!dss_feat_color_mode_supported(plane, oi->color_mode))
1850 return -EINVAL; 2137 return -EINVAL;
1851 2138
1852 r = dispc_ovl_calc_scaling(plane, channel, oi->width, oi->height, 2139 r = dispc_ovl_calc_scaling(plane, channel, mgr_timings, in_width,
1853 outw, outh, oi->color_mode, 2140 in_height, out_width, out_height, oi->color_mode,
1854 &five_taps); 2141 &five_taps, &x_predecim, &y_predecim, oi->pos_x);
1855 if (r) 2142 if (r)
1856 return r; 2143 return r;
1857 2144
2145 in_width = DIV_ROUND_UP(in_width, x_predecim);
2146 in_height = DIV_ROUND_UP(in_height, y_predecim);
2147
1858 if (oi->color_mode == OMAP_DSS_COLOR_YUV2 || 2148 if (oi->color_mode == OMAP_DSS_COLOR_YUV2 ||
1859 oi->color_mode == OMAP_DSS_COLOR_UYVY || 2149 oi->color_mode == OMAP_DSS_COLOR_UYVY ||
1860 oi->color_mode == OMAP_DSS_COLOR_NV12) 2150 oi->color_mode == OMAP_DSS_COLOR_NV12)
@@ -1868,32 +2158,46 @@ int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
1868 * so the integer part must be added to the base address of the 2158 * so the integer part must be added to the base address of the
1869 * bottom field. 2159 * bottom field.
1870 */ 2160 */
1871 if (!oi->height || oi->height == outh) 2161 if (!in_height || in_height == out_height)
1872 field_offset = 0; 2162 field_offset = 0;
1873 else 2163 else
1874 field_offset = oi->height / outh / 2; 2164 field_offset = in_height / out_height / 2;
1875 } 2165 }
1876 2166
1877 /* Fields are independent but interleaved in memory. */ 2167 /* Fields are independent but interleaved in memory. */
1878 if (fieldmode) 2168 if (fieldmode)
1879 field_offset = 1; 2169 field_offset = 1;
1880 2170
1881 if (oi->rotation_type == OMAP_DSS_ROT_DMA) 2171 offset0 = 0;
2172 offset1 = 0;
2173 row_inc = 0;
2174 pix_inc = 0;
2175
2176 if (oi->rotation_type == OMAP_DSS_ROT_TILER)
2177 calc_tiler_rotation_offset(oi->screen_width, in_width,
2178 oi->color_mode, fieldmode, field_offset,
2179 &offset0, &offset1, &row_inc, &pix_inc,
2180 x_predecim, y_predecim);
2181 else if (oi->rotation_type == OMAP_DSS_ROT_DMA)
1882 calc_dma_rotation_offset(oi->rotation, oi->mirror, 2182 calc_dma_rotation_offset(oi->rotation, oi->mirror,
1883 oi->screen_width, oi->width, frame_height, 2183 oi->screen_width, in_width, frame_height,
1884 oi->color_mode, fieldmode, field_offset, 2184 oi->color_mode, fieldmode, field_offset,
1885 &offset0, &offset1, &row_inc, &pix_inc); 2185 &offset0, &offset1, &row_inc, &pix_inc,
2186 x_predecim, y_predecim);
1886 else 2187 else
1887 calc_vrfb_rotation_offset(oi->rotation, oi->mirror, 2188 calc_vrfb_rotation_offset(oi->rotation, oi->mirror,
1888 oi->screen_width, oi->width, frame_height, 2189 oi->screen_width, in_width, frame_height,
1889 oi->color_mode, fieldmode, field_offset, 2190 oi->color_mode, fieldmode, field_offset,
1890 &offset0, &offset1, &row_inc, &pix_inc); 2191 &offset0, &offset1, &row_inc, &pix_inc,
2192 x_predecim, y_predecim);
1891 2193
1892 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n", 2194 DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n",
1893 offset0, offset1, row_inc, pix_inc); 2195 offset0, offset1, row_inc, pix_inc);
1894 2196
1895 dispc_ovl_set_color_mode(plane, oi->color_mode); 2197 dispc_ovl_set_color_mode(plane, oi->color_mode);
1896 2198
2199 dispc_ovl_configure_burst_type(plane, oi->rotation_type);
2200
1897 dispc_ovl_set_ba0(plane, oi->paddr + offset0); 2201 dispc_ovl_set_ba0(plane, oi->paddr + offset0);
1898 dispc_ovl_set_ba1(plane, oi->paddr + offset1); 2202 dispc_ovl_set_ba1(plane, oi->paddr + offset1);
1899 2203
@@ -1906,19 +2210,18 @@ int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
1906 dispc_ovl_set_row_inc(plane, row_inc); 2210 dispc_ovl_set_row_inc(plane, row_inc);
1907 dispc_ovl_set_pix_inc(plane, pix_inc); 2211 dispc_ovl_set_pix_inc(plane, pix_inc);
1908 2212
1909 DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, oi->width, 2213 DSSDBG("%d,%d %dx%d -> %dx%d\n", oi->pos_x, oi->pos_y, in_width,
1910 oi->height, outw, outh); 2214 in_height, out_width, out_height);
1911 2215
1912 dispc_ovl_set_pos(plane, oi->pos_x, oi->pos_y); 2216 dispc_ovl_set_pos(plane, oi->pos_x, oi->pos_y);
1913 2217
1914 dispc_ovl_set_pic_size(plane, oi->width, oi->height); 2218 dispc_ovl_set_pic_size(plane, in_width, in_height);
1915 2219
1916 if (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) { 2220 if (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) {
1917 dispc_ovl_set_scaling(plane, oi->width, oi->height, 2221 dispc_ovl_set_scaling(plane, in_width, in_height, out_width,
1918 outw, outh, 2222 out_height, ilace, five_taps, fieldmode,
1919 ilace, five_taps, fieldmode,
1920 oi->color_mode, oi->rotation); 2223 oi->color_mode, oi->rotation);
1921 dispc_ovl_set_vid_size(plane, outw, outh); 2224 dispc_ovl_set_vid_size(plane, out_width, out_height);
1922 dispc_ovl_set_vid_color_conv(plane, cconv); 2225 dispc_ovl_set_vid_color_conv(plane, cconv);
1923 } 2226 }
1924 2227
@@ -2087,8 +2390,10 @@ bool dispc_mgr_is_enabled(enum omap_channel channel)
2087 return !!REG_GET(DISPC_CONTROL, 1, 1); 2390 return !!REG_GET(DISPC_CONTROL, 1, 1);
2088 else if (channel == OMAP_DSS_CHANNEL_LCD2) 2391 else if (channel == OMAP_DSS_CHANNEL_LCD2)
2089 return !!REG_GET(DISPC_CONTROL2, 0, 0); 2392 return !!REG_GET(DISPC_CONTROL2, 0, 0);
2090 else 2393 else {
2091 BUG(); 2394 BUG();
2395 return false;
2396 }
2092} 2397}
2093 2398
2094void dispc_mgr_enable(enum omap_channel channel, bool enable) 2399void dispc_mgr_enable(enum omap_channel channel, bool enable)
@@ -2285,6 +2590,12 @@ void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable)
2285 REG_FLD_MOD(DISPC_CONTROL, enable, 11, 11); 2590 REG_FLD_MOD(DISPC_CONTROL, enable, 11, 11);
2286} 2591}
2287 2592
2593static bool _dispc_mgr_size_ok(u16 width, u16 height)
2594{
2595 return width <= dss_feat_get_param_max(FEAT_PARAM_MGR_WIDTH) &&
2596 height <= dss_feat_get_param_max(FEAT_PARAM_MGR_HEIGHT);
2597}
2598
2288static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp, 2599static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2289 int vsw, int vfp, int vbp) 2600 int vsw, int vfp, int vbp)
2290{ 2601{
@@ -2309,11 +2620,20 @@ static bool _dispc_lcd_timings_ok(int hsw, int hfp, int hbp,
2309 return true; 2620 return true;
2310} 2621}
2311 2622
2312bool dispc_lcd_timings_ok(struct omap_video_timings *timings) 2623bool dispc_mgr_timings_ok(enum omap_channel channel,
2624 const struct omap_video_timings *timings)
2313{ 2625{
2314 return _dispc_lcd_timings_ok(timings->hsw, timings->hfp, 2626 bool timings_ok;
2315 timings->hbp, timings->vsw, 2627
2316 timings->vfp, timings->vbp); 2628 timings_ok = _dispc_mgr_size_ok(timings->x_res, timings->y_res);
2629
2630 if (dispc_mgr_is_lcd(channel))
2631 timings_ok = timings_ok && _dispc_lcd_timings_ok(timings->hsw,
2632 timings->hfp, timings->hbp,
2633 timings->vsw, timings->vfp,
2634 timings->vbp);
2635
2636 return timings_ok;
2317} 2637}
2318 2638
2319static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw, 2639static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
@@ -2340,37 +2660,45 @@ static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, int hsw,
2340} 2660}
2341 2661
2342/* change name to mode? */ 2662/* change name to mode? */
2343void dispc_mgr_set_lcd_timings(enum omap_channel channel, 2663void dispc_mgr_set_timings(enum omap_channel channel,
2344 struct omap_video_timings *timings) 2664 struct omap_video_timings *timings)
2345{ 2665{
2346 unsigned xtot, ytot; 2666 unsigned xtot, ytot;
2347 unsigned long ht, vt; 2667 unsigned long ht, vt;
2668 struct omap_video_timings t = *timings;
2669
2670 DSSDBG("channel %d xres %u yres %u\n", channel, t.x_res, t.y_res);
2348 2671
2349 if (!_dispc_lcd_timings_ok(timings->hsw, timings->hfp, 2672 if (!dispc_mgr_timings_ok(channel, &t)) {
2350 timings->hbp, timings->vsw,
2351 timings->vfp, timings->vbp))
2352 BUG(); 2673 BUG();
2674 return;
2675 }
2676
2677 if (dispc_mgr_is_lcd(channel)) {
2678 _dispc_mgr_set_lcd_timings(channel, t.hsw, t.hfp, t.hbp, t.vsw,
2679 t.vfp, t.vbp);
2680
2681 xtot = t.x_res + t.hfp + t.hsw + t.hbp;
2682 ytot = t.y_res + t.vfp + t.vsw + t.vbp;
2353 2683
2354 _dispc_mgr_set_lcd_timings(channel, timings->hsw, timings->hfp, 2684 ht = (timings->pixel_clock * 1000) / xtot;
2355 timings->hbp, timings->vsw, timings->vfp, 2685 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2356 timings->vbp);
2357 2686
2358 dispc_mgr_set_lcd_size(channel, timings->x_res, timings->y_res); 2687 DSSDBG("pck %u\n", timings->pixel_clock);
2688 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2689 t.hsw, t.hfp, t.hbp, t.vsw, t.vfp, t.vbp);
2359 2690
2360 xtot = timings->x_res + timings->hfp + timings->hsw + timings->hbp; 2691 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt);
2361 ytot = timings->y_res + timings->vfp + timings->vsw + timings->vbp; 2692 } else {
2693 enum dss_hdmi_venc_clk_source_select source;
2362 2694
2363 ht = (timings->pixel_clock * 1000) / xtot; 2695 source = dss_get_hdmi_venc_clk_source();
2364 vt = (timings->pixel_clock * 1000) / xtot / ytot;
2365 2696
2366 DSSDBG("channel %d xres %u yres %u\n", channel, timings->x_res, 2697 if (source == DSS_VENC_TV_CLK)
2367 timings->y_res); 2698 t.y_res /= 2;
2368 DSSDBG("pck %u\n", timings->pixel_clock); 2699 }
2369 DSSDBG("hsw %d hfp %d hbp %d vsw %d vfp %d vbp %d\n",
2370 timings->hsw, timings->hfp, timings->hbp,
2371 timings->vsw, timings->vfp, timings->vbp);
2372 2700
2373 DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt); 2701 dispc_mgr_set_size(channel, t.x_res, t.y_res);
2374} 2702}
2375 2703
2376static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div, 2704static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div,
@@ -2411,6 +2739,7 @@ unsigned long dispc_fclk_rate(void)
2411 break; 2739 break;
2412 default: 2740 default:
2413 BUG(); 2741 BUG();
2742 return 0;
2414 } 2743 }
2415 2744
2416 return r; 2745 return r;
@@ -2441,6 +2770,7 @@ unsigned long dispc_mgr_lclk_rate(enum omap_channel channel)
2441 break; 2770 break;
2442 default: 2771 default:
2443 BUG(); 2772 BUG();
2773 return 0;
2444 } 2774 }
2445 2775
2446 return r / lcd; 2776 return r / lcd;
@@ -2462,20 +2792,35 @@ unsigned long dispc_mgr_pclk_rate(enum omap_channel channel)
2462 2792
2463 return r / pcd; 2793 return r / pcd;
2464 } else { 2794 } else {
2465 struct omap_dss_device *dssdev = 2795 enum dss_hdmi_venc_clk_source_select source;
2466 dispc_mgr_get_device(channel);
2467 2796
2468 switch (dssdev->type) { 2797 source = dss_get_hdmi_venc_clk_source();
2469 case OMAP_DISPLAY_TYPE_VENC: 2798
2799 switch (source) {
2800 case DSS_VENC_TV_CLK:
2470 return venc_get_pixel_clock(); 2801 return venc_get_pixel_clock();
2471 case OMAP_DISPLAY_TYPE_HDMI: 2802 case DSS_HDMI_M_PCLK:
2472 return hdmi_get_pixel_clock(); 2803 return hdmi_get_pixel_clock();
2473 default: 2804 default:
2474 BUG(); 2805 BUG();
2806 return 0;
2475 } 2807 }
2476 } 2808 }
2477} 2809}
2478 2810
2811unsigned long dispc_core_clk_rate(void)
2812{
2813 int lcd;
2814 unsigned long fclk = dispc_fclk_rate();
2815
2816 if (dss_has_feature(FEAT_CORE_CLK_DIV))
2817 lcd = REG_GET(DISPC_DIVISOR, 23, 16);
2818 else
2819 lcd = REG_GET(DISPC_DIVISORo(OMAP_DSS_CHANNEL_LCD), 23, 16);
2820
2821 return fclk / lcd;
2822}
2823
2479void dispc_dump_clocks(struct seq_file *s) 2824void dispc_dump_clocks(struct seq_file *s)
2480{ 2825{
2481 int lcd, pcd; 2826 int lcd, pcd;
@@ -2588,7 +2933,7 @@ void dispc_dump_irqs(struct seq_file *s)
2588} 2933}
2589#endif 2934#endif
2590 2935
2591void dispc_dump_regs(struct seq_file *s) 2936static void dispc_dump_regs(struct seq_file *s)
2592{ 2937{
2593 int i, j; 2938 int i, j;
2594 const char *mgr_names[] = { 2939 const char *mgr_names[] = {
@@ -3247,27 +3592,6 @@ int omap_dispc_wait_for_irq_interruptible_timeout(u32 irqmask,
3247 return 0; 3592 return 0;
3248} 3593}
3249 3594
3250#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
3251void dispc_fake_vsync_irq(void)
3252{
3253 u32 irqstatus = DISPC_IRQ_VSYNC;
3254 int i;
3255
3256 WARN_ON(!in_interrupt());
3257
3258 for (i = 0; i < DISPC_MAX_NR_ISRS; i++) {
3259 struct omap_dispc_isr_data *isr_data;
3260 isr_data = &dispc.registered_isr[i];
3261
3262 if (!isr_data->isr)
3263 continue;
3264
3265 if (isr_data->mask & irqstatus)
3266 isr_data->isr(isr_data->arg, irqstatus);
3267 }
3268}
3269#endif
3270
3271static void _omap_dispc_initialize_irq(void) 3595static void _omap_dispc_initialize_irq(void)
3272{ 3596{
3273 unsigned long flags; 3597 unsigned long flags;
@@ -3330,7 +3654,7 @@ static void _omap_dispc_initial_config(void)
3330} 3654}
3331 3655
3332/* DISPC HW IP initialisation */ 3656/* DISPC HW IP initialisation */
3333static int omap_dispchw_probe(struct platform_device *pdev) 3657static int __init omap_dispchw_probe(struct platform_device *pdev)
3334{ 3658{
3335 u32 rev; 3659 u32 rev;
3336 int r = 0; 3660 int r = 0;
@@ -3399,6 +3723,11 @@ static int omap_dispchw_probe(struct platform_device *pdev)
3399 3723
3400 dispc_runtime_put(); 3724 dispc_runtime_put();
3401 3725
3726 dss_debugfs_create_file("dispc", dispc_dump_regs);
3727
3728#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
3729 dss_debugfs_create_file("dispc_irq", dispc_dump_irqs);
3730#endif
3402 return 0; 3731 return 0;
3403 3732
3404err_runtime_get: 3733err_runtime_get:
@@ -3407,7 +3736,7 @@ err_runtime_get:
3407 return r; 3736 return r;
3408} 3737}
3409 3738
3410static int omap_dispchw_remove(struct platform_device *pdev) 3739static int __exit omap_dispchw_remove(struct platform_device *pdev)
3411{ 3740{
3412 pm_runtime_disable(&pdev->dev); 3741 pm_runtime_disable(&pdev->dev);
3413 3742
@@ -3419,19 +3748,12 @@ static int omap_dispchw_remove(struct platform_device *pdev)
3419static int dispc_runtime_suspend(struct device *dev) 3748static int dispc_runtime_suspend(struct device *dev)
3420{ 3749{
3421 dispc_save_context(); 3750 dispc_save_context();
3422 dss_runtime_put();
3423 3751
3424 return 0; 3752 return 0;
3425} 3753}
3426 3754
3427static int dispc_runtime_resume(struct device *dev) 3755static int dispc_runtime_resume(struct device *dev)
3428{ 3756{
3429 int r;
3430
3431 r = dss_runtime_get();
3432 if (r < 0)
3433 return r;
3434
3435 dispc_restore_context(); 3757 dispc_restore_context();
3436 3758
3437 return 0; 3759 return 0;
@@ -3443,8 +3765,7 @@ static const struct dev_pm_ops dispc_pm_ops = {
3443}; 3765};
3444 3766
3445static struct platform_driver omap_dispchw_driver = { 3767static struct platform_driver omap_dispchw_driver = {
3446 .probe = omap_dispchw_probe, 3768 .remove = __exit_p(omap_dispchw_remove),
3447 .remove = omap_dispchw_remove,
3448 .driver = { 3769 .driver = {
3449 .name = "omapdss_dispc", 3770 .name = "omapdss_dispc",
3450 .owner = THIS_MODULE, 3771 .owner = THIS_MODULE,
@@ -3452,12 +3773,12 @@ static struct platform_driver omap_dispchw_driver = {
3452 }, 3773 },
3453}; 3774};
3454 3775
3455int dispc_init_platform_driver(void) 3776int __init dispc_init_platform_driver(void)
3456{ 3777{
3457 return platform_driver_register(&omap_dispchw_driver); 3778 return platform_driver_probe(&omap_dispchw_driver, omap_dispchw_probe);
3458} 3779}
3459 3780
3460void dispc_uninit_platform_driver(void) 3781void __exit dispc_uninit_platform_driver(void)
3461{ 3782{
3462 return platform_driver_unregister(&omap_dispchw_driver); 3783 platform_driver_unregister(&omap_dispchw_driver);
3463} 3784}
diff --git a/drivers/video/omap2/dss/dispc.h b/drivers/video/omap2/dss/dispc.h
index 5836bd1650f9..f278080e1063 100644
--- a/drivers/video/omap2/dss/dispc.h
+++ b/drivers/video/omap2/dss/dispc.h
@@ -120,6 +120,7 @@ static inline u16 DISPC_DEFAULT_COLOR(enum omap_channel channel)
120 return 0x03AC; 120 return 0x03AC;
121 default: 121 default:
122 BUG(); 122 BUG();
123 return 0;
123 } 124 }
124} 125}
125 126
@@ -134,6 +135,7 @@ static inline u16 DISPC_TRANS_COLOR(enum omap_channel channel)
134 return 0x03B0; 135 return 0x03B0;
135 default: 136 default:
136 BUG(); 137 BUG();
138 return 0;
137 } 139 }
138} 140}
139 141
@@ -144,10 +146,12 @@ static inline u16 DISPC_TIMING_H(enum omap_channel channel)
144 return 0x0064; 146 return 0x0064;
145 case OMAP_DSS_CHANNEL_DIGIT: 147 case OMAP_DSS_CHANNEL_DIGIT:
146 BUG(); 148 BUG();
149 return 0;
147 case OMAP_DSS_CHANNEL_LCD2: 150 case OMAP_DSS_CHANNEL_LCD2:
148 return 0x0400; 151 return 0x0400;
149 default: 152 default:
150 BUG(); 153 BUG();
154 return 0;
151 } 155 }
152} 156}
153 157
@@ -158,10 +162,12 @@ static inline u16 DISPC_TIMING_V(enum omap_channel channel)
158 return 0x0068; 162 return 0x0068;
159 case OMAP_DSS_CHANNEL_DIGIT: 163 case OMAP_DSS_CHANNEL_DIGIT:
160 BUG(); 164 BUG();
165 return 0;
161 case OMAP_DSS_CHANNEL_LCD2: 166 case OMAP_DSS_CHANNEL_LCD2:
162 return 0x0404; 167 return 0x0404;
163 default: 168 default:
164 BUG(); 169 BUG();
170 return 0;
165 } 171 }
166} 172}
167 173
@@ -172,10 +178,12 @@ static inline u16 DISPC_POL_FREQ(enum omap_channel channel)
172 return 0x006C; 178 return 0x006C;
173 case OMAP_DSS_CHANNEL_DIGIT: 179 case OMAP_DSS_CHANNEL_DIGIT:
174 BUG(); 180 BUG();
181 return 0;
175 case OMAP_DSS_CHANNEL_LCD2: 182 case OMAP_DSS_CHANNEL_LCD2:
176 return 0x0408; 183 return 0x0408;
177 default: 184 default:
178 BUG(); 185 BUG();
186 return 0;
179 } 187 }
180} 188}
181 189
@@ -186,10 +194,12 @@ static inline u16 DISPC_DIVISORo(enum omap_channel channel)
186 return 0x0070; 194 return 0x0070;
187 case OMAP_DSS_CHANNEL_DIGIT: 195 case OMAP_DSS_CHANNEL_DIGIT:
188 BUG(); 196 BUG();
197 return 0;
189 case OMAP_DSS_CHANNEL_LCD2: 198 case OMAP_DSS_CHANNEL_LCD2:
190 return 0x040C; 199 return 0x040C;
191 default: 200 default:
192 BUG(); 201 BUG();
202 return 0;
193 } 203 }
194} 204}
195 205
@@ -205,6 +215,7 @@ static inline u16 DISPC_SIZE_MGR(enum omap_channel channel)
205 return 0x03CC; 215 return 0x03CC;
206 default: 216 default:
207 BUG(); 217 BUG();
218 return 0;
208 } 219 }
209} 220}
210 221
@@ -215,10 +226,12 @@ static inline u16 DISPC_DATA_CYCLE1(enum omap_channel channel)
215 return 0x01D4; 226 return 0x01D4;
216 case OMAP_DSS_CHANNEL_DIGIT: 227 case OMAP_DSS_CHANNEL_DIGIT:
217 BUG(); 228 BUG();
229 return 0;
218 case OMAP_DSS_CHANNEL_LCD2: 230 case OMAP_DSS_CHANNEL_LCD2:
219 return 0x03C0; 231 return 0x03C0;
220 default: 232 default:
221 BUG(); 233 BUG();
234 return 0;
222 } 235 }
223} 236}
224 237
@@ -229,10 +242,12 @@ static inline u16 DISPC_DATA_CYCLE2(enum omap_channel channel)
229 return 0x01D8; 242 return 0x01D8;
230 case OMAP_DSS_CHANNEL_DIGIT: 243 case OMAP_DSS_CHANNEL_DIGIT:
231 BUG(); 244 BUG();
245 return 0;
232 case OMAP_DSS_CHANNEL_LCD2: 246 case OMAP_DSS_CHANNEL_LCD2:
233 return 0x03C4; 247 return 0x03C4;
234 default: 248 default:
235 BUG(); 249 BUG();
250 return 0;
236 } 251 }
237} 252}
238 253
@@ -243,10 +258,12 @@ static inline u16 DISPC_DATA_CYCLE3(enum omap_channel channel)
243 return 0x01DC; 258 return 0x01DC;
244 case OMAP_DSS_CHANNEL_DIGIT: 259 case OMAP_DSS_CHANNEL_DIGIT:
245 BUG(); 260 BUG();
261 return 0;
246 case OMAP_DSS_CHANNEL_LCD2: 262 case OMAP_DSS_CHANNEL_LCD2:
247 return 0x03C8; 263 return 0x03C8;
248 default: 264 default:
249 BUG(); 265 BUG();
266 return 0;
250 } 267 }
251} 268}
252 269
@@ -257,10 +274,12 @@ static inline u16 DISPC_CPR_COEF_R(enum omap_channel channel)
257 return 0x0220; 274 return 0x0220;
258 case OMAP_DSS_CHANNEL_DIGIT: 275 case OMAP_DSS_CHANNEL_DIGIT:
259 BUG(); 276 BUG();
277 return 0;
260 case OMAP_DSS_CHANNEL_LCD2: 278 case OMAP_DSS_CHANNEL_LCD2:
261 return 0x03BC; 279 return 0x03BC;
262 default: 280 default:
263 BUG(); 281 BUG();
282 return 0;
264 } 283 }
265} 284}
266 285
@@ -271,10 +290,12 @@ static inline u16 DISPC_CPR_COEF_G(enum omap_channel channel)
271 return 0x0224; 290 return 0x0224;
272 case OMAP_DSS_CHANNEL_DIGIT: 291 case OMAP_DSS_CHANNEL_DIGIT:
273 BUG(); 292 BUG();
293 return 0;
274 case OMAP_DSS_CHANNEL_LCD2: 294 case OMAP_DSS_CHANNEL_LCD2:
275 return 0x03B8; 295 return 0x03B8;
276 default: 296 default:
277 BUG(); 297 BUG();
298 return 0;
278 } 299 }
279} 300}
280 301
@@ -285,10 +306,12 @@ static inline u16 DISPC_CPR_COEF_B(enum omap_channel channel)
285 return 0x0228; 306 return 0x0228;
286 case OMAP_DSS_CHANNEL_DIGIT: 307 case OMAP_DSS_CHANNEL_DIGIT:
287 BUG(); 308 BUG();
309 return 0;
288 case OMAP_DSS_CHANNEL_LCD2: 310 case OMAP_DSS_CHANNEL_LCD2:
289 return 0x03B4; 311 return 0x03B4;
290 default: 312 default:
291 BUG(); 313 BUG();
314 return 0;
292 } 315 }
293} 316}
294 317
@@ -306,6 +329,7 @@ static inline u16 DISPC_OVL_BASE(enum omap_plane plane)
306 return 0x0300; 329 return 0x0300;
307 default: 330 default:
308 BUG(); 331 BUG();
332 return 0;
309 } 333 }
310} 334}
311 335
@@ -321,6 +345,7 @@ static inline u16 DISPC_BA0_OFFSET(enum omap_plane plane)
321 return 0x0008; 345 return 0x0008;
322 default: 346 default:
323 BUG(); 347 BUG();
348 return 0;
324 } 349 }
325} 350}
326 351
@@ -335,6 +360,7 @@ static inline u16 DISPC_BA1_OFFSET(enum omap_plane plane)
335 return 0x000C; 360 return 0x000C;
336 default: 361 default:
337 BUG(); 362 BUG();
363 return 0;
338 } 364 }
339} 365}
340 366
@@ -343,6 +369,7 @@ static inline u16 DISPC_BA0_UV_OFFSET(enum omap_plane plane)
343 switch (plane) { 369 switch (plane) {
344 case OMAP_DSS_GFX: 370 case OMAP_DSS_GFX:
345 BUG(); 371 BUG();
372 return 0;
346 case OMAP_DSS_VIDEO1: 373 case OMAP_DSS_VIDEO1:
347 return 0x0544; 374 return 0x0544;
348 case OMAP_DSS_VIDEO2: 375 case OMAP_DSS_VIDEO2:
@@ -351,6 +378,7 @@ static inline u16 DISPC_BA0_UV_OFFSET(enum omap_plane plane)
351 return 0x0310; 378 return 0x0310;
352 default: 379 default:
353 BUG(); 380 BUG();
381 return 0;
354 } 382 }
355} 383}
356 384
@@ -359,6 +387,7 @@ static inline u16 DISPC_BA1_UV_OFFSET(enum omap_plane plane)
359 switch (plane) { 387 switch (plane) {
360 case OMAP_DSS_GFX: 388 case OMAP_DSS_GFX:
361 BUG(); 389 BUG();
390 return 0;
362 case OMAP_DSS_VIDEO1: 391 case OMAP_DSS_VIDEO1:
363 return 0x0548; 392 return 0x0548;
364 case OMAP_DSS_VIDEO2: 393 case OMAP_DSS_VIDEO2:
@@ -367,6 +396,7 @@ static inline u16 DISPC_BA1_UV_OFFSET(enum omap_plane plane)
367 return 0x0314; 396 return 0x0314;
368 default: 397 default:
369 BUG(); 398 BUG();
399 return 0;
370 } 400 }
371} 401}
372 402
@@ -381,6 +411,7 @@ static inline u16 DISPC_POS_OFFSET(enum omap_plane plane)
381 return 0x009C; 411 return 0x009C;
382 default: 412 default:
383 BUG(); 413 BUG();
414 return 0;
384 } 415 }
385} 416}
386 417
@@ -395,6 +426,7 @@ static inline u16 DISPC_SIZE_OFFSET(enum omap_plane plane)
395 return 0x00A8; 426 return 0x00A8;
396 default: 427 default:
397 BUG(); 428 BUG();
429 return 0;
398 } 430 }
399} 431}
400 432
@@ -410,6 +442,7 @@ static inline u16 DISPC_ATTR_OFFSET(enum omap_plane plane)
410 return 0x0070; 442 return 0x0070;
411 default: 443 default:
412 BUG(); 444 BUG();
445 return 0;
413 } 446 }
414} 447}
415 448
@@ -418,6 +451,7 @@ static inline u16 DISPC_ATTR2_OFFSET(enum omap_plane plane)
418 switch (plane) { 451 switch (plane) {
419 case OMAP_DSS_GFX: 452 case OMAP_DSS_GFX:
420 BUG(); 453 BUG();
454 return 0;
421 case OMAP_DSS_VIDEO1: 455 case OMAP_DSS_VIDEO1:
422 return 0x0568; 456 return 0x0568;
423 case OMAP_DSS_VIDEO2: 457 case OMAP_DSS_VIDEO2:
@@ -426,6 +460,7 @@ static inline u16 DISPC_ATTR2_OFFSET(enum omap_plane plane)
426 return 0x032C; 460 return 0x032C;
427 default: 461 default:
428 BUG(); 462 BUG();
463 return 0;
429 } 464 }
430} 465}
431 466
@@ -441,6 +476,7 @@ static inline u16 DISPC_FIFO_THRESH_OFFSET(enum omap_plane plane)
441 return 0x008C; 476 return 0x008C;
442 default: 477 default:
443 BUG(); 478 BUG();
479 return 0;
444 } 480 }
445} 481}
446 482
@@ -456,6 +492,7 @@ static inline u16 DISPC_FIFO_SIZE_STATUS_OFFSET(enum omap_plane plane)
456 return 0x0088; 492 return 0x0088;
457 default: 493 default:
458 BUG(); 494 BUG();
495 return 0;
459 } 496 }
460} 497}
461 498
@@ -471,6 +508,7 @@ static inline u16 DISPC_ROW_INC_OFFSET(enum omap_plane plane)
471 return 0x00A4; 508 return 0x00A4;
472 default: 509 default:
473 BUG(); 510 BUG();
511 return 0;
474 } 512 }
475} 513}
476 514
@@ -486,6 +524,7 @@ static inline u16 DISPC_PIX_INC_OFFSET(enum omap_plane plane)
486 return 0x0098; 524 return 0x0098;
487 default: 525 default:
488 BUG(); 526 BUG();
527 return 0;
489 } 528 }
490} 529}
491 530
@@ -498,8 +537,10 @@ static inline u16 DISPC_WINDOW_SKIP_OFFSET(enum omap_plane plane)
498 case OMAP_DSS_VIDEO2: 537 case OMAP_DSS_VIDEO2:
499 case OMAP_DSS_VIDEO3: 538 case OMAP_DSS_VIDEO3:
500 BUG(); 539 BUG();
540 return 0;
501 default: 541 default:
502 BUG(); 542 BUG();
543 return 0;
503 } 544 }
504} 545}
505 546
@@ -512,8 +553,10 @@ static inline u16 DISPC_TABLE_BA_OFFSET(enum omap_plane plane)
512 case OMAP_DSS_VIDEO2: 553 case OMAP_DSS_VIDEO2:
513 case OMAP_DSS_VIDEO3: 554 case OMAP_DSS_VIDEO3:
514 BUG(); 555 BUG();
556 return 0;
515 default: 557 default:
516 BUG(); 558 BUG();
559 return 0;
517 } 560 }
518} 561}
519 562
@@ -522,6 +565,7 @@ static inline u16 DISPC_FIR_OFFSET(enum omap_plane plane)
522 switch (plane) { 565 switch (plane) {
523 case OMAP_DSS_GFX: 566 case OMAP_DSS_GFX:
524 BUG(); 567 BUG();
568 return 0;
525 case OMAP_DSS_VIDEO1: 569 case OMAP_DSS_VIDEO1:
526 case OMAP_DSS_VIDEO2: 570 case OMAP_DSS_VIDEO2:
527 return 0x0024; 571 return 0x0024;
@@ -529,6 +573,7 @@ static inline u16 DISPC_FIR_OFFSET(enum omap_plane plane)
529 return 0x0090; 573 return 0x0090;
530 default: 574 default:
531 BUG(); 575 BUG();
576 return 0;
532 } 577 }
533} 578}
534 579
@@ -537,6 +582,7 @@ static inline u16 DISPC_FIR2_OFFSET(enum omap_plane plane)
537 switch (plane) { 582 switch (plane) {
538 case OMAP_DSS_GFX: 583 case OMAP_DSS_GFX:
539 BUG(); 584 BUG();
585 return 0;
540 case OMAP_DSS_VIDEO1: 586 case OMAP_DSS_VIDEO1:
541 return 0x0580; 587 return 0x0580;
542 case OMAP_DSS_VIDEO2: 588 case OMAP_DSS_VIDEO2:
@@ -545,6 +591,7 @@ static inline u16 DISPC_FIR2_OFFSET(enum omap_plane plane)
545 return 0x0424; 591 return 0x0424;
546 default: 592 default:
547 BUG(); 593 BUG();
594 return 0;
548 } 595 }
549} 596}
550 597
@@ -553,6 +600,7 @@ static inline u16 DISPC_PIC_SIZE_OFFSET(enum omap_plane plane)
553 switch (plane) { 600 switch (plane) {
554 case OMAP_DSS_GFX: 601 case OMAP_DSS_GFX:
555 BUG(); 602 BUG();
603 return 0;
556 case OMAP_DSS_VIDEO1: 604 case OMAP_DSS_VIDEO1:
557 case OMAP_DSS_VIDEO2: 605 case OMAP_DSS_VIDEO2:
558 return 0x0028; 606 return 0x0028;
@@ -560,6 +608,7 @@ static inline u16 DISPC_PIC_SIZE_OFFSET(enum omap_plane plane)
560 return 0x0094; 608 return 0x0094;
561 default: 609 default:
562 BUG(); 610 BUG();
611 return 0;
563 } 612 }
564} 613}
565 614
@@ -569,6 +618,7 @@ static inline u16 DISPC_ACCU0_OFFSET(enum omap_plane plane)
569 switch (plane) { 618 switch (plane) {
570 case OMAP_DSS_GFX: 619 case OMAP_DSS_GFX:
571 BUG(); 620 BUG();
621 return 0;
572 case OMAP_DSS_VIDEO1: 622 case OMAP_DSS_VIDEO1:
573 case OMAP_DSS_VIDEO2: 623 case OMAP_DSS_VIDEO2:
574 return 0x002C; 624 return 0x002C;
@@ -576,6 +626,7 @@ static inline u16 DISPC_ACCU0_OFFSET(enum omap_plane plane)
576 return 0x0000; 626 return 0x0000;
577 default: 627 default:
578 BUG(); 628 BUG();
629 return 0;
579 } 630 }
580} 631}
581 632
@@ -584,6 +635,7 @@ static inline u16 DISPC_ACCU2_0_OFFSET(enum omap_plane plane)
584 switch (plane) { 635 switch (plane) {
585 case OMAP_DSS_GFX: 636 case OMAP_DSS_GFX:
586 BUG(); 637 BUG();
638 return 0;
587 case OMAP_DSS_VIDEO1: 639 case OMAP_DSS_VIDEO1:
588 return 0x0584; 640 return 0x0584;
589 case OMAP_DSS_VIDEO2: 641 case OMAP_DSS_VIDEO2:
@@ -592,6 +644,7 @@ static inline u16 DISPC_ACCU2_0_OFFSET(enum omap_plane plane)
592 return 0x0428; 644 return 0x0428;
593 default: 645 default:
594 BUG(); 646 BUG();
647 return 0;
595 } 648 }
596} 649}
597 650
@@ -600,6 +653,7 @@ static inline u16 DISPC_ACCU1_OFFSET(enum omap_plane plane)
600 switch (plane) { 653 switch (plane) {
601 case OMAP_DSS_GFX: 654 case OMAP_DSS_GFX:
602 BUG(); 655 BUG();
656 return 0;
603 case OMAP_DSS_VIDEO1: 657 case OMAP_DSS_VIDEO1:
604 case OMAP_DSS_VIDEO2: 658 case OMAP_DSS_VIDEO2:
605 return 0x0030; 659 return 0x0030;
@@ -607,6 +661,7 @@ static inline u16 DISPC_ACCU1_OFFSET(enum omap_plane plane)
607 return 0x0004; 661 return 0x0004;
608 default: 662 default:
609 BUG(); 663 BUG();
664 return 0;
610 } 665 }
611} 666}
612 667
@@ -615,6 +670,7 @@ static inline u16 DISPC_ACCU2_1_OFFSET(enum omap_plane plane)
615 switch (plane) { 670 switch (plane) {
616 case OMAP_DSS_GFX: 671 case OMAP_DSS_GFX:
617 BUG(); 672 BUG();
673 return 0;
618 case OMAP_DSS_VIDEO1: 674 case OMAP_DSS_VIDEO1:
619 return 0x0588; 675 return 0x0588;
620 case OMAP_DSS_VIDEO2: 676 case OMAP_DSS_VIDEO2:
@@ -623,6 +679,7 @@ static inline u16 DISPC_ACCU2_1_OFFSET(enum omap_plane plane)
623 return 0x042C; 679 return 0x042C;
624 default: 680 default:
625 BUG(); 681 BUG();
682 return 0;
626 } 683 }
627} 684}
628 685
@@ -632,6 +689,7 @@ static inline u16 DISPC_FIR_COEF_H_OFFSET(enum omap_plane plane, u16 i)
632 switch (plane) { 689 switch (plane) {
633 case OMAP_DSS_GFX: 690 case OMAP_DSS_GFX:
634 BUG(); 691 BUG();
692 return 0;
635 case OMAP_DSS_VIDEO1: 693 case OMAP_DSS_VIDEO1:
636 case OMAP_DSS_VIDEO2: 694 case OMAP_DSS_VIDEO2:
637 return 0x0034 + i * 0x8; 695 return 0x0034 + i * 0x8;
@@ -639,6 +697,7 @@ static inline u16 DISPC_FIR_COEF_H_OFFSET(enum omap_plane plane, u16 i)
639 return 0x0010 + i * 0x8; 697 return 0x0010 + i * 0x8;
640 default: 698 default:
641 BUG(); 699 BUG();
700 return 0;
642 } 701 }
643} 702}
644 703
@@ -648,6 +707,7 @@ static inline u16 DISPC_FIR_COEF_H2_OFFSET(enum omap_plane plane, u16 i)
648 switch (plane) { 707 switch (plane) {
649 case OMAP_DSS_GFX: 708 case OMAP_DSS_GFX:
650 BUG(); 709 BUG();
710 return 0;
651 case OMAP_DSS_VIDEO1: 711 case OMAP_DSS_VIDEO1:
652 return 0x058C + i * 0x8; 712 return 0x058C + i * 0x8;
653 case OMAP_DSS_VIDEO2: 713 case OMAP_DSS_VIDEO2:
@@ -656,6 +716,7 @@ static inline u16 DISPC_FIR_COEF_H2_OFFSET(enum omap_plane plane, u16 i)
656 return 0x0430 + i * 0x8; 716 return 0x0430 + i * 0x8;
657 default: 717 default:
658 BUG(); 718 BUG();
719 return 0;
659 } 720 }
660} 721}
661 722
@@ -665,6 +726,7 @@ static inline u16 DISPC_FIR_COEF_HV_OFFSET(enum omap_plane plane, u16 i)
665 switch (plane) { 726 switch (plane) {
666 case OMAP_DSS_GFX: 727 case OMAP_DSS_GFX:
667 BUG(); 728 BUG();
729 return 0;
668 case OMAP_DSS_VIDEO1: 730 case OMAP_DSS_VIDEO1:
669 case OMAP_DSS_VIDEO2: 731 case OMAP_DSS_VIDEO2:
670 return 0x0038 + i * 0x8; 732 return 0x0038 + i * 0x8;
@@ -672,6 +734,7 @@ static inline u16 DISPC_FIR_COEF_HV_OFFSET(enum omap_plane plane, u16 i)
672 return 0x0014 + i * 0x8; 734 return 0x0014 + i * 0x8;
673 default: 735 default:
674 BUG(); 736 BUG();
737 return 0;
675 } 738 }
676} 739}
677 740
@@ -681,6 +744,7 @@ static inline u16 DISPC_FIR_COEF_HV2_OFFSET(enum omap_plane plane, u16 i)
681 switch (plane) { 744 switch (plane) {
682 case OMAP_DSS_GFX: 745 case OMAP_DSS_GFX:
683 BUG(); 746 BUG();
747 return 0;
684 case OMAP_DSS_VIDEO1: 748 case OMAP_DSS_VIDEO1:
685 return 0x0590 + i * 8; 749 return 0x0590 + i * 8;
686 case OMAP_DSS_VIDEO2: 750 case OMAP_DSS_VIDEO2:
@@ -689,6 +753,7 @@ static inline u16 DISPC_FIR_COEF_HV2_OFFSET(enum omap_plane plane, u16 i)
689 return 0x0434 + i * 0x8; 753 return 0x0434 + i * 0x8;
690 default: 754 default:
691 BUG(); 755 BUG();
756 return 0;
692 } 757 }
693} 758}
694 759
@@ -698,12 +763,14 @@ static inline u16 DISPC_CONV_COEF_OFFSET(enum omap_plane plane, u16 i)
698 switch (plane) { 763 switch (plane) {
699 case OMAP_DSS_GFX: 764 case OMAP_DSS_GFX:
700 BUG(); 765 BUG();
766 return 0;
701 case OMAP_DSS_VIDEO1: 767 case OMAP_DSS_VIDEO1:
702 case OMAP_DSS_VIDEO2: 768 case OMAP_DSS_VIDEO2:
703 case OMAP_DSS_VIDEO3: 769 case OMAP_DSS_VIDEO3:
704 return 0x0074 + i * 0x4; 770 return 0x0074 + i * 0x4;
705 default: 771 default:
706 BUG(); 772 BUG();
773 return 0;
707 } 774 }
708} 775}
709 776
@@ -713,6 +780,7 @@ static inline u16 DISPC_FIR_COEF_V_OFFSET(enum omap_plane plane, u16 i)
713 switch (plane) { 780 switch (plane) {
714 case OMAP_DSS_GFX: 781 case OMAP_DSS_GFX:
715 BUG(); 782 BUG();
783 return 0;
716 case OMAP_DSS_VIDEO1: 784 case OMAP_DSS_VIDEO1:
717 return 0x0124 + i * 0x4; 785 return 0x0124 + i * 0x4;
718 case OMAP_DSS_VIDEO2: 786 case OMAP_DSS_VIDEO2:
@@ -721,6 +789,7 @@ static inline u16 DISPC_FIR_COEF_V_OFFSET(enum omap_plane plane, u16 i)
721 return 0x0050 + i * 0x4; 789 return 0x0050 + i * 0x4;
722 default: 790 default:
723 BUG(); 791 BUG();
792 return 0;
724 } 793 }
725} 794}
726 795
@@ -730,6 +799,7 @@ static inline u16 DISPC_FIR_COEF_V2_OFFSET(enum omap_plane plane, u16 i)
730 switch (plane) { 799 switch (plane) {
731 case OMAP_DSS_GFX: 800 case OMAP_DSS_GFX:
732 BUG(); 801 BUG();
802 return 0;
733 case OMAP_DSS_VIDEO1: 803 case OMAP_DSS_VIDEO1:
734 return 0x05CC + i * 0x4; 804 return 0x05CC + i * 0x4;
735 case OMAP_DSS_VIDEO2: 805 case OMAP_DSS_VIDEO2:
@@ -738,6 +808,7 @@ static inline u16 DISPC_FIR_COEF_V2_OFFSET(enum omap_plane plane, u16 i)
738 return 0x0470 + i * 0x4; 808 return 0x0470 + i * 0x4;
739 default: 809 default:
740 BUG(); 810 BUG();
811 return 0;
741 } 812 }
742} 813}
743 814
@@ -754,6 +825,7 @@ static inline u16 DISPC_PRELOAD_OFFSET(enum omap_plane plane)
754 return 0x00A0; 825 return 0x00A0;
755 default: 826 default:
756 BUG(); 827 BUG();
828 return 0;
757 } 829 }
758} 830}
759#endif 831#endif
diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
index 4424c198dbcd..249010630370 100644
--- a/drivers/video/omap2/dss/display.c
+++ b/drivers/video/omap2/dss/display.c
@@ -304,10 +304,18 @@ int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev)
304 return 24; 304 return 24;
305 default: 305 default:
306 BUG(); 306 BUG();
307 return 0;
307 } 308 }
308} 309}
309EXPORT_SYMBOL(omapdss_default_get_recommended_bpp); 310EXPORT_SYMBOL(omapdss_default_get_recommended_bpp);
310 311
312void omapdss_default_get_timings(struct omap_dss_device *dssdev,
313 struct omap_video_timings *timings)
314{
315 *timings = dssdev->panel.timings;
316}
317EXPORT_SYMBOL(omapdss_default_get_timings);
318
311/* Checks if replication logic should be used. Only use for active matrix, 319/* Checks if replication logic should be used. Only use for active matrix,
312 * when overlay is in RGB12U or RGB16 mode, and LCD interface is 320 * when overlay is in RGB12U or RGB16 mode, and LCD interface is
313 * 18bpp or 24bpp */ 321 * 18bpp or 24bpp */
@@ -340,6 +348,7 @@ bool dss_use_replication(struct omap_dss_device *dssdev,
340 break; 348 break;
341 default: 349 default:
342 BUG(); 350 BUG();
351 return false;
343 } 352 }
344 353
345 return bpp > 16; 354 return bpp > 16;
@@ -352,46 +361,6 @@ void dss_init_device(struct platform_device *pdev,
352 int i; 361 int i;
353 int r; 362 int r;
354 363
355 switch (dssdev->type) {
356#ifdef CONFIG_OMAP2_DSS_DPI
357 case OMAP_DISPLAY_TYPE_DPI:
358 r = dpi_init_display(dssdev);
359 break;
360#endif
361#ifdef CONFIG_OMAP2_DSS_RFBI
362 case OMAP_DISPLAY_TYPE_DBI:
363 r = rfbi_init_display(dssdev);
364 break;
365#endif
366#ifdef CONFIG_OMAP2_DSS_VENC
367 case OMAP_DISPLAY_TYPE_VENC:
368 r = venc_init_display(dssdev);
369 break;
370#endif
371#ifdef CONFIG_OMAP2_DSS_SDI
372 case OMAP_DISPLAY_TYPE_SDI:
373 r = sdi_init_display(dssdev);
374 break;
375#endif
376#ifdef CONFIG_OMAP2_DSS_DSI
377 case OMAP_DISPLAY_TYPE_DSI:
378 r = dsi_init_display(dssdev);
379 break;
380#endif
381 case OMAP_DISPLAY_TYPE_HDMI:
382 r = hdmi_init_display(dssdev);
383 break;
384 default:
385 DSSERR("Support for display '%s' not compiled in.\n",
386 dssdev->name);
387 return;
388 }
389
390 if (r) {
391 DSSERR("failed to init display %s\n", dssdev->name);
392 return;
393 }
394
395 /* create device sysfs files */ 364 /* create device sysfs files */
396 i = 0; 365 i = 0;
397 while ((attr = display_sysfs_attrs[i++]) != NULL) { 366 while ((attr = display_sysfs_attrs[i++]) != NULL) {
diff --git a/drivers/video/omap2/dss/dpi.c b/drivers/video/omap2/dss/dpi.c
index faaf305fda27..8c2056c9537b 100644
--- a/drivers/video/omap2/dss/dpi.c
+++ b/drivers/video/omap2/dss/dpi.c
@@ -156,7 +156,7 @@ static int dpi_set_mode(struct omap_dss_device *dssdev)
156 t->pixel_clock = pck; 156 t->pixel_clock = pck;
157 } 157 }
158 158
159 dispc_mgr_set_lcd_timings(dssdev->manager->id, t); 159 dss_mgr_set_timings(dssdev->manager, t);
160 160
161 return 0; 161 return 0;
162} 162}
@@ -202,10 +202,6 @@ int omapdss_dpi_display_enable(struct omap_dss_device *dssdev)
202 goto err_reg_enable; 202 goto err_reg_enable;
203 } 203 }
204 204
205 r = dss_runtime_get();
206 if (r)
207 goto err_get_dss;
208
209 r = dispc_runtime_get(); 205 r = dispc_runtime_get();
210 if (r) 206 if (r)
211 goto err_get_dispc; 207 goto err_get_dispc;
@@ -244,8 +240,6 @@ err_dsi_pll_init:
244err_get_dsi: 240err_get_dsi:
245 dispc_runtime_put(); 241 dispc_runtime_put();
246err_get_dispc: 242err_get_dispc:
247 dss_runtime_put();
248err_get_dss:
249 if (cpu_is_omap34xx()) 243 if (cpu_is_omap34xx())
250 regulator_disable(dpi.vdds_dsi_reg); 244 regulator_disable(dpi.vdds_dsi_reg);
251err_reg_enable: 245err_reg_enable:
@@ -266,7 +260,6 @@ void omapdss_dpi_display_disable(struct omap_dss_device *dssdev)
266 } 260 }
267 261
268 dispc_runtime_put(); 262 dispc_runtime_put();
269 dss_runtime_put();
270 263
271 if (cpu_is_omap34xx()) 264 if (cpu_is_omap34xx())
272 regulator_disable(dpi.vdds_dsi_reg); 265 regulator_disable(dpi.vdds_dsi_reg);
@@ -283,21 +276,15 @@ void dpi_set_timings(struct omap_dss_device *dssdev,
283 DSSDBG("dpi_set_timings\n"); 276 DSSDBG("dpi_set_timings\n");
284 dssdev->panel.timings = *timings; 277 dssdev->panel.timings = *timings;
285 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) { 278 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
286 r = dss_runtime_get();
287 if (r)
288 return;
289
290 r = dispc_runtime_get(); 279 r = dispc_runtime_get();
291 if (r) { 280 if (r)
292 dss_runtime_put();
293 return; 281 return;
294 }
295 282
296 dpi_set_mode(dssdev); 283 dpi_set_mode(dssdev);
297 dispc_mgr_go(dssdev->manager->id);
298 284
299 dispc_runtime_put(); 285 dispc_runtime_put();
300 dss_runtime_put(); 286 } else {
287 dss_mgr_set_timings(dssdev->manager, timings);
301 } 288 }
302} 289}
303EXPORT_SYMBOL(dpi_set_timings); 290EXPORT_SYMBOL(dpi_set_timings);
@@ -312,7 +299,7 @@ int dpi_check_timings(struct omap_dss_device *dssdev,
312 unsigned long pck; 299 unsigned long pck;
313 struct dispc_clock_info dispc_cinfo; 300 struct dispc_clock_info dispc_cinfo;
314 301
315 if (!dispc_lcd_timings_ok(timings)) 302 if (dss_mgr_check_timings(dssdev->manager, timings))
316 return -EINVAL; 303 return -EINVAL;
317 304
318 if (timings->pixel_clock == 0) 305 if (timings->pixel_clock == 0)
@@ -352,7 +339,7 @@ int dpi_check_timings(struct omap_dss_device *dssdev,
352} 339}
353EXPORT_SYMBOL(dpi_check_timings); 340EXPORT_SYMBOL(dpi_check_timings);
354 341
355int dpi_init_display(struct omap_dss_device *dssdev) 342static int __init dpi_init_display(struct omap_dss_device *dssdev)
356{ 343{
357 DSSDBG("init_display\n"); 344 DSSDBG("init_display\n");
358 345
@@ -378,12 +365,58 @@ int dpi_init_display(struct omap_dss_device *dssdev)
378 return 0; 365 return 0;
379} 366}
380 367
381int dpi_init(void) 368static void __init dpi_probe_pdata(struct platform_device *pdev)
382{ 369{
370 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
371 int i, r;
372
373 for (i = 0; i < pdata->num_devices; ++i) {
374 struct omap_dss_device *dssdev = pdata->devices[i];
375
376 if (dssdev->type != OMAP_DISPLAY_TYPE_DPI)
377 continue;
378
379 r = dpi_init_display(dssdev);
380 if (r) {
381 DSSERR("device %s init failed: %d\n", dssdev->name, r);
382 continue;
383 }
384
385 r = omap_dss_register_device(dssdev, &pdev->dev, i);
386 if (r)
387 DSSERR("device %s register failed: %d\n",
388 dssdev->name, r);
389 }
390}
391
392static int __init omap_dpi_probe(struct platform_device *pdev)
393{
394 dpi_probe_pdata(pdev);
395
396 return 0;
397}
398
399static int __exit omap_dpi_remove(struct platform_device *pdev)
400{
401 omap_dss_unregister_child_devices(&pdev->dev);
402
383 return 0; 403 return 0;
384} 404}
385 405
386void dpi_exit(void) 406static struct platform_driver omap_dpi_driver = {
407 .remove = __exit_p(omap_dpi_remove),
408 .driver = {
409 .name = "omapdss_dpi",
410 .owner = THIS_MODULE,
411 },
412};
413
414int __init dpi_init_platform_driver(void)
387{ 415{
416 return platform_driver_probe(&omap_dpi_driver, omap_dpi_probe);
388} 417}
389 418
419void __exit dpi_uninit_platform_driver(void)
420{
421 platform_driver_unregister(&omap_dpi_driver);
422}
diff --git a/drivers/video/omap2/dss/dsi.c b/drivers/video/omap2/dss/dsi.c
index 210a3c4f6150..ec363d8390ed 100644
--- a/drivers/video/omap2/dss/dsi.c
+++ b/drivers/video/omap2/dss/dsi.c
@@ -256,14 +256,13 @@ struct dsi_data {
256 struct platform_device *pdev; 256 struct platform_device *pdev;
257 void __iomem *base; 257 void __iomem *base;
258 258
259 int module_id;
260
259 int irq; 261 int irq;
260 262
261 struct clk *dss_clk; 263 struct clk *dss_clk;
262 struct clk *sys_clk; 264 struct clk *sys_clk;
263 265
264 int (*enable_pads)(int dsi_id, unsigned lane_mask);
265 void (*disable_pads)(int dsi_id, unsigned lane_mask);
266
267 struct dsi_clock_info current_cinfo; 266 struct dsi_clock_info current_cinfo;
268 267
269 bool vdds_dsi_enabled; 268 bool vdds_dsi_enabled;
@@ -361,11 +360,6 @@ struct platform_device *dsi_get_dsidev_from_id(int module)
361 return dsi_pdev_map[module]; 360 return dsi_pdev_map[module];
362} 361}
363 362
364static inline int dsi_get_dsidev_id(struct platform_device *dsidev)
365{
366 return dsidev->id;
367}
368
369static inline void dsi_write_reg(struct platform_device *dsidev, 363static inline void dsi_write_reg(struct platform_device *dsidev,
370 const struct dsi_reg idx, u32 val) 364 const struct dsi_reg idx, u32 val)
371{ 365{
@@ -452,6 +446,7 @@ u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt)
452 return 16; 446 return 16;
453 default: 447 default:
454 BUG(); 448 BUG();
449 return 0;
455 } 450 }
456} 451}
457 452
@@ -1184,10 +1179,9 @@ static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev)
1184static unsigned long dsi_fclk_rate(struct platform_device *dsidev) 1179static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
1185{ 1180{
1186 unsigned long r; 1181 unsigned long r;
1187 int dsi_module = dsi_get_dsidev_id(dsidev);
1188 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1182 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1189 1183
1190 if (dss_get_dsi_clk_source(dsi_module) == OMAP_DSS_CLK_SRC_FCK) { 1184 if (dss_get_dsi_clk_source(dsi->module_id) == OMAP_DSS_CLK_SRC_FCK) {
1191 /* DSI FCLK source is DSS_CLK_FCK */ 1185 /* DSI FCLK source is DSS_CLK_FCK */
1192 r = clk_get_rate(dsi->dss_clk); 1186 r = clk_get_rate(dsi->dss_clk);
1193 } else { 1187 } else {
@@ -1279,10 +1273,9 @@ static int dsi_pll_power(struct platform_device *dsidev,
1279} 1273}
1280 1274
1281/* calculate clock rates using dividers in cinfo */ 1275/* calculate clock rates using dividers in cinfo */
1282static int dsi_calc_clock_rates(struct omap_dss_device *dssdev, 1276static int dsi_calc_clock_rates(struct platform_device *dsidev,
1283 struct dsi_clock_info *cinfo) 1277 struct dsi_clock_info *cinfo)
1284{ 1278{
1285 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
1286 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1279 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1287 1280
1288 if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max) 1281 if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
@@ -1297,21 +1290,8 @@ static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
1297 if (cinfo->regm_dsi > dsi->regm_dsi_max) 1290 if (cinfo->regm_dsi > dsi->regm_dsi_max)
1298 return -EINVAL; 1291 return -EINVAL;
1299 1292
1300 if (cinfo->use_sys_clk) { 1293 cinfo->clkin = clk_get_rate(dsi->sys_clk);
1301 cinfo->clkin = clk_get_rate(dsi->sys_clk); 1294 cinfo->fint = cinfo->clkin / cinfo->regn;
1302 /* XXX it is unclear if highfreq should be used
1303 * with DSS_SYS_CLK source also */
1304 cinfo->highfreq = 0;
1305 } else {
1306 cinfo->clkin = dispc_mgr_pclk_rate(dssdev->manager->id);
1307
1308 if (cinfo->clkin < 32000000)
1309 cinfo->highfreq = 0;
1310 else
1311 cinfo->highfreq = 1;
1312 }
1313
1314 cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
1315 1295
1316 if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min) 1296 if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
1317 return -EINVAL; 1297 return -EINVAL;
@@ -1378,27 +1358,21 @@ retry:
1378 1358
1379 memset(&cur, 0, sizeof(cur)); 1359 memset(&cur, 0, sizeof(cur));
1380 cur.clkin = dss_sys_clk; 1360 cur.clkin = dss_sys_clk;
1381 cur.use_sys_clk = 1;
1382 cur.highfreq = 0;
1383 1361
1384 /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */ 1362 /* 0.75MHz < Fint = clkin / regn < 2.1MHz */
1385 /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
1386 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */ 1363 /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
1387 for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) { 1364 for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
1388 if (cur.highfreq == 0) 1365 cur.fint = cur.clkin / cur.regn;
1389 cur.fint = cur.clkin / cur.regn;
1390 else
1391 cur.fint = cur.clkin / (2 * cur.regn);
1392 1366
1393 if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min) 1367 if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
1394 continue; 1368 continue;
1395 1369
1396 /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */ 1370 /* DSIPHY(MHz) = (2 * regm / regn) * clkin */
1397 for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) { 1371 for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
1398 unsigned long a, b; 1372 unsigned long a, b;
1399 1373
1400 a = 2 * cur.regm * (cur.clkin/1000); 1374 a = 2 * cur.regm * (cur.clkin/1000);
1401 b = cur.regn * (cur.highfreq + 1); 1375 b = cur.regn;
1402 cur.clkin4ddr = a / b * 1000; 1376 cur.clkin4ddr = a / b * 1000;
1403 1377
1404 if (cur.clkin4ddr > 1800 * 1000 * 1000) 1378 if (cur.clkin4ddr > 1800 * 1000 * 1000)
@@ -1486,9 +1460,7 @@ int dsi_pll_set_clock_div(struct platform_device *dsidev,
1486 1460
1487 DSSDBGF(); 1461 DSSDBGF();
1488 1462
1489 dsi->current_cinfo.use_sys_clk = cinfo->use_sys_clk; 1463 dsi->current_cinfo.clkin = cinfo->clkin;
1490 dsi->current_cinfo.highfreq = cinfo->highfreq;
1491
1492 dsi->current_cinfo.fint = cinfo->fint; 1464 dsi->current_cinfo.fint = cinfo->fint;
1493 dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr; 1465 dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
1494 dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk = 1466 dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
@@ -1503,17 +1475,13 @@ int dsi_pll_set_clock_div(struct platform_device *dsidev,
1503 1475
1504 DSSDBG("DSI Fint %ld\n", cinfo->fint); 1476 DSSDBG("DSI Fint %ld\n", cinfo->fint);
1505 1477
1506 DSSDBG("clkin (%s) rate %ld, highfreq %d\n", 1478 DSSDBG("clkin rate %ld\n", cinfo->clkin);
1507 cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree",
1508 cinfo->clkin,
1509 cinfo->highfreq);
1510 1479
1511 /* DSIPHY == CLKIN4DDR */ 1480 /* DSIPHY == CLKIN4DDR */
1512 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n", 1481 DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu = %lu\n",
1513 cinfo->regm, 1482 cinfo->regm,
1514 cinfo->regn, 1483 cinfo->regn,
1515 cinfo->clkin, 1484 cinfo->clkin,
1516 cinfo->highfreq + 1,
1517 cinfo->clkin4ddr); 1485 cinfo->clkin4ddr);
1518 1486
1519 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n", 1487 DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
@@ -1568,10 +1536,6 @@ int dsi_pll_set_clock_div(struct platform_device *dsidev,
1568 1536
1569 if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) 1537 if (dss_has_feature(FEAT_DSI_PLL_FREQSEL))
1570 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */ 1538 l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
1571 l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1,
1572 11, 11); /* DSI_PLL_CLKSEL */
1573 l = FLD_MOD(l, cinfo->highfreq,
1574 12, 12); /* DSI_PLL_HIGHFREQ */
1575 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */ 1539 l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
1576 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */ 1540 l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
1577 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */ 1541 l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
@@ -1716,7 +1680,7 @@ static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
1716 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1680 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1717 struct dsi_clock_info *cinfo = &dsi->current_cinfo; 1681 struct dsi_clock_info *cinfo = &dsi->current_cinfo;
1718 enum omap_dss_clk_source dispc_clk_src, dsi_clk_src; 1682 enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
1719 int dsi_module = dsi_get_dsidev_id(dsidev); 1683 int dsi_module = dsi->module_id;
1720 1684
1721 dispc_clk_src = dss_get_dispc_clk_source(); 1685 dispc_clk_src = dss_get_dispc_clk_source();
1722 dsi_clk_src = dss_get_dsi_clk_source(dsi_module); 1686 dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
@@ -1726,8 +1690,7 @@ static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
1726 1690
1727 seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1); 1691 seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
1728 1692
1729 seq_printf(s, "dsi pll source = %s\n", 1693 seq_printf(s, "dsi pll clkin\t%lu\n", cinfo->clkin);
1730 cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree");
1731 1694
1732 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn); 1695 seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
1733 1696
@@ -1789,7 +1752,6 @@ static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
1789 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 1752 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
1790 unsigned long flags; 1753 unsigned long flags;
1791 struct dsi_irq_stats stats; 1754 struct dsi_irq_stats stats;
1792 int dsi_module = dsi_get_dsidev_id(dsidev);
1793 1755
1794 spin_lock_irqsave(&dsi->irq_stats_lock, flags); 1756 spin_lock_irqsave(&dsi->irq_stats_lock, flags);
1795 1757
@@ -1806,7 +1768,7 @@ static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
1806#define PIS(x) \ 1768#define PIS(x) \
1807 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]); 1769 seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
1808 1770
1809 seq_printf(s, "-- DSI%d interrupts --\n", dsi_module + 1); 1771 seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1);
1810 PIS(VC0); 1772 PIS(VC0);
1811 PIS(VC1); 1773 PIS(VC1);
1812 PIS(VC2); 1774 PIS(VC2);
@@ -1886,22 +1848,6 @@ static void dsi2_dump_irqs(struct seq_file *s)
1886 1848
1887 dsi_dump_dsidev_irqs(dsidev, s); 1849 dsi_dump_dsidev_irqs(dsidev, s);
1888} 1850}
1889
1890void dsi_create_debugfs_files_irq(struct dentry *debugfs_dir,
1891 const struct file_operations *debug_fops)
1892{
1893 struct platform_device *dsidev;
1894
1895 dsidev = dsi_get_dsidev_from_id(0);
1896 if (dsidev)
1897 debugfs_create_file("dsi1_irqs", S_IRUGO, debugfs_dir,
1898 &dsi1_dump_irqs, debug_fops);
1899
1900 dsidev = dsi_get_dsidev_from_id(1);
1901 if (dsidev)
1902 debugfs_create_file("dsi2_irqs", S_IRUGO, debugfs_dir,
1903 &dsi2_dump_irqs, debug_fops);
1904}
1905#endif 1851#endif
1906 1852
1907static void dsi_dump_dsidev_regs(struct platform_device *dsidev, 1853static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
@@ -2002,21 +1948,6 @@ static void dsi2_dump_regs(struct seq_file *s)
2002 dsi_dump_dsidev_regs(dsidev, s); 1948 dsi_dump_dsidev_regs(dsidev, s);
2003} 1949}
2004 1950
2005void dsi_create_debugfs_files_reg(struct dentry *debugfs_dir,
2006 const struct file_operations *debug_fops)
2007{
2008 struct platform_device *dsidev;
2009
2010 dsidev = dsi_get_dsidev_from_id(0);
2011 if (dsidev)
2012 debugfs_create_file("dsi1_regs", S_IRUGO, debugfs_dir,
2013 &dsi1_dump_regs, debug_fops);
2014
2015 dsidev = dsi_get_dsidev_from_id(1);
2016 if (dsidev)
2017 debugfs_create_file("dsi2_regs", S_IRUGO, debugfs_dir,
2018 &dsi2_dump_regs, debug_fops);
2019}
2020enum dsi_cio_power_state { 1951enum dsi_cio_power_state {
2021 DSI_COMPLEXIO_POWER_OFF = 0x0, 1952 DSI_COMPLEXIO_POWER_OFF = 0x0,
2022 DSI_COMPLEXIO_POWER_ON = 0x1, 1953 DSI_COMPLEXIO_POWER_ON = 0x1,
@@ -2073,6 +2004,7 @@ static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
2073 return 1365 * 3; /* 1365x24 bits */ 2004 return 1365 * 3; /* 1365x24 bits */
2074 default: 2005 default:
2075 BUG(); 2006 BUG();
2007 return 0;
2076 } 2008 }
2077} 2009}
2078 2010
@@ -2337,7 +2269,7 @@ static int dsi_cio_init(struct omap_dss_device *dssdev)
2337 2269
2338 DSSDBGF(); 2270 DSSDBGF();
2339 2271
2340 r = dsi->enable_pads(dsidev->id, dsi_get_lane_mask(dssdev)); 2272 r = dss_dsi_enable_pads(dsi->module_id, dsi_get_lane_mask(dssdev));
2341 if (r) 2273 if (r)
2342 return r; 2274 return r;
2343 2275
@@ -2447,7 +2379,7 @@ err_cio_pwr:
2447 dsi_cio_disable_lane_override(dsidev); 2379 dsi_cio_disable_lane_override(dsidev);
2448err_scp_clk_dom: 2380err_scp_clk_dom:
2449 dsi_disable_scp_clk(dsidev); 2381 dsi_disable_scp_clk(dsidev);
2450 dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev)); 2382 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dssdev));
2451 return r; 2383 return r;
2452} 2384}
2453 2385
@@ -2461,7 +2393,7 @@ static void dsi_cio_uninit(struct omap_dss_device *dssdev)
2461 2393
2462 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF); 2394 dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
2463 dsi_disable_scp_clk(dsidev); 2395 dsi_disable_scp_clk(dsidev);
2464 dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev)); 2396 dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dssdev));
2465} 2397}
2466 2398
2467static void dsi_config_tx_fifo(struct platform_device *dsidev, 2399static void dsi_config_tx_fifo(struct platform_device *dsidev,
@@ -2485,6 +2417,7 @@ static void dsi_config_tx_fifo(struct platform_device *dsidev,
2485 if (add + size > 4) { 2417 if (add + size > 4) {
2486 DSSERR("Illegal FIFO configuration\n"); 2418 DSSERR("Illegal FIFO configuration\n");
2487 BUG(); 2419 BUG();
2420 return;
2488 } 2421 }
2489 2422
2490 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); 2423 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
@@ -2517,6 +2450,7 @@ static void dsi_config_rx_fifo(struct platform_device *dsidev,
2517 if (add + size > 4) { 2450 if (add + size > 4) {
2518 DSSERR("Illegal FIFO configuration\n"); 2451 DSSERR("Illegal FIFO configuration\n");
2519 BUG(); 2452 BUG();
2453 return;
2520 } 2454 }
2521 2455
2522 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4); 2456 v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
@@ -2658,6 +2592,7 @@ static int dsi_sync_vc(struct platform_device *dsidev, int channel)
2658 return dsi_sync_vc_l4(dsidev, channel); 2592 return dsi_sync_vc_l4(dsidev, channel);
2659 default: 2593 default:
2660 BUG(); 2594 BUG();
2595 return -EINVAL;
2661 } 2596 }
2662} 2597}
2663 2598
@@ -3226,6 +3161,7 @@ static int dsi_vc_generic_send_read_request(struct omap_dss_device *dssdev,
3226 data = reqdata[0] | (reqdata[1] << 8); 3161 data = reqdata[0] | (reqdata[1] << 8);
3227 } else { 3162 } else {
3228 BUG(); 3163 BUG();
3164 return -EINVAL;
3229 } 3165 }
3230 3166
3231 r = dsi_vc_send_short(dsidev, channel, data_type, data, 0); 3167 r = dsi_vc_send_short(dsidev, channel, data_type, data, 0);
@@ -3340,7 +3276,6 @@ static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel,
3340 goto err; 3276 goto err;
3341 } 3277 }
3342 3278
3343 BUG();
3344err: 3279err:
3345 DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel, 3280 DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel,
3346 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS"); 3281 type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS");
@@ -3735,6 +3670,186 @@ static void dsi_config_blanking_modes(struct omap_dss_device *dssdev)
3735 dsi_write_reg(dsidev, DSI_CTRL, r); 3670 dsi_write_reg(dsidev, DSI_CTRL, r);
3736} 3671}
3737 3672
3673/*
3674 * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3
3675 * results in maximum transition time for data and clock lanes to enter and
3676 * exit HS mode. Hence, this is the scenario where the least amount of command
3677 * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS
3678 * clock cycles that can be used to interleave command mode data in HS so that
3679 * all scenarios are satisfied.
3680 */
3681static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs,
3682 int exit_hs, int exiths_clk, int ddr_pre, int ddr_post)
3683{
3684 int transition;
3685
3686 /*
3687 * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition
3688 * time of data lanes only, if it isn't set, we need to consider HS
3689 * transition time of both data and clock lanes. HS transition time
3690 * of Scenario 3 is considered.
3691 */
3692 if (ddr_alwon) {
3693 transition = enter_hs + exit_hs + max(enter_hs, 2) + 1;
3694 } else {
3695 int trans1, trans2;
3696 trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1;
3697 trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre +
3698 enter_hs + 1;
3699 transition = max(trans1, trans2);
3700 }
3701
3702 return blank > transition ? blank - transition : 0;
3703}
3704
3705/*
3706 * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1
3707 * results in maximum transition time for data lanes to enter and exit LP mode.
3708 * Hence, this is the scenario where the least amount of command mode data can
3709 * be interleaved. We program the minimum amount of bytes that can be
3710 * interleaved in LP so that all scenarios are satisfied.
3711 */
3712static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs,
3713 int lp_clk_div, int tdsi_fclk)
3714{
3715 int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */
3716 int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */
3717 int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */
3718 int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */
3719 int lp_inter; /* cmd mode data that can be interleaved, in bytes */
3720
3721 /* maximum LP transition time according to Scenario 1 */
3722 trans_lp = exit_hs + max(enter_hs, 2) + 1;
3723
3724 /* CLKIN4DDR = 16 * TXBYTECLKHS */
3725 tlp_avail = thsbyte_clk * (blank - trans_lp);
3726
3727 ttxclkesc = tdsi_fclk / lp_clk_div;
3728
3729 lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc -
3730 26) / 16;
3731
3732 return max(lp_inter, 0);
3733}
3734
3735static void dsi_config_cmd_mode_interleaving(struct omap_dss_device *dssdev)
3736{
3737 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
3738 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
3739 int blanking_mode;
3740 int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode;
3741 int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div;
3742 int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat;
3743 int tclk_trail, ths_exit, exiths_clk;
3744 bool ddr_alwon;
3745 struct omap_video_timings *timings = &dssdev->panel.timings;
3746 int bpp = dsi_get_pixel_size(dssdev->panel.dsi_pix_fmt);
3747 int ndl = dsi->num_lanes_used - 1;
3748 int dsi_fclk_hsdiv = dssdev->clocks.dsi.regm_dsi + 1;
3749 int hsa_interleave_hs = 0, hsa_interleave_lp = 0;
3750 int hfp_interleave_hs = 0, hfp_interleave_lp = 0;
3751 int hbp_interleave_hs = 0, hbp_interleave_lp = 0;
3752 int bl_interleave_hs = 0, bl_interleave_lp = 0;
3753 u32 r;
3754
3755 r = dsi_read_reg(dsidev, DSI_CTRL);
3756 blanking_mode = FLD_GET(r, 20, 20);
3757 hfp_blanking_mode = FLD_GET(r, 21, 21);
3758 hbp_blanking_mode = FLD_GET(r, 22, 22);
3759 hsa_blanking_mode = FLD_GET(r, 23, 23);
3760
3761 r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
3762 hbp = FLD_GET(r, 11, 0);
3763 hfp = FLD_GET(r, 23, 12);
3764 hsa = FLD_GET(r, 31, 24);
3765
3766 r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
3767 ddr_clk_post = FLD_GET(r, 7, 0);
3768 ddr_clk_pre = FLD_GET(r, 15, 8);
3769
3770 r = dsi_read_reg(dsidev, DSI_VM_TIMING7);
3771 exit_hs_mode_lat = FLD_GET(r, 15, 0);
3772 enter_hs_mode_lat = FLD_GET(r, 31, 16);
3773
3774 r = dsi_read_reg(dsidev, DSI_CLK_CTRL);
3775 lp_clk_div = FLD_GET(r, 12, 0);
3776 ddr_alwon = FLD_GET(r, 13, 13);
3777
3778 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
3779 ths_exit = FLD_GET(r, 7, 0);
3780
3781 r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
3782 tclk_trail = FLD_GET(r, 15, 8);
3783
3784 exiths_clk = ths_exit + tclk_trail;
3785
3786 width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
3787 bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl);
3788
3789 if (!hsa_blanking_mode) {
3790 hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon,
3791 enter_hs_mode_lat, exit_hs_mode_lat,
3792 exiths_clk, ddr_clk_pre, ddr_clk_post);
3793 hsa_interleave_lp = dsi_compute_interleave_lp(hsa,
3794 enter_hs_mode_lat, exit_hs_mode_lat,
3795 lp_clk_div, dsi_fclk_hsdiv);
3796 }
3797
3798 if (!hfp_blanking_mode) {
3799 hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon,
3800 enter_hs_mode_lat, exit_hs_mode_lat,
3801 exiths_clk, ddr_clk_pre, ddr_clk_post);
3802 hfp_interleave_lp = dsi_compute_interleave_lp(hfp,
3803 enter_hs_mode_lat, exit_hs_mode_lat,
3804 lp_clk_div, dsi_fclk_hsdiv);
3805 }
3806
3807 if (!hbp_blanking_mode) {
3808 hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon,
3809 enter_hs_mode_lat, exit_hs_mode_lat,
3810 exiths_clk, ddr_clk_pre, ddr_clk_post);
3811
3812 hbp_interleave_lp = dsi_compute_interleave_lp(hbp,
3813 enter_hs_mode_lat, exit_hs_mode_lat,
3814 lp_clk_div, dsi_fclk_hsdiv);
3815 }
3816
3817 if (!blanking_mode) {
3818 bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon,
3819 enter_hs_mode_lat, exit_hs_mode_lat,
3820 exiths_clk, ddr_clk_pre, ddr_clk_post);
3821
3822 bl_interleave_lp = dsi_compute_interleave_lp(bllp,
3823 enter_hs_mode_lat, exit_hs_mode_lat,
3824 lp_clk_div, dsi_fclk_hsdiv);
3825 }
3826
3827 DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3828 hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs,
3829 bl_interleave_hs);
3830
3831 DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n",
3832 hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp,
3833 bl_interleave_lp);
3834
3835 r = dsi_read_reg(dsidev, DSI_VM_TIMING4);
3836 r = FLD_MOD(r, hsa_interleave_hs, 23, 16);
3837 r = FLD_MOD(r, hfp_interleave_hs, 15, 8);
3838 r = FLD_MOD(r, hbp_interleave_hs, 7, 0);
3839 dsi_write_reg(dsidev, DSI_VM_TIMING4, r);
3840
3841 r = dsi_read_reg(dsidev, DSI_VM_TIMING5);
3842 r = FLD_MOD(r, hsa_interleave_lp, 23, 16);
3843 r = FLD_MOD(r, hfp_interleave_lp, 15, 8);
3844 r = FLD_MOD(r, hbp_interleave_lp, 7, 0);
3845 dsi_write_reg(dsidev, DSI_VM_TIMING5, r);
3846
3847 r = dsi_read_reg(dsidev, DSI_VM_TIMING6);
3848 r = FLD_MOD(r, bl_interleave_hs, 31, 15);
3849 r = FLD_MOD(r, bl_interleave_lp, 16, 0);
3850 dsi_write_reg(dsidev, DSI_VM_TIMING6, r);
3851}
3852
3738static int dsi_proto_config(struct omap_dss_device *dssdev) 3853static int dsi_proto_config(struct omap_dss_device *dssdev)
3739{ 3854{
3740 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 3855 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
@@ -3769,6 +3884,7 @@ static int dsi_proto_config(struct omap_dss_device *dssdev)
3769 break; 3884 break;
3770 default: 3885 default:
3771 BUG(); 3886 BUG();
3887 return -EINVAL;
3772 } 3888 }
3773 3889
3774 r = dsi_read_reg(dsidev, DSI_CTRL); 3890 r = dsi_read_reg(dsidev, DSI_CTRL);
@@ -3793,6 +3909,7 @@ static int dsi_proto_config(struct omap_dss_device *dssdev)
3793 if (dssdev->panel.dsi_mode == OMAP_DSS_DSI_VIDEO_MODE) { 3909 if (dssdev->panel.dsi_mode == OMAP_DSS_DSI_VIDEO_MODE) {
3794 dsi_config_vp_sync_events(dssdev); 3910 dsi_config_vp_sync_events(dssdev);
3795 dsi_config_blanking_modes(dssdev); 3911 dsi_config_blanking_modes(dssdev);
3912 dsi_config_cmd_mode_interleaving(dssdev);
3796 } 3913 }
3797 3914
3798 dsi_vc_initial_config(dsidev, 0); 3915 dsi_vc_initial_config(dsidev, 0);
@@ -4008,6 +4125,7 @@ int dsi_enable_video_output(struct omap_dss_device *dssdev, int channel)
4008 break; 4125 break;
4009 default: 4126 default:
4010 BUG(); 4127 BUG();
4128 return -EINVAL;
4011 }; 4129 };
4012 4130
4013 dsi_if_enable(dsidev, false); 4131 dsi_if_enable(dsidev, false);
@@ -4192,10 +4310,6 @@ static void dsi_framedone_irq_callback(void *data, u32 mask)
4192 __cancel_delayed_work(&dsi->framedone_timeout_work); 4310 __cancel_delayed_work(&dsi->framedone_timeout_work);
4193 4311
4194 dsi_handle_framedone(dsidev, 0); 4312 dsi_handle_framedone(dsidev, 0);
4195
4196#ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
4197 dispc_fake_vsync_irq();
4198#endif
4199} 4313}
4200 4314
4201int omap_dsi_update(struct omap_dss_device *dssdev, int channel, 4315int omap_dsi_update(struct omap_dss_device *dssdev, int channel,
@@ -4259,13 +4373,12 @@ static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
4259 dispc_mgr_enable_stallmode(dssdev->manager->id, true); 4373 dispc_mgr_enable_stallmode(dssdev->manager->id, true);
4260 dispc_mgr_enable_fifohandcheck(dssdev->manager->id, 1); 4374 dispc_mgr_enable_fifohandcheck(dssdev->manager->id, 1);
4261 4375
4262 dispc_mgr_set_lcd_timings(dssdev->manager->id, &timings); 4376 dss_mgr_set_timings(dssdev->manager, &timings);
4263 } else { 4377 } else {
4264 dispc_mgr_enable_stallmode(dssdev->manager->id, false); 4378 dispc_mgr_enable_stallmode(dssdev->manager->id, false);
4265 dispc_mgr_enable_fifohandcheck(dssdev->manager->id, 0); 4379 dispc_mgr_enable_fifohandcheck(dssdev->manager->id, 0);
4266 4380
4267 dispc_mgr_set_lcd_timings(dssdev->manager->id, 4381 dss_mgr_set_timings(dssdev->manager, &dssdev->panel.timings);
4268 &dssdev->panel.timings);
4269 } 4382 }
4270 4383
4271 dispc_mgr_set_lcd_display_type(dssdev->manager->id, 4384 dispc_mgr_set_lcd_display_type(dssdev->manager->id,
@@ -4294,13 +4407,11 @@ static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
4294 struct dsi_clock_info cinfo; 4407 struct dsi_clock_info cinfo;
4295 int r; 4408 int r;
4296 4409
4297 /* we always use DSS_CLK_SYSCK as input clock */
4298 cinfo.use_sys_clk = true;
4299 cinfo.regn = dssdev->clocks.dsi.regn; 4410 cinfo.regn = dssdev->clocks.dsi.regn;
4300 cinfo.regm = dssdev->clocks.dsi.regm; 4411 cinfo.regm = dssdev->clocks.dsi.regm;
4301 cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc; 4412 cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc;
4302 cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi; 4413 cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi;
4303 r = dsi_calc_clock_rates(dssdev, &cinfo); 4414 r = dsi_calc_clock_rates(dsidev, &cinfo);
4304 if (r) { 4415 if (r) {
4305 DSSERR("Failed to calc dsi clocks\n"); 4416 DSSERR("Failed to calc dsi clocks\n");
4306 return r; 4417 return r;
@@ -4345,7 +4456,7 @@ static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
4345static int dsi_display_init_dsi(struct omap_dss_device *dssdev) 4456static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
4346{ 4457{
4347 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4458 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4348 int dsi_module = dsi_get_dsidev_id(dsidev); 4459 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4349 int r; 4460 int r;
4350 4461
4351 r = dsi_pll_init(dsidev, true, true); 4462 r = dsi_pll_init(dsidev, true, true);
@@ -4357,7 +4468,7 @@ static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
4357 goto err1; 4468 goto err1;
4358 4469
4359 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src); 4470 dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
4360 dss_select_dsi_clk_source(dsi_module, dssdev->clocks.dsi.dsi_fclk_src); 4471 dss_select_dsi_clk_source(dsi->module_id, dssdev->clocks.dsi.dsi_fclk_src);
4361 dss_select_lcd_clk_source(dssdev->manager->id, 4472 dss_select_lcd_clk_source(dssdev->manager->id,
4362 dssdev->clocks.dispc.channel.lcd_clk_src); 4473 dssdev->clocks.dispc.channel.lcd_clk_src);
4363 4474
@@ -4396,7 +4507,7 @@ err3:
4396 dsi_cio_uninit(dssdev); 4507 dsi_cio_uninit(dssdev);
4397err2: 4508err2:
4398 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK); 4509 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
4399 dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK); 4510 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
4400 dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK); 4511 dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
4401 4512
4402err1: 4513err1:
@@ -4410,7 +4521,6 @@ static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
4410{ 4521{
4411 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4522 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4412 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4523 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4413 int dsi_module = dsi_get_dsidev_id(dsidev);
4414 4524
4415 if (enter_ulps && !dsi->ulps_enabled) 4525 if (enter_ulps && !dsi->ulps_enabled)
4416 dsi_enter_ulps(dsidev); 4526 dsi_enter_ulps(dsidev);
@@ -4423,7 +4533,7 @@ static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
4423 dsi_vc_enable(dsidev, 3, 0); 4533 dsi_vc_enable(dsidev, 3, 0);
4424 4534
4425 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK); 4535 dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
4426 dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK); 4536 dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
4427 dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK); 4537 dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
4428 dsi_cio_uninit(dssdev); 4538 dsi_cio_uninit(dssdev);
4429 dsi_pll_uninit(dsidev, disconnect_lanes); 4539 dsi_pll_uninit(dsidev, disconnect_lanes);
@@ -4527,7 +4637,7 @@ int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
4527} 4637}
4528EXPORT_SYMBOL(omapdss_dsi_enable_te); 4638EXPORT_SYMBOL(omapdss_dsi_enable_te);
4529 4639
4530int dsi_init_display(struct omap_dss_device *dssdev) 4640static int __init dsi_init_display(struct omap_dss_device *dssdev)
4531{ 4641{
4532 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev); 4642 struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
4533 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4643 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
@@ -4680,13 +4790,39 @@ static void dsi_put_clocks(struct platform_device *dsidev)
4680 clk_put(dsi->sys_clk); 4790 clk_put(dsi->sys_clk);
4681} 4791}
4682 4792
4793static void __init dsi_probe_pdata(struct platform_device *dsidev)
4794{
4795 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4796 struct omap_dss_board_info *pdata = dsidev->dev.platform_data;
4797 int i, r;
4798
4799 for (i = 0; i < pdata->num_devices; ++i) {
4800 struct omap_dss_device *dssdev = pdata->devices[i];
4801
4802 if (dssdev->type != OMAP_DISPLAY_TYPE_DSI)
4803 continue;
4804
4805 if (dssdev->phy.dsi.module != dsi->module_id)
4806 continue;
4807
4808 r = dsi_init_display(dssdev);
4809 if (r) {
4810 DSSERR("device %s init failed: %d\n", dssdev->name, r);
4811 continue;
4812 }
4813
4814 r = omap_dss_register_device(dssdev, &dsidev->dev, i);
4815 if (r)
4816 DSSERR("device %s register failed: %d\n",
4817 dssdev->name, r);
4818 }
4819}
4820
4683/* DSI1 HW IP initialisation */ 4821/* DSI1 HW IP initialisation */
4684static int omap_dsihw_probe(struct platform_device *dsidev) 4822static int __init omap_dsihw_probe(struct platform_device *dsidev)
4685{ 4823{
4686 struct omap_display_platform_data *dss_plat_data;
4687 struct omap_dss_board_info *board_info;
4688 u32 rev; 4824 u32 rev;
4689 int r, i, dsi_module = dsi_get_dsidev_id(dsidev); 4825 int r, i;
4690 struct resource *dsi_mem; 4826 struct resource *dsi_mem;
4691 struct dsi_data *dsi; 4827 struct dsi_data *dsi;
4692 4828
@@ -4694,15 +4830,11 @@ static int omap_dsihw_probe(struct platform_device *dsidev)
4694 if (!dsi) 4830 if (!dsi)
4695 return -ENOMEM; 4831 return -ENOMEM;
4696 4832
4833 dsi->module_id = dsidev->id;
4697 dsi->pdev = dsidev; 4834 dsi->pdev = dsidev;
4698 dsi_pdev_map[dsi_module] = dsidev; 4835 dsi_pdev_map[dsi->module_id] = dsidev;
4699 dev_set_drvdata(&dsidev->dev, dsi); 4836 dev_set_drvdata(&dsidev->dev, dsi);
4700 4837
4701 dss_plat_data = dsidev->dev.platform_data;
4702 board_info = dss_plat_data->board_data;
4703 dsi->enable_pads = board_info->dsi_enable_pads;
4704 dsi->disable_pads = board_info->dsi_disable_pads;
4705
4706 spin_lock_init(&dsi->irq_lock); 4838 spin_lock_init(&dsi->irq_lock);
4707 spin_lock_init(&dsi->errors_lock); 4839 spin_lock_init(&dsi->errors_lock);
4708 dsi->errors = 0; 4840 dsi->errors = 0;
@@ -4780,8 +4912,21 @@ static int omap_dsihw_probe(struct platform_device *dsidev)
4780 else 4912 else
4781 dsi->num_lanes_supported = 3; 4913 dsi->num_lanes_supported = 3;
4782 4914
4915 dsi_probe_pdata(dsidev);
4916
4783 dsi_runtime_put(dsidev); 4917 dsi_runtime_put(dsidev);
4784 4918
4919 if (dsi->module_id == 0)
4920 dss_debugfs_create_file("dsi1_regs", dsi1_dump_regs);
4921 else if (dsi->module_id == 1)
4922 dss_debugfs_create_file("dsi2_regs", dsi2_dump_regs);
4923
4924#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
4925 if (dsi->module_id == 0)
4926 dss_debugfs_create_file("dsi1_irqs", dsi1_dump_irqs);
4927 else if (dsi->module_id == 1)
4928 dss_debugfs_create_file("dsi2_irqs", dsi2_dump_irqs);
4929#endif
4785 return 0; 4930 return 0;
4786 4931
4787err_runtime_get: 4932err_runtime_get:
@@ -4790,12 +4935,14 @@ err_runtime_get:
4790 return r; 4935 return r;
4791} 4936}
4792 4937
4793static int omap_dsihw_remove(struct platform_device *dsidev) 4938static int __exit omap_dsihw_remove(struct platform_device *dsidev)
4794{ 4939{
4795 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev); 4940 struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
4796 4941
4797 WARN_ON(dsi->scp_clk_refcount > 0); 4942 WARN_ON(dsi->scp_clk_refcount > 0);
4798 4943
4944 omap_dss_unregister_child_devices(&dsidev->dev);
4945
4799 pm_runtime_disable(&dsidev->dev); 4946 pm_runtime_disable(&dsidev->dev);
4800 4947
4801 dsi_put_clocks(dsidev); 4948 dsi_put_clocks(dsidev);
@@ -4816,7 +4963,6 @@ static int omap_dsihw_remove(struct platform_device *dsidev)
4816static int dsi_runtime_suspend(struct device *dev) 4963static int dsi_runtime_suspend(struct device *dev)
4817{ 4964{
4818 dispc_runtime_put(); 4965 dispc_runtime_put();
4819 dss_runtime_put();
4820 4966
4821 return 0; 4967 return 0;
4822} 4968}
@@ -4825,20 +4971,11 @@ static int dsi_runtime_resume(struct device *dev)
4825{ 4971{
4826 int r; 4972 int r;
4827 4973
4828 r = dss_runtime_get();
4829 if (r)
4830 goto err_get_dss;
4831
4832 r = dispc_runtime_get(); 4974 r = dispc_runtime_get();
4833 if (r) 4975 if (r)
4834 goto err_get_dispc; 4976 return r;
4835 4977
4836 return 0; 4978 return 0;
4837
4838err_get_dispc:
4839 dss_runtime_put();
4840err_get_dss:
4841 return r;
4842} 4979}
4843 4980
4844static const struct dev_pm_ops dsi_pm_ops = { 4981static const struct dev_pm_ops dsi_pm_ops = {
@@ -4847,8 +4984,7 @@ static const struct dev_pm_ops dsi_pm_ops = {
4847}; 4984};
4848 4985
4849static struct platform_driver omap_dsihw_driver = { 4986static struct platform_driver omap_dsihw_driver = {
4850 .probe = omap_dsihw_probe, 4987 .remove = __exit_p(omap_dsihw_remove),
4851 .remove = omap_dsihw_remove,
4852 .driver = { 4988 .driver = {
4853 .name = "omapdss_dsi", 4989 .name = "omapdss_dsi",
4854 .owner = THIS_MODULE, 4990 .owner = THIS_MODULE,
@@ -4856,12 +4992,12 @@ static struct platform_driver omap_dsihw_driver = {
4856 }, 4992 },
4857}; 4993};
4858 4994
4859int dsi_init_platform_driver(void) 4995int __init dsi_init_platform_driver(void)
4860{ 4996{
4861 return platform_driver_register(&omap_dsihw_driver); 4997 return platform_driver_probe(&omap_dsihw_driver, omap_dsihw_probe);
4862} 4998}
4863 4999
4864void dsi_uninit_platform_driver(void) 5000void __exit dsi_uninit_platform_driver(void)
4865{ 5001{
4866 return platform_driver_unregister(&omap_dsihw_driver); 5002 platform_driver_unregister(&omap_dsihw_driver);
4867} 5003}
diff --git a/drivers/video/omap2/dss/dss.c b/drivers/video/omap2/dss/dss.c
index bd2d5e159463..6ea1ff149f6f 100644
--- a/drivers/video/omap2/dss/dss.c
+++ b/drivers/video/omap2/dss/dss.c
@@ -62,6 +62,9 @@ struct dss_reg {
62#define REG_FLD_MOD(idx, val, start, end) \ 62#define REG_FLD_MOD(idx, val, start, end) \
63 dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end)) 63 dss_write_reg(idx, FLD_MOD(dss_read_reg(idx), val, start, end))
64 64
65static int dss_runtime_get(void);
66static void dss_runtime_put(void);
67
65static struct { 68static struct {
66 struct platform_device *pdev; 69 struct platform_device *pdev;
67 void __iomem *base; 70 void __iomem *base;
@@ -277,7 +280,7 @@ void dss_dump_clocks(struct seq_file *s)
277 dss_runtime_put(); 280 dss_runtime_put();
278} 281}
279 282
280void dss_dump_regs(struct seq_file *s) 283static void dss_dump_regs(struct seq_file *s)
281{ 284{
282#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r)) 285#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dss_read_reg(r))
283 286
@@ -322,6 +325,7 @@ void dss_select_dispc_clk_source(enum omap_dss_clk_source clk_src)
322 break; 325 break;
323 default: 326 default:
324 BUG(); 327 BUG();
328 return;
325 } 329 }
326 330
327 dss_feat_get_reg_field(FEAT_REG_DISPC_CLK_SWITCH, &start, &end); 331 dss_feat_get_reg_field(FEAT_REG_DISPC_CLK_SWITCH, &start, &end);
@@ -335,7 +339,7 @@ void dss_select_dsi_clk_source(int dsi_module,
335 enum omap_dss_clk_source clk_src) 339 enum omap_dss_clk_source clk_src)
336{ 340{
337 struct platform_device *dsidev; 341 struct platform_device *dsidev;
338 int b; 342 int b, pos;
339 343
340 switch (clk_src) { 344 switch (clk_src) {
341 case OMAP_DSS_CLK_SRC_FCK: 345 case OMAP_DSS_CLK_SRC_FCK:
@@ -355,9 +359,11 @@ void dss_select_dsi_clk_source(int dsi_module,
355 break; 359 break;
356 default: 360 default:
357 BUG(); 361 BUG();
362 return;
358 } 363 }
359 364
360 REG_FLD_MOD(DSS_CONTROL, b, 1, 1); /* DSI_CLK_SWITCH */ 365 pos = dsi_module == 0 ? 1 : 10;
366 REG_FLD_MOD(DSS_CONTROL, b, pos, pos); /* DSIx_CLK_SWITCH */
361 367
362 dss.dsi_clk_source[dsi_module] = clk_src; 368 dss.dsi_clk_source[dsi_module] = clk_src;
363} 369}
@@ -389,6 +395,7 @@ void dss_select_lcd_clk_source(enum omap_channel channel,
389 break; 395 break;
390 default: 396 default:
391 BUG(); 397 BUG();
398 return;
392 } 399 }
393 400
394 pos = channel == OMAP_DSS_CHANNEL_LCD ? 0 : 12; 401 pos = channel == OMAP_DSS_CHANNEL_LCD ? 0 : 12;
@@ -706,7 +713,7 @@ static void dss_put_clocks(void)
706 clk_put(dss.dss_clk); 713 clk_put(dss.dss_clk);
707} 714}
708 715
709int dss_runtime_get(void) 716static int dss_runtime_get(void)
710{ 717{
711 int r; 718 int r;
712 719
@@ -717,7 +724,7 @@ int dss_runtime_get(void)
717 return r < 0 ? r : 0; 724 return r < 0 ? r : 0;
718} 725}
719 726
720void dss_runtime_put(void) 727static void dss_runtime_put(void)
721{ 728{
722 int r; 729 int r;
723 730
@@ -740,7 +747,7 @@ void dss_debug_dump_clocks(struct seq_file *s)
740#endif 747#endif
741 748
742/* DSS HW IP initialisation */ 749/* DSS HW IP initialisation */
743static int omap_dsshw_probe(struct platform_device *pdev) 750static int __init omap_dsshw_probe(struct platform_device *pdev)
744{ 751{
745 struct resource *dss_mem; 752 struct resource *dss_mem;
746 u32 rev; 753 u32 rev;
@@ -785,40 +792,24 @@ static int omap_dsshw_probe(struct platform_device *pdev)
785 dss.lcd_clk_source[0] = OMAP_DSS_CLK_SRC_FCK; 792 dss.lcd_clk_source[0] = OMAP_DSS_CLK_SRC_FCK;
786 dss.lcd_clk_source[1] = OMAP_DSS_CLK_SRC_FCK; 793 dss.lcd_clk_source[1] = OMAP_DSS_CLK_SRC_FCK;
787 794
788 r = dpi_init();
789 if (r) {
790 DSSERR("Failed to initialize DPI\n");
791 goto err_dpi;
792 }
793
794 r = sdi_init();
795 if (r) {
796 DSSERR("Failed to initialize SDI\n");
797 goto err_sdi;
798 }
799
800 rev = dss_read_reg(DSS_REVISION); 795 rev = dss_read_reg(DSS_REVISION);
801 printk(KERN_INFO "OMAP DSS rev %d.%d\n", 796 printk(KERN_INFO "OMAP DSS rev %d.%d\n",
802 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); 797 FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
803 798
804 dss_runtime_put(); 799 dss_runtime_put();
805 800
801 dss_debugfs_create_file("dss", dss_dump_regs);
802
806 return 0; 803 return 0;
807err_sdi: 804
808 dpi_exit();
809err_dpi:
810 dss_runtime_put();
811err_runtime_get: 805err_runtime_get:
812 pm_runtime_disable(&pdev->dev); 806 pm_runtime_disable(&pdev->dev);
813 dss_put_clocks(); 807 dss_put_clocks();
814 return r; 808 return r;
815} 809}
816 810
817static int omap_dsshw_remove(struct platform_device *pdev) 811static int __exit omap_dsshw_remove(struct platform_device *pdev)
818{ 812{
819 dpi_exit();
820 sdi_exit();
821
822 pm_runtime_disable(&pdev->dev); 813 pm_runtime_disable(&pdev->dev);
823 814
824 dss_put_clocks(); 815 dss_put_clocks();
@@ -829,11 +820,24 @@ static int omap_dsshw_remove(struct platform_device *pdev)
829static int dss_runtime_suspend(struct device *dev) 820static int dss_runtime_suspend(struct device *dev)
830{ 821{
831 dss_save_context(); 822 dss_save_context();
823 dss_set_min_bus_tput(dev, 0);
832 return 0; 824 return 0;
833} 825}
834 826
835static int dss_runtime_resume(struct device *dev) 827static int dss_runtime_resume(struct device *dev)
836{ 828{
829 int r;
830 /*
831 * Set an arbitrarily high tput request to ensure OPP100.
832 * What we should really do is to make a request to stay in OPP100,
833 * without any tput requirements, but that is not currently possible
834 * via the PM layer.
835 */
836
837 r = dss_set_min_bus_tput(dev, 1000000000);
838 if (r)
839 return r;
840
837 dss_restore_context(); 841 dss_restore_context();
838 return 0; 842 return 0;
839} 843}
@@ -844,8 +848,7 @@ static const struct dev_pm_ops dss_pm_ops = {
844}; 848};
845 849
846static struct platform_driver omap_dsshw_driver = { 850static struct platform_driver omap_dsshw_driver = {
847 .probe = omap_dsshw_probe, 851 .remove = __exit_p(omap_dsshw_remove),
848 .remove = omap_dsshw_remove,
849 .driver = { 852 .driver = {
850 .name = "omapdss_dss", 853 .name = "omapdss_dss",
851 .owner = THIS_MODULE, 854 .owner = THIS_MODULE,
@@ -853,12 +856,12 @@ static struct platform_driver omap_dsshw_driver = {
853 }, 856 },
854}; 857};
855 858
856int dss_init_platform_driver(void) 859int __init dss_init_platform_driver(void)
857{ 860{
858 return platform_driver_register(&omap_dsshw_driver); 861 return platform_driver_probe(&omap_dsshw_driver, omap_dsshw_probe);
859} 862}
860 863
861void dss_uninit_platform_driver(void) 864void dss_uninit_platform_driver(void)
862{ 865{
863 return platform_driver_unregister(&omap_dsshw_driver); 866 platform_driver_unregister(&omap_dsshw_driver);
864} 867}
diff --git a/drivers/video/omap2/dss/dss.h b/drivers/video/omap2/dss/dss.h
index d4b3dff2ead3..dd1092ceaeef 100644
--- a/drivers/video/omap2/dss/dss.h
+++ b/drivers/video/omap2/dss/dss.h
@@ -150,9 +150,6 @@ struct dsi_clock_info {
150 u16 regm_dsi; /* OMAP3: REGM4 150 u16 regm_dsi; /* OMAP3: REGM4
151 * OMAP4: REGM5 */ 151 * OMAP4: REGM5 */
152 u16 lp_clk_div; 152 u16 lp_clk_div;
153
154 u8 highfreq;
155 bool use_sys_clk;
156}; 153};
157 154
158struct seq_file; 155struct seq_file;
@@ -162,6 +159,16 @@ struct platform_device;
162struct bus_type *dss_get_bus(void); 159struct bus_type *dss_get_bus(void);
163struct regulator *dss_get_vdds_dsi(void); 160struct regulator *dss_get_vdds_dsi(void);
164struct regulator *dss_get_vdds_sdi(void); 161struct regulator *dss_get_vdds_sdi(void);
162int dss_get_ctx_loss_count(struct device *dev);
163int dss_dsi_enable_pads(int dsi_id, unsigned lane_mask);
164void dss_dsi_disable_pads(int dsi_id, unsigned lane_mask);
165int dss_set_min_bus_tput(struct device *dev, unsigned long tput);
166int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *));
167
168int omap_dss_register_device(struct omap_dss_device *dssdev,
169 struct device *parent, int disp_num);
170void omap_dss_unregister_device(struct omap_dss_device *dssdev);
171void omap_dss_unregister_child_devices(struct device *parent);
165 172
166/* apply */ 173/* apply */
167void dss_apply_init(void); 174void dss_apply_init(void);
@@ -179,6 +186,9 @@ void dss_mgr_get_info(struct omap_overlay_manager *mgr,
179int dss_mgr_set_device(struct omap_overlay_manager *mgr, 186int dss_mgr_set_device(struct omap_overlay_manager *mgr,
180 struct omap_dss_device *dssdev); 187 struct omap_dss_device *dssdev);
181int dss_mgr_unset_device(struct omap_overlay_manager *mgr); 188int dss_mgr_unset_device(struct omap_overlay_manager *mgr);
189void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
190 struct omap_video_timings *timings);
191const struct omap_video_timings *dss_mgr_get_timings(struct omap_overlay_manager *mgr);
182 192
183bool dss_ovl_is_enabled(struct omap_overlay *ovl); 193bool dss_ovl_is_enabled(struct omap_overlay *ovl);
184int dss_ovl_enable(struct omap_overlay *ovl); 194int dss_ovl_enable(struct omap_overlay *ovl);
@@ -208,9 +218,11 @@ int dss_init_overlay_managers(struct platform_device *pdev);
208void dss_uninit_overlay_managers(struct platform_device *pdev); 218void dss_uninit_overlay_managers(struct platform_device *pdev);
209int dss_mgr_simple_check(struct omap_overlay_manager *mgr, 219int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
210 const struct omap_overlay_manager_info *info); 220 const struct omap_overlay_manager_info *info);
221int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
222 const struct omap_video_timings *timings);
211int dss_mgr_check(struct omap_overlay_manager *mgr, 223int dss_mgr_check(struct omap_overlay_manager *mgr,
212 struct omap_dss_device *dssdev,
213 struct omap_overlay_manager_info *info, 224 struct omap_overlay_manager_info *info,
225 const struct omap_video_timings *mgr_timings,
214 struct omap_overlay_info **overlay_infos); 226 struct omap_overlay_info **overlay_infos);
215 227
216/* overlay */ 228/* overlay */
@@ -220,22 +232,18 @@ void dss_overlay_setup_dispc_manager(struct omap_overlay_manager *mgr);
220void dss_recheck_connections(struct omap_dss_device *dssdev, bool force); 232void dss_recheck_connections(struct omap_dss_device *dssdev, bool force);
221int dss_ovl_simple_check(struct omap_overlay *ovl, 233int dss_ovl_simple_check(struct omap_overlay *ovl,
222 const struct omap_overlay_info *info); 234 const struct omap_overlay_info *info);
223int dss_ovl_check(struct omap_overlay *ovl, 235int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info,
224 struct omap_overlay_info *info, struct omap_dss_device *dssdev); 236 const struct omap_video_timings *mgr_timings);
225 237
226/* DSS */ 238/* DSS */
227int dss_init_platform_driver(void); 239int dss_init_platform_driver(void) __init;
228void dss_uninit_platform_driver(void); 240void dss_uninit_platform_driver(void);
229 241
230int dss_runtime_get(void);
231void dss_runtime_put(void);
232
233void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select); 242void dss_select_hdmi_venc_clk_source(enum dss_hdmi_venc_clk_source_select);
234enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void); 243enum dss_hdmi_venc_clk_source_select dss_get_hdmi_venc_clk_source(void);
235const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src); 244const char *dss_get_generic_clk_source_name(enum omap_dss_clk_source clk_src);
236void dss_dump_clocks(struct seq_file *s); 245void dss_dump_clocks(struct seq_file *s);
237 246
238void dss_dump_regs(struct seq_file *s);
239#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT) 247#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_OMAP2_DSS_DEBUG_SUPPORT)
240void dss_debug_dump_clocks(struct seq_file *s); 248void dss_debug_dump_clocks(struct seq_file *s);
241#endif 249#endif
@@ -265,19 +273,8 @@ int dss_calc_clock_div(bool is_tft, unsigned long req_pck,
265 struct dispc_clock_info *dispc_cinfo); 273 struct dispc_clock_info *dispc_cinfo);
266 274
267/* SDI */ 275/* SDI */
268#ifdef CONFIG_OMAP2_DSS_SDI 276int sdi_init_platform_driver(void) __init;
269int sdi_init(void); 277void sdi_uninit_platform_driver(void) __exit;
270void sdi_exit(void);
271int sdi_init_display(struct omap_dss_device *display);
272#else
273static inline int sdi_init(void)
274{
275 return 0;
276}
277static inline void sdi_exit(void)
278{
279}
280#endif
281 278
282/* DSI */ 279/* DSI */
283#ifdef CONFIG_OMAP2_DSS_DSI 280#ifdef CONFIG_OMAP2_DSS_DSI
@@ -285,19 +282,14 @@ static inline void sdi_exit(void)
285struct dentry; 282struct dentry;
286struct file_operations; 283struct file_operations;
287 284
288int dsi_init_platform_driver(void); 285int dsi_init_platform_driver(void) __init;
289void dsi_uninit_platform_driver(void); 286void dsi_uninit_platform_driver(void) __exit;
290 287
291int dsi_runtime_get(struct platform_device *dsidev); 288int dsi_runtime_get(struct platform_device *dsidev);
292void dsi_runtime_put(struct platform_device *dsidev); 289void dsi_runtime_put(struct platform_device *dsidev);
293 290
294void dsi_dump_clocks(struct seq_file *s); 291void dsi_dump_clocks(struct seq_file *s);
295void dsi_create_debugfs_files_irq(struct dentry *debugfs_dir,
296 const struct file_operations *debug_fops);
297void dsi_create_debugfs_files_reg(struct dentry *debugfs_dir,
298 const struct file_operations *debug_fops);
299 292
300int dsi_init_display(struct omap_dss_device *display);
301void dsi_irq_handler(void); 293void dsi_irq_handler(void);
302u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt); 294u8 dsi_get_pixel_size(enum omap_dss_dsi_pixel_format fmt);
303 295
@@ -314,13 +306,6 @@ void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev);
314void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev); 306void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev);
315struct platform_device *dsi_get_dsidev_from_id(int module); 307struct platform_device *dsi_get_dsidev_from_id(int module);
316#else 308#else
317static inline int dsi_init_platform_driver(void)
318{
319 return 0;
320}
321static inline void dsi_uninit_platform_driver(void)
322{
323}
324static inline int dsi_runtime_get(struct platform_device *dsidev) 309static inline int dsi_runtime_get(struct platform_device *dsidev)
325{ 310{
326 return 0; 311 return 0;
@@ -377,28 +362,14 @@ static inline struct platform_device *dsi_get_dsidev_from_id(int module)
377#endif 362#endif
378 363
379/* DPI */ 364/* DPI */
380#ifdef CONFIG_OMAP2_DSS_DPI 365int dpi_init_platform_driver(void) __init;
381int dpi_init(void); 366void dpi_uninit_platform_driver(void) __exit;
382void dpi_exit(void);
383int dpi_init_display(struct omap_dss_device *dssdev);
384#else
385static inline int dpi_init(void)
386{
387 return 0;
388}
389static inline void dpi_exit(void)
390{
391}
392#endif
393 367
394/* DISPC */ 368/* DISPC */
395int dispc_init_platform_driver(void); 369int dispc_init_platform_driver(void) __init;
396void dispc_uninit_platform_driver(void); 370void dispc_uninit_platform_driver(void) __exit;
397void dispc_dump_clocks(struct seq_file *s); 371void dispc_dump_clocks(struct seq_file *s);
398void dispc_dump_irqs(struct seq_file *s);
399void dispc_dump_regs(struct seq_file *s);
400void dispc_irq_handler(void); 372void dispc_irq_handler(void);
401void dispc_fake_vsync_irq(void);
402 373
403int dispc_runtime_get(void); 374int dispc_runtime_get(void);
404void dispc_runtime_put(void); 375void dispc_runtime_put(void);
@@ -409,12 +380,12 @@ void dispc_disable_sidle(void);
409void dispc_lcd_enable_signal_polarity(bool act_high); 380void dispc_lcd_enable_signal_polarity(bool act_high);
410void dispc_lcd_enable_signal(bool enable); 381void dispc_lcd_enable_signal(bool enable);
411void dispc_pck_free_enable(bool enable); 382void dispc_pck_free_enable(bool enable);
412void dispc_set_digit_size(u16 width, u16 height);
413void dispc_enable_fifomerge(bool enable); 383void dispc_enable_fifomerge(bool enable);
414void dispc_enable_gamma_table(bool enable); 384void dispc_enable_gamma_table(bool enable);
415void dispc_set_loadmode(enum omap_dss_load_mode mode); 385void dispc_set_loadmode(enum omap_dss_load_mode mode);
416 386
417bool dispc_lcd_timings_ok(struct omap_video_timings *timings); 387bool dispc_mgr_timings_ok(enum omap_channel channel,
388 const struct omap_video_timings *timings);
418unsigned long dispc_fclk_rate(void); 389unsigned long dispc_fclk_rate(void);
419void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck, 390void dispc_find_clk_divs(bool is_tft, unsigned long req_pck, unsigned long fck,
420 struct dispc_clock_info *cinfo); 391 struct dispc_clock_info *cinfo);
@@ -424,15 +395,16 @@ int dispc_calc_clock_rates(unsigned long dispc_fclk_rate,
424 395
425void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high); 396void dispc_ovl_set_fifo_threshold(enum omap_plane plane, u32 low, u32 high);
426void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane, 397void dispc_ovl_compute_fifo_thresholds(enum omap_plane plane,
427 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge); 398 u32 *fifo_low, u32 *fifo_high, bool use_fifomerge,
399 bool manual_update);
428int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi, 400int dispc_ovl_setup(enum omap_plane plane, struct omap_overlay_info *oi,
429 bool ilace, bool replication); 401 bool ilace, bool replication,
402 const struct omap_video_timings *mgr_timings);
430int dispc_ovl_enable(enum omap_plane plane, bool enable); 403int dispc_ovl_enable(enum omap_plane plane, bool enable);
431void dispc_ovl_set_channel_out(enum omap_plane plane, 404void dispc_ovl_set_channel_out(enum omap_plane plane,
432 enum omap_channel channel); 405 enum omap_channel channel);
433 406
434void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable); 407void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable);
435void dispc_mgr_set_lcd_size(enum omap_channel channel, u16 width, u16 height);
436u32 dispc_mgr_get_vsync_irq(enum omap_channel channel); 408u32 dispc_mgr_get_vsync_irq(enum omap_channel channel);
437u32 dispc_mgr_get_framedone_irq(enum omap_channel channel); 409u32 dispc_mgr_get_framedone_irq(enum omap_channel channel);
438bool dispc_mgr_go_busy(enum omap_channel channel); 410bool dispc_mgr_go_busy(enum omap_channel channel);
@@ -445,12 +417,13 @@ void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable);
445void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines); 417void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines);
446void dispc_mgr_set_lcd_display_type(enum omap_channel channel, 418void dispc_mgr_set_lcd_display_type(enum omap_channel channel,
447 enum omap_lcd_display_type type); 419 enum omap_lcd_display_type type);
448void dispc_mgr_set_lcd_timings(enum omap_channel channel, 420void dispc_mgr_set_timings(enum omap_channel channel,
449 struct omap_video_timings *timings); 421 struct omap_video_timings *timings);
450void dispc_mgr_set_pol_freq(enum omap_channel channel, 422void dispc_mgr_set_pol_freq(enum omap_channel channel,
451 enum omap_panel_config config, u8 acbi, u8 acb); 423 enum omap_panel_config config, u8 acbi, u8 acb);
452unsigned long dispc_mgr_lclk_rate(enum omap_channel channel); 424unsigned long dispc_mgr_lclk_rate(enum omap_channel channel);
453unsigned long dispc_mgr_pclk_rate(enum omap_channel channel); 425unsigned long dispc_mgr_pclk_rate(enum omap_channel channel);
426unsigned long dispc_core_clk_rate(void);
454int dispc_mgr_set_clock_div(enum omap_channel channel, 427int dispc_mgr_set_clock_div(enum omap_channel channel,
455 struct dispc_clock_info *cinfo); 428 struct dispc_clock_info *cinfo);
456int dispc_mgr_get_clock_div(enum omap_channel channel, 429int dispc_mgr_get_clock_div(enum omap_channel channel,
@@ -460,19 +433,10 @@ void dispc_mgr_setup(enum omap_channel channel,
460 433
461/* VENC */ 434/* VENC */
462#ifdef CONFIG_OMAP2_DSS_VENC 435#ifdef CONFIG_OMAP2_DSS_VENC
463int venc_init_platform_driver(void); 436int venc_init_platform_driver(void) __init;
464void venc_uninit_platform_driver(void); 437void venc_uninit_platform_driver(void) __exit;
465void venc_dump_regs(struct seq_file *s);
466int venc_init_display(struct omap_dss_device *display);
467unsigned long venc_get_pixel_clock(void); 438unsigned long venc_get_pixel_clock(void);
468#else 439#else
469static inline int venc_init_platform_driver(void)
470{
471 return 0;
472}
473static inline void venc_uninit_platform_driver(void)
474{
475}
476static inline unsigned long venc_get_pixel_clock(void) 440static inline unsigned long venc_get_pixel_clock(void)
477{ 441{
478 WARN("%s: VENC not compiled in, returning pclk as 0\n", __func__); 442 WARN("%s: VENC not compiled in, returning pclk as 0\n", __func__);
@@ -482,23 +446,10 @@ static inline unsigned long venc_get_pixel_clock(void)
482 446
483/* HDMI */ 447/* HDMI */
484#ifdef CONFIG_OMAP4_DSS_HDMI 448#ifdef CONFIG_OMAP4_DSS_HDMI
485int hdmi_init_platform_driver(void); 449int hdmi_init_platform_driver(void) __init;
486void hdmi_uninit_platform_driver(void); 450void hdmi_uninit_platform_driver(void) __exit;
487int hdmi_init_display(struct omap_dss_device *dssdev);
488unsigned long hdmi_get_pixel_clock(void); 451unsigned long hdmi_get_pixel_clock(void);
489void hdmi_dump_regs(struct seq_file *s);
490#else 452#else
491static inline int hdmi_init_display(struct omap_dss_device *dssdev)
492{
493 return 0;
494}
495static inline int hdmi_init_platform_driver(void)
496{
497 return 0;
498}
499static inline void hdmi_uninit_platform_driver(void)
500{
501}
502static inline unsigned long hdmi_get_pixel_clock(void) 453static inline unsigned long hdmi_get_pixel_clock(void)
503{ 454{
504 WARN("%s: HDMI not compiled in, returning pclk as 0\n", __func__); 455 WARN("%s: HDMI not compiled in, returning pclk as 0\n", __func__);
@@ -514,22 +465,18 @@ int omapdss_hdmi_read_edid(u8 *buf, int len);
514bool omapdss_hdmi_detect(void); 465bool omapdss_hdmi_detect(void);
515int hdmi_panel_init(void); 466int hdmi_panel_init(void);
516void hdmi_panel_exit(void); 467void hdmi_panel_exit(void);
468#ifdef CONFIG_OMAP4_DSS_HDMI_AUDIO
469int hdmi_audio_enable(void);
470void hdmi_audio_disable(void);
471int hdmi_audio_start(void);
472void hdmi_audio_stop(void);
473bool hdmi_mode_has_audio(void);
474int hdmi_audio_config(struct omap_dss_audio *audio);
475#endif
517 476
518/* RFBI */ 477/* RFBI */
519#ifdef CONFIG_OMAP2_DSS_RFBI 478int rfbi_init_platform_driver(void) __init;
520int rfbi_init_platform_driver(void); 479void rfbi_uninit_platform_driver(void) __exit;
521void rfbi_uninit_platform_driver(void);
522void rfbi_dump_regs(struct seq_file *s);
523int rfbi_init_display(struct omap_dss_device *display);
524#else
525static inline int rfbi_init_platform_driver(void)
526{
527 return 0;
528}
529static inline void rfbi_uninit_platform_driver(void)
530{
531}
532#endif
533 480
534 481
535#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS 482#ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
diff --git a/drivers/video/omap2/dss/dss_features.c b/drivers/video/omap2/dss/dss_features.c
index ce14aa6dd672..938709724f0c 100644
--- a/drivers/video/omap2/dss/dss_features.c
+++ b/drivers/video/omap2/dss/dss_features.c
@@ -52,6 +52,8 @@ struct omap_dss_features {
52 const char * const *clksrc_names; 52 const char * const *clksrc_names;
53 const struct dss_param_range *dss_params; 53 const struct dss_param_range *dss_params;
54 54
55 const enum omap_dss_rotation_type supported_rotation_types;
56
55 const u32 buffer_size_unit; 57 const u32 buffer_size_unit;
56 const u32 burst_size_unit; 58 const u32 burst_size_unit;
57}; 59};
@@ -311,6 +313,8 @@ static const struct dss_param_range omap2_dss_param_range[] = {
311 * scaler cannot scale a image with width more than 768. 313 * scaler cannot scale a image with width more than 768.
312 */ 314 */
313 [FEAT_PARAM_LINEWIDTH] = { 1, 768 }, 315 [FEAT_PARAM_LINEWIDTH] = { 1, 768 },
316 [FEAT_PARAM_MGR_WIDTH] = { 1, 2048 },
317 [FEAT_PARAM_MGR_HEIGHT] = { 1, 2048 },
314}; 318};
315 319
316static const struct dss_param_range omap3_dss_param_range[] = { 320static const struct dss_param_range omap3_dss_param_range[] = {
@@ -324,6 +328,8 @@ static const struct dss_param_range omap3_dss_param_range[] = {
324 [FEAT_PARAM_DSIPLL_LPDIV] = { 1, (1 << 13) - 1}, 328 [FEAT_PARAM_DSIPLL_LPDIV] = { 1, (1 << 13) - 1},
325 [FEAT_PARAM_DOWNSCALE] = { 1, 4 }, 329 [FEAT_PARAM_DOWNSCALE] = { 1, 4 },
326 [FEAT_PARAM_LINEWIDTH] = { 1, 1024 }, 330 [FEAT_PARAM_LINEWIDTH] = { 1, 1024 },
331 [FEAT_PARAM_MGR_WIDTH] = { 1, 2048 },
332 [FEAT_PARAM_MGR_HEIGHT] = { 1, 2048 },
327}; 333};
328 334
329static const struct dss_param_range omap4_dss_param_range[] = { 335static const struct dss_param_range omap4_dss_param_range[] = {
@@ -337,6 +343,8 @@ static const struct dss_param_range omap4_dss_param_range[] = {
337 [FEAT_PARAM_DSIPLL_LPDIV] = { 0, (1 << 13) - 1 }, 343 [FEAT_PARAM_DSIPLL_LPDIV] = { 0, (1 << 13) - 1 },
338 [FEAT_PARAM_DOWNSCALE] = { 1, 4 }, 344 [FEAT_PARAM_DOWNSCALE] = { 1, 4 },
339 [FEAT_PARAM_LINEWIDTH] = { 1, 2048 }, 345 [FEAT_PARAM_LINEWIDTH] = { 1, 2048 },
346 [FEAT_PARAM_MGR_WIDTH] = { 1, 2048 },
347 [FEAT_PARAM_MGR_HEIGHT] = { 1, 2048 },
340}; 348};
341 349
342static const enum dss_feat_id omap2_dss_feat_list[] = { 350static const enum dss_feat_id omap2_dss_feat_list[] = {
@@ -399,6 +407,7 @@ static const enum dss_feat_id omap4430_es1_0_dss_feat_list[] = {
399 FEAT_FIR_COEF_V, 407 FEAT_FIR_COEF_V,
400 FEAT_ALPHA_FREE_ZORDER, 408 FEAT_ALPHA_FREE_ZORDER,
401 FEAT_FIFO_MERGE, 409 FEAT_FIFO_MERGE,
410 FEAT_BURST_2D,
402}; 411};
403 412
404static const enum dss_feat_id omap4430_es2_0_1_2_dss_feat_list[] = { 413static const enum dss_feat_id omap4430_es2_0_1_2_dss_feat_list[] = {
@@ -416,6 +425,7 @@ static const enum dss_feat_id omap4430_es2_0_1_2_dss_feat_list[] = {
416 FEAT_FIR_COEF_V, 425 FEAT_FIR_COEF_V,
417 FEAT_ALPHA_FREE_ZORDER, 426 FEAT_ALPHA_FREE_ZORDER,
418 FEAT_FIFO_MERGE, 427 FEAT_FIFO_MERGE,
428 FEAT_BURST_2D,
419}; 429};
420 430
421static const enum dss_feat_id omap4_dss_feat_list[] = { 431static const enum dss_feat_id omap4_dss_feat_list[] = {
@@ -434,6 +444,7 @@ static const enum dss_feat_id omap4_dss_feat_list[] = {
434 FEAT_FIR_COEF_V, 444 FEAT_FIR_COEF_V,
435 FEAT_ALPHA_FREE_ZORDER, 445 FEAT_ALPHA_FREE_ZORDER,
436 FEAT_FIFO_MERGE, 446 FEAT_FIFO_MERGE,
447 FEAT_BURST_2D,
437}; 448};
438 449
439/* OMAP2 DSS Features */ 450/* OMAP2 DSS Features */
@@ -451,6 +462,7 @@ static const struct omap_dss_features omap2_dss_features = {
451 .overlay_caps = omap2_dss_overlay_caps, 462 .overlay_caps = omap2_dss_overlay_caps,
452 .clksrc_names = omap2_dss_clk_source_names, 463 .clksrc_names = omap2_dss_clk_source_names,
453 .dss_params = omap2_dss_param_range, 464 .dss_params = omap2_dss_param_range,
465 .supported_rotation_types = OMAP_DSS_ROT_DMA | OMAP_DSS_ROT_VRFB,
454 .buffer_size_unit = 1, 466 .buffer_size_unit = 1,
455 .burst_size_unit = 8, 467 .burst_size_unit = 8,
456}; 468};
@@ -470,6 +482,7 @@ static const struct omap_dss_features omap3430_dss_features = {
470 .overlay_caps = omap3430_dss_overlay_caps, 482 .overlay_caps = omap3430_dss_overlay_caps,
471 .clksrc_names = omap3_dss_clk_source_names, 483 .clksrc_names = omap3_dss_clk_source_names,
472 .dss_params = omap3_dss_param_range, 484 .dss_params = omap3_dss_param_range,
485 .supported_rotation_types = OMAP_DSS_ROT_DMA | OMAP_DSS_ROT_VRFB,
473 .buffer_size_unit = 1, 486 .buffer_size_unit = 1,
474 .burst_size_unit = 8, 487 .burst_size_unit = 8,
475}; 488};
@@ -488,6 +501,7 @@ static const struct omap_dss_features omap3630_dss_features = {
488 .overlay_caps = omap3630_dss_overlay_caps, 501 .overlay_caps = omap3630_dss_overlay_caps,
489 .clksrc_names = omap3_dss_clk_source_names, 502 .clksrc_names = omap3_dss_clk_source_names,
490 .dss_params = omap3_dss_param_range, 503 .dss_params = omap3_dss_param_range,
504 .supported_rotation_types = OMAP_DSS_ROT_DMA | OMAP_DSS_ROT_VRFB,
491 .buffer_size_unit = 1, 505 .buffer_size_unit = 1,
492 .burst_size_unit = 8, 506 .burst_size_unit = 8,
493}; 507};
@@ -508,6 +522,7 @@ static const struct omap_dss_features omap4430_es1_0_dss_features = {
508 .overlay_caps = omap4_dss_overlay_caps, 522 .overlay_caps = omap4_dss_overlay_caps,
509 .clksrc_names = omap4_dss_clk_source_names, 523 .clksrc_names = omap4_dss_clk_source_names,
510 .dss_params = omap4_dss_param_range, 524 .dss_params = omap4_dss_param_range,
525 .supported_rotation_types = OMAP_DSS_ROT_DMA | OMAP_DSS_ROT_TILER,
511 .buffer_size_unit = 16, 526 .buffer_size_unit = 16,
512 .burst_size_unit = 16, 527 .burst_size_unit = 16,
513}; 528};
@@ -527,6 +542,7 @@ static const struct omap_dss_features omap4430_es2_0_1_2_dss_features = {
527 .overlay_caps = omap4_dss_overlay_caps, 542 .overlay_caps = omap4_dss_overlay_caps,
528 .clksrc_names = omap4_dss_clk_source_names, 543 .clksrc_names = omap4_dss_clk_source_names,
529 .dss_params = omap4_dss_param_range, 544 .dss_params = omap4_dss_param_range,
545 .supported_rotation_types = OMAP_DSS_ROT_DMA | OMAP_DSS_ROT_TILER,
530 .buffer_size_unit = 16, 546 .buffer_size_unit = 16,
531 .burst_size_unit = 16, 547 .burst_size_unit = 16,
532}; 548};
@@ -546,6 +562,7 @@ static const struct omap_dss_features omap4_dss_features = {
546 .overlay_caps = omap4_dss_overlay_caps, 562 .overlay_caps = omap4_dss_overlay_caps,
547 .clksrc_names = omap4_dss_clk_source_names, 563 .clksrc_names = omap4_dss_clk_source_names,
548 .dss_params = omap4_dss_param_range, 564 .dss_params = omap4_dss_param_range,
565 .supported_rotation_types = OMAP_DSS_ROT_DMA | OMAP_DSS_ROT_TILER,
549 .buffer_size_unit = 16, 566 .buffer_size_unit = 16,
550 .burst_size_unit = 16, 567 .burst_size_unit = 16,
551}; 568};
@@ -562,13 +579,17 @@ static const struct ti_hdmi_ip_ops omap4_hdmi_functions = {
562 .pll_enable = ti_hdmi_4xxx_pll_enable, 579 .pll_enable = ti_hdmi_4xxx_pll_enable,
563 .pll_disable = ti_hdmi_4xxx_pll_disable, 580 .pll_disable = ti_hdmi_4xxx_pll_disable,
564 .video_enable = ti_hdmi_4xxx_wp_video_start, 581 .video_enable = ti_hdmi_4xxx_wp_video_start,
582 .video_disable = ti_hdmi_4xxx_wp_video_stop,
565 .dump_wrapper = ti_hdmi_4xxx_wp_dump, 583 .dump_wrapper = ti_hdmi_4xxx_wp_dump,
566 .dump_core = ti_hdmi_4xxx_core_dump, 584 .dump_core = ti_hdmi_4xxx_core_dump,
567 .dump_pll = ti_hdmi_4xxx_pll_dump, 585 .dump_pll = ti_hdmi_4xxx_pll_dump,
568 .dump_phy = ti_hdmi_4xxx_phy_dump, 586 .dump_phy = ti_hdmi_4xxx_phy_dump,
569#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ 587#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
570 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
571 .audio_enable = ti_hdmi_4xxx_wp_audio_enable, 588 .audio_enable = ti_hdmi_4xxx_wp_audio_enable,
589 .audio_disable = ti_hdmi_4xxx_wp_audio_disable,
590 .audio_start = ti_hdmi_4xxx_audio_start,
591 .audio_stop = ti_hdmi_4xxx_audio_stop,
592 .audio_config = ti_hdmi_4xxx_audio_config,
572#endif 593#endif
573 594
574}; 595};
@@ -662,6 +683,11 @@ void dss_feat_get_reg_field(enum dss_feat_reg_field id, u8 *start, u8 *end)
662 *end = omap_current_dss_features->reg_fields[id].end; 683 *end = omap_current_dss_features->reg_fields[id].end;
663} 684}
664 685
686bool dss_feat_rotation_type_supported(enum omap_dss_rotation_type rot_type)
687{
688 return omap_current_dss_features->supported_rotation_types & rot_type;
689}
690
665void dss_features_init(void) 691void dss_features_init(void)
666{ 692{
667 if (cpu_is_omap24xx()) 693 if (cpu_is_omap24xx())
diff --git a/drivers/video/omap2/dss/dss_features.h b/drivers/video/omap2/dss/dss_features.h
index c332e7ddfce1..bdf469f080e7 100644
--- a/drivers/video/omap2/dss/dss_features.h
+++ b/drivers/video/omap2/dss/dss_features.h
@@ -62,6 +62,7 @@ enum dss_feat_id {
62 FEAT_FIFO_MERGE, 62 FEAT_FIFO_MERGE,
63 /* An unknown HW bug causing the normal FIFO thresholds not to work */ 63 /* An unknown HW bug causing the normal FIFO thresholds not to work */
64 FEAT_OMAP3_DSI_FIFO_BUG, 64 FEAT_OMAP3_DSI_FIFO_BUG,
65 FEAT_BURST_2D,
65}; 66};
66 67
67/* DSS register field id */ 68/* DSS register field id */
@@ -91,6 +92,8 @@ enum dss_range_param {
91 FEAT_PARAM_DSIPLL_LPDIV, 92 FEAT_PARAM_DSIPLL_LPDIV,
92 FEAT_PARAM_DOWNSCALE, 93 FEAT_PARAM_DOWNSCALE,
93 FEAT_PARAM_LINEWIDTH, 94 FEAT_PARAM_LINEWIDTH,
95 FEAT_PARAM_MGR_WIDTH,
96 FEAT_PARAM_MGR_HEIGHT,
94}; 97};
95 98
96/* DSS Feature Functions */ 99/* DSS Feature Functions */
@@ -108,6 +111,8 @@ const char *dss_feat_get_clk_source_name(enum omap_dss_clk_source id);
108u32 dss_feat_get_buffer_size_unit(void); /* in bytes */ 111u32 dss_feat_get_buffer_size_unit(void); /* in bytes */
109u32 dss_feat_get_burst_size_unit(void); /* in bytes */ 112u32 dss_feat_get_burst_size_unit(void); /* in bytes */
110 113
114bool dss_feat_rotation_type_supported(enum omap_dss_rotation_type rot_type);
115
111bool dss_has_feature(enum dss_feat_id id); 116bool dss_has_feature(enum dss_feat_id id);
112void dss_feat_get_reg_field(enum dss_feat_reg_field id, u8 *start, u8 *end); 117void dss_feat_get_reg_field(enum dss_feat_reg_field id, u8 *start, u8 *end);
113void dss_features_init(void); 118void dss_features_init(void);
diff --git a/drivers/video/omap2/dss/hdmi.c b/drivers/video/omap2/dss/hdmi.c
index c4b4f6950a92..8195c7166d20 100644
--- a/drivers/video/omap2/dss/hdmi.c
+++ b/drivers/video/omap2/dss/hdmi.c
@@ -33,12 +33,6 @@
33#include <linux/pm_runtime.h> 33#include <linux/pm_runtime.h>
34#include <linux/clk.h> 34#include <linux/clk.h>
35#include <video/omapdss.h> 35#include <video/omapdss.h>
36#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
37 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
38#include <sound/soc.h>
39#include <sound/pcm_params.h>
40#include "ti_hdmi_4xxx_ip.h"
41#endif
42 36
43#include "ti_hdmi.h" 37#include "ti_hdmi.h"
44#include "dss.h" 38#include "dss.h"
@@ -63,7 +57,6 @@
63 57
64static struct { 58static struct {
65 struct mutex lock; 59 struct mutex lock;
66 struct omap_display_platform_data *pdata;
67 struct platform_device *pdev; 60 struct platform_device *pdev;
68 struct hdmi_ip_data ip_data; 61 struct hdmi_ip_data ip_data;
69 62
@@ -130,25 +123,12 @@ static int hdmi_runtime_get(void)
130 123
131 DSSDBG("hdmi_runtime_get\n"); 124 DSSDBG("hdmi_runtime_get\n");
132 125
133 /*
134 * HACK: Add dss_runtime_get() to ensure DSS clock domain is enabled.
135 * This should be removed later.
136 */
137 r = dss_runtime_get();
138 if (r < 0)
139 goto err_get_dss;
140
141 r = pm_runtime_get_sync(&hdmi.pdev->dev); 126 r = pm_runtime_get_sync(&hdmi.pdev->dev);
142 WARN_ON(r < 0); 127 WARN_ON(r < 0);
143 if (r < 0) 128 if (r < 0)
144 goto err_get_hdmi; 129 return r;
145 130
146 return 0; 131 return 0;
147
148err_get_hdmi:
149 dss_runtime_put();
150err_get_dss:
151 return r;
152} 132}
153 133
154static void hdmi_runtime_put(void) 134static void hdmi_runtime_put(void)
@@ -159,15 +139,9 @@ static void hdmi_runtime_put(void)
159 139
160 r = pm_runtime_put_sync(&hdmi.pdev->dev); 140 r = pm_runtime_put_sync(&hdmi.pdev->dev);
161 WARN_ON(r < 0); 141 WARN_ON(r < 0);
162
163 /*
164 * HACK: This is added to complement the dss_runtime_get() call in
165 * hdmi_runtime_get(). This should be removed later.
166 */
167 dss_runtime_put();
168} 142}
169 143
170int hdmi_init_display(struct omap_dss_device *dssdev) 144static int __init hdmi_init_display(struct omap_dss_device *dssdev)
171{ 145{
172 DSSDBG("init_display\n"); 146 DSSDBG("init_display\n");
173 147
@@ -344,7 +318,7 @@ static int hdmi_power_on(struct omap_dss_device *dssdev)
344 318
345 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data); 319 hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
346 320
347 hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0); 321 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
348 322
349 /* config the PLL and PHY hdmi_set_pll_pwrfirst */ 323 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
350 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data); 324 r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
@@ -376,10 +350,11 @@ static int hdmi_power_on(struct omap_dss_device *dssdev)
376 dispc_enable_gamma_table(0); 350 dispc_enable_gamma_table(0);
377 351
378 /* tv size */ 352 /* tv size */
379 dispc_set_digit_size(dssdev->panel.timings.x_res, 353 dss_mgr_set_timings(dssdev->manager, &dssdev->panel.timings);
380 dssdev->panel.timings.y_res);
381 354
382 hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 1); 355 r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
356 if (r)
357 goto err_vid_enable;
383 358
384 r = dss_mgr_enable(dssdev->manager); 359 r = dss_mgr_enable(dssdev->manager);
385 if (r) 360 if (r)
@@ -388,7 +363,8 @@ static int hdmi_power_on(struct omap_dss_device *dssdev)
388 return 0; 363 return 0;
389 364
390err_mgr_enable: 365err_mgr_enable:
391 hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0); 366 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
367err_vid_enable:
392 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data); 368 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
393 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data); 369 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
394err: 370err:
@@ -400,7 +376,7 @@ static void hdmi_power_off(struct omap_dss_device *dssdev)
400{ 376{
401 dss_mgr_disable(dssdev->manager); 377 dss_mgr_disable(dssdev->manager);
402 378
403 hdmi.ip_data.ops->video_enable(&hdmi.ip_data, 0); 379 hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
404 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data); 380 hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
405 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data); 381 hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
406 hdmi_runtime_put(); 382 hdmi_runtime_put();
@@ -436,10 +412,12 @@ void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
436 r = hdmi_power_on(dssdev); 412 r = hdmi_power_on(dssdev);
437 if (r) 413 if (r)
438 DSSERR("failed to power on device\n"); 414 DSSERR("failed to power on device\n");
415 } else {
416 dss_mgr_set_timings(dssdev->manager, &dssdev->panel.timings);
439 } 417 }
440} 418}
441 419
442void hdmi_dump_regs(struct seq_file *s) 420static void hdmi_dump_regs(struct seq_file *s)
443{ 421{
444 mutex_lock(&hdmi.lock); 422 mutex_lock(&hdmi.lock);
445 423
@@ -555,248 +533,201 @@ void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
555 mutex_unlock(&hdmi.lock); 533 mutex_unlock(&hdmi.lock);
556} 534}
557 535
558#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ 536static int hdmi_get_clocks(struct platform_device *pdev)
559 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
560
561static int hdmi_audio_trigger(struct snd_pcm_substream *substream, int cmd,
562 struct snd_soc_dai *dai)
563{ 537{
564 struct snd_soc_pcm_runtime *rtd = substream->private_data; 538 struct clk *clk;
565 struct snd_soc_codec *codec = rtd->codec;
566 struct platform_device *pdev = to_platform_device(codec->dev);
567 struct hdmi_ip_data *ip_data = snd_soc_codec_get_drvdata(codec);
568 int err = 0;
569 539
570 if (!(ip_data->ops) && !(ip_data->ops->audio_enable)) { 540 clk = clk_get(&pdev->dev, "sys_clk");
571 dev_err(&pdev->dev, "Cannot enable/disable audio\n"); 541 if (IS_ERR(clk)) {
572 return -ENODEV; 542 DSSERR("can't get sys_clk\n");
543 return PTR_ERR(clk);
573 } 544 }
574 545
575 switch (cmd) { 546 hdmi.sys_clk = clk;
576 case SNDRV_PCM_TRIGGER_START: 547
577 case SNDRV_PCM_TRIGGER_RESUME: 548 return 0;
578 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 549}
579 ip_data->ops->audio_enable(ip_data, true); 550
580 break; 551static void hdmi_put_clocks(void)
581 case SNDRV_PCM_TRIGGER_STOP: 552{
582 case SNDRV_PCM_TRIGGER_SUSPEND: 553 if (hdmi.sys_clk)
583 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 554 clk_put(hdmi.sys_clk);
584 ip_data->ops->audio_enable(ip_data, false); 555}
585 break; 556
586 default: 557#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
587 err = -EINVAL; 558int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
588 } 559{
589 return err; 560 u32 deep_color;
590} 561 bool deep_color_correct = false;
591 562 u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
592static int hdmi_audio_hw_params(struct snd_pcm_substream *substream, 563
593 struct snd_pcm_hw_params *params, 564 if (n == NULL || cts == NULL)
594 struct snd_soc_dai *dai)
595{
596 struct snd_soc_pcm_runtime *rtd = substream->private_data;
597 struct snd_soc_codec *codec = rtd->codec;
598 struct hdmi_ip_data *ip_data = snd_soc_codec_get_drvdata(codec);
599 struct hdmi_audio_format audio_format;
600 struct hdmi_audio_dma audio_dma;
601 struct hdmi_core_audio_config core_cfg;
602 struct hdmi_core_infoframe_audio aud_if_cfg;
603 int err, n, cts;
604 enum hdmi_core_audio_sample_freq sample_freq;
605
606 switch (params_format(params)) {
607 case SNDRV_PCM_FORMAT_S16_LE:
608 core_cfg.i2s_cfg.word_max_length =
609 HDMI_AUDIO_I2S_MAX_WORD_20BITS;
610 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS;
611 core_cfg.i2s_cfg.in_length_bits =
612 HDMI_AUDIO_I2S_INPUT_LENGTH_16;
613 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
614 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
615 audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
616 audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
617 audio_dma.transfer_size = 0x10;
618 break;
619 case SNDRV_PCM_FORMAT_S24_LE:
620 core_cfg.i2s_cfg.word_max_length =
621 HDMI_AUDIO_I2S_MAX_WORD_24BITS;
622 core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS;
623 core_cfg.i2s_cfg.in_length_bits =
624 HDMI_AUDIO_I2S_INPUT_LENGTH_24;
625 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
626 audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
627 audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
628 core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
629 audio_dma.transfer_size = 0x20;
630 break;
631 default:
632 return -EINVAL; 565 return -EINVAL;
633 }
634 566
635 switch (params_rate(params)) { 567 /* TODO: When implemented, query deep color mode here. */
568 deep_color = 100;
569
570 /*
571 * When using deep color, the default N value (as in the HDMI
572 * specification) yields to an non-integer CTS. Hence, we
573 * modify it while keeping the restrictions described in
574 * section 7.2.1 of the HDMI 1.4a specification.
575 */
576 switch (sample_freq) {
636 case 32000: 577 case 32000:
637 sample_freq = HDMI_AUDIO_FS_32000; 578 case 48000:
579 case 96000:
580 case 192000:
581 if (deep_color == 125)
582 if (pclk == 27027 || pclk == 74250)
583 deep_color_correct = true;
584 if (deep_color == 150)
585 if (pclk == 27027)
586 deep_color_correct = true;
638 break; 587 break;
639 case 44100: 588 case 44100:
640 sample_freq = HDMI_AUDIO_FS_44100; 589 case 88200:
641 break; 590 case 176400:
642 case 48000: 591 if (deep_color == 125)
643 sample_freq = HDMI_AUDIO_FS_48000; 592 if (pclk == 27027)
593 deep_color_correct = true;
644 break; 594 break;
645 default: 595 default:
646 return -EINVAL; 596 return -EINVAL;
647 } 597 }
648 598
649 err = hdmi_config_audio_acr(ip_data, params_rate(params), &n, &cts); 599 if (deep_color_correct) {
650 if (err < 0) 600 switch (sample_freq) {
651 return err; 601 case 32000:
652 602 *n = 8192;
653 /* Audio wrapper config */ 603 break;
654 audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL; 604 case 44100:
655 audio_format.active_chnnls_msk = 0x03; 605 *n = 12544;
656 audio_format.type = HDMI_AUDIO_TYPE_LPCM; 606 break;
657 audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST; 607 case 48000:
658 /* Disable start/stop signals of IEC 60958 blocks */ 608 *n = 8192;
659 audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF; 609 break;
610 case 88200:
611 *n = 25088;
612 break;
613 case 96000:
614 *n = 16384;
615 break;
616 case 176400:
617 *n = 50176;
618 break;
619 case 192000:
620 *n = 32768;
621 break;
622 default:
623 return -EINVAL;
624 }
625 } else {
626 switch (sample_freq) {
627 case 32000:
628 *n = 4096;
629 break;
630 case 44100:
631 *n = 6272;
632 break;
633 case 48000:
634 *n = 6144;
635 break;
636 case 88200:
637 *n = 12544;
638 break;
639 case 96000:
640 *n = 12288;
641 break;
642 case 176400:
643 *n = 25088;
644 break;
645 case 192000:
646 *n = 24576;
647 break;
648 default:
649 return -EINVAL;
650 }
651 }
652 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
653 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
660 654
661 audio_dma.block_size = 0xC0; 655 return 0;
662 audio_dma.mode = HDMI_AUDIO_TRANSF_DMA; 656}
663 audio_dma.fifo_threshold = 0x20; /* in number of samples */
664 657
665 hdmi_wp_audio_config_dma(ip_data, &audio_dma); 658int hdmi_audio_enable(void)
666 hdmi_wp_audio_config_format(ip_data, &audio_format); 659{
660 DSSDBG("audio_enable\n");
667 661
668 /* 662 return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
669 * I2S config 663}
670 */
671 core_cfg.i2s_cfg.en_high_bitrate_aud = false;
672 /* Only used with high bitrate audio */
673 core_cfg.i2s_cfg.cbit_order = false;
674 /* Serial data and word select should change on sck rising edge */
675 core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
676 core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
677 /* Set I2S word select polarity */
678 core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT;
679 core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
680 /* Set serial data to word select shift. See Phillips spec. */
681 core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
682 /* Enable one of the four available serial data channels */
683 core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
684
685 /* Core audio config */
686 core_cfg.freq_sample = sample_freq;
687 core_cfg.n = n;
688 core_cfg.cts = cts;
689 if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
690 core_cfg.aud_par_busclk = 0;
691 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
692 core_cfg.use_mclk = dss_has_feature(FEAT_HDMI_AUDIO_USE_MCLK);
693 } else {
694 core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8);
695 core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
696 core_cfg.use_mclk = true;
697 }
698 664
699 if (core_cfg.use_mclk) 665void hdmi_audio_disable(void)
700 core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS; 666{
701 core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH; 667 DSSDBG("audio_disable\n");
702 core_cfg.en_spdif = false;
703 /* Use sample frequency from channel status word */
704 core_cfg.fs_override = true;
705 /* Enable ACR packets */
706 core_cfg.en_acr_pkt = true;
707 /* Disable direct streaming digital audio */
708 core_cfg.en_dsd_audio = false;
709 /* Use parallel audio interface */
710 core_cfg.en_parallel_aud_input = true;
711
712 hdmi_core_audio_config(ip_data, &core_cfg);
713 668
714 /* 669 hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
715 * Configure packet
716 * info frame audio see doc CEA861-D page 74
717 */
718 aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM;
719 aud_if_cfg.db1_channel_count = 2;
720 aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM;
721 aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM;
722 aud_if_cfg.db4_channel_alloc = 0x00;
723 aud_if_cfg.db5_downmix_inh = false;
724 aud_if_cfg.db5_lsv = 0;
725
726 hdmi_core_audio_infoframe_config(ip_data, &aud_if_cfg);
727 return 0;
728} 670}
729 671
730static int hdmi_audio_startup(struct snd_pcm_substream *substream, 672int hdmi_audio_start(void)
731 struct snd_soc_dai *dai)
732{ 673{
733 if (!hdmi.ip_data.cfg.cm.mode) { 674 DSSDBG("audio_start\n");
734 pr_err("Current video settings do not support audio.\n"); 675
735 return -EIO; 676 return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
736 }
737 return 0;
738} 677}
739 678
740static int hdmi_audio_codec_probe(struct snd_soc_codec *codec) 679void hdmi_audio_stop(void)
741{ 680{
742 struct hdmi_ip_data *priv = &hdmi.ip_data; 681 DSSDBG("audio_stop\n");
743 682
744 snd_soc_codec_set_drvdata(codec, priv); 683 hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
745 return 0;
746} 684}
747 685
748static struct snd_soc_codec_driver hdmi_audio_codec_drv = { 686bool hdmi_mode_has_audio(void)
749 .probe = hdmi_audio_codec_probe, 687{
750}; 688 if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
689 return true;
690 else
691 return false;
692}
751 693
752static struct snd_soc_dai_ops hdmi_audio_codec_ops = { 694int hdmi_audio_config(struct omap_dss_audio *audio)
753 .hw_params = hdmi_audio_hw_params, 695{
754 .trigger = hdmi_audio_trigger, 696 return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
755 .startup = hdmi_audio_startup, 697}
756};
757 698
758static struct snd_soc_dai_driver hdmi_codec_dai_drv = {
759 .name = "hdmi-audio-codec",
760 .playback = {
761 .channels_min = 2,
762 .channels_max = 2,
763 .rates = SNDRV_PCM_RATE_32000 |
764 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
765 .formats = SNDRV_PCM_FMTBIT_S16_LE |
766 SNDRV_PCM_FMTBIT_S24_LE,
767 },
768 .ops = &hdmi_audio_codec_ops,
769};
770#endif 699#endif
771 700
772static int hdmi_get_clocks(struct platform_device *pdev) 701static void __init hdmi_probe_pdata(struct platform_device *pdev)
773{ 702{
774 struct clk *clk; 703 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
704 int r, i;
775 705
776 clk = clk_get(&pdev->dev, "sys_clk"); 706 for (i = 0; i < pdata->num_devices; ++i) {
777 if (IS_ERR(clk)) { 707 struct omap_dss_device *dssdev = pdata->devices[i];
778 DSSERR("can't get sys_clk\n");
779 return PTR_ERR(clk);
780 }
781 708
782 hdmi.sys_clk = clk; 709 if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
710 continue;
783 711
784 return 0; 712 r = hdmi_init_display(dssdev);
785} 713 if (r) {
714 DSSERR("device %s init failed: %d\n", dssdev->name, r);
715 continue;
716 }
786 717
787static void hdmi_put_clocks(void) 718 r = omap_dss_register_device(dssdev, &pdev->dev, i);
788{ 719 if (r)
789 if (hdmi.sys_clk) 720 DSSERR("device %s register failed: %d\n",
790 clk_put(hdmi.sys_clk); 721 dssdev->name, r);
722 }
791} 723}
792 724
793/* HDMI HW IP initialisation */ 725/* HDMI HW IP initialisation */
794static int omapdss_hdmihw_probe(struct platform_device *pdev) 726static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
795{ 727{
796 struct resource *hdmi_mem; 728 struct resource *hdmi_mem;
797 int r; 729 int r;
798 730
799 hdmi.pdata = pdev->dev.platform_data;
800 hdmi.pdev = pdev; 731 hdmi.pdev = pdev;
801 732
802 mutex_init(&hdmi.lock); 733 mutex_init(&hdmi.lock);
@@ -830,28 +761,18 @@ static int omapdss_hdmihw_probe(struct platform_device *pdev)
830 761
831 hdmi_panel_init(); 762 hdmi_panel_init();
832 763
833#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ 764 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
834 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE) 765
766 hdmi_probe_pdata(pdev);
835 767
836 /* Register ASoC codec DAI */
837 r = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv,
838 &hdmi_codec_dai_drv, 1);
839 if (r) {
840 DSSERR("can't register ASoC HDMI audio codec\n");
841 return r;
842 }
843#endif
844 return 0; 768 return 0;
845} 769}
846 770
847static int omapdss_hdmihw_remove(struct platform_device *pdev) 771static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
848{ 772{
849 hdmi_panel_exit(); 773 omap_dss_unregister_child_devices(&pdev->dev);
850 774
851#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ 775 hdmi_panel_exit();
852 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
853 snd_soc_unregister_codec(&pdev->dev);
854#endif
855 776
856 pm_runtime_disable(&pdev->dev); 777 pm_runtime_disable(&pdev->dev);
857 778
@@ -867,7 +788,6 @@ static int hdmi_runtime_suspend(struct device *dev)
867 clk_disable(hdmi.sys_clk); 788 clk_disable(hdmi.sys_clk);
868 789
869 dispc_runtime_put(); 790 dispc_runtime_put();
870 dss_runtime_put();
871 791
872 return 0; 792 return 0;
873} 793}
@@ -876,23 +796,13 @@ static int hdmi_runtime_resume(struct device *dev)
876{ 796{
877 int r; 797 int r;
878 798
879 r = dss_runtime_get();
880 if (r < 0)
881 goto err_get_dss;
882
883 r = dispc_runtime_get(); 799 r = dispc_runtime_get();
884 if (r < 0) 800 if (r < 0)
885 goto err_get_dispc; 801 return r;
886
887 802
888 clk_enable(hdmi.sys_clk); 803 clk_enable(hdmi.sys_clk);
889 804
890 return 0; 805 return 0;
891
892err_get_dispc:
893 dss_runtime_put();
894err_get_dss:
895 return r;
896} 806}
897 807
898static const struct dev_pm_ops hdmi_pm_ops = { 808static const struct dev_pm_ops hdmi_pm_ops = {
@@ -901,8 +811,7 @@ static const struct dev_pm_ops hdmi_pm_ops = {
901}; 811};
902 812
903static struct platform_driver omapdss_hdmihw_driver = { 813static struct platform_driver omapdss_hdmihw_driver = {
904 .probe = omapdss_hdmihw_probe, 814 .remove = __exit_p(omapdss_hdmihw_remove),
905 .remove = omapdss_hdmihw_remove,
906 .driver = { 815 .driver = {
907 .name = "omapdss_hdmi", 816 .name = "omapdss_hdmi",
908 .owner = THIS_MODULE, 817 .owner = THIS_MODULE,
@@ -910,12 +819,12 @@ static struct platform_driver omapdss_hdmihw_driver = {
910 }, 819 },
911}; 820};
912 821
913int hdmi_init_platform_driver(void) 822int __init hdmi_init_platform_driver(void)
914{ 823{
915 return platform_driver_register(&omapdss_hdmihw_driver); 824 return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
916} 825}
917 826
918void hdmi_uninit_platform_driver(void) 827void __exit hdmi_uninit_platform_driver(void)
919{ 828{
920 return platform_driver_unregister(&omapdss_hdmihw_driver); 829 platform_driver_unregister(&omapdss_hdmihw_driver);
921} 830}
diff --git a/drivers/video/omap2/dss/hdmi_panel.c b/drivers/video/omap2/dss/hdmi_panel.c
index 533d5dc634d2..1179e3c4b1c7 100644
--- a/drivers/video/omap2/dss/hdmi_panel.c
+++ b/drivers/video/omap2/dss/hdmi_panel.c
@@ -30,7 +30,12 @@
30#include "dss.h" 30#include "dss.h"
31 31
32static struct { 32static struct {
33 struct mutex hdmi_lock; 33 /* This protects the panel ops, mainly when accessing the HDMI IP. */
34 struct mutex lock;
35#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
36 /* This protects the audio ops, specifically. */
37 spinlock_t audio_lock;
38#endif
34} hdmi; 39} hdmi;
35 40
36 41
@@ -54,12 +59,168 @@ static void hdmi_panel_remove(struct omap_dss_device *dssdev)
54 59
55} 60}
56 61
62#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
63static int hdmi_panel_audio_enable(struct omap_dss_device *dssdev)
64{
65 unsigned long flags;
66 int r;
67
68 mutex_lock(&hdmi.lock);
69 spin_lock_irqsave(&hdmi.audio_lock, flags);
70
71 /* enable audio only if the display is active and supports audio */
72 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE ||
73 !hdmi_mode_has_audio()) {
74 DSSERR("audio not supported or display is off\n");
75 r = -EPERM;
76 goto err;
77 }
78
79 r = hdmi_audio_enable();
80
81 if (!r)
82 dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
83
84err:
85 spin_unlock_irqrestore(&hdmi.audio_lock, flags);
86 mutex_unlock(&hdmi.lock);
87 return r;
88}
89
90static void hdmi_panel_audio_disable(struct omap_dss_device *dssdev)
91{
92 unsigned long flags;
93
94 spin_lock_irqsave(&hdmi.audio_lock, flags);
95
96 hdmi_audio_disable();
97
98 dssdev->audio_state = OMAP_DSS_AUDIO_DISABLED;
99
100 spin_unlock_irqrestore(&hdmi.audio_lock, flags);
101}
102
103static int hdmi_panel_audio_start(struct omap_dss_device *dssdev)
104{
105 unsigned long flags;
106 int r;
107
108 spin_lock_irqsave(&hdmi.audio_lock, flags);
109 /*
110 * No need to check the panel state. It was checked when trasitioning
111 * to AUDIO_ENABLED.
112 */
113 if (dssdev->audio_state != OMAP_DSS_AUDIO_ENABLED) {
114 DSSERR("audio start from invalid state\n");
115 r = -EPERM;
116 goto err;
117 }
118
119 r = hdmi_audio_start();
120
121 if (!r)
122 dssdev->audio_state = OMAP_DSS_AUDIO_PLAYING;
123
124err:
125 spin_unlock_irqrestore(&hdmi.audio_lock, flags);
126 return r;
127}
128
129static void hdmi_panel_audio_stop(struct omap_dss_device *dssdev)
130{
131 unsigned long flags;
132
133 spin_lock_irqsave(&hdmi.audio_lock, flags);
134
135 hdmi_audio_stop();
136 dssdev->audio_state = OMAP_DSS_AUDIO_ENABLED;
137
138 spin_unlock_irqrestore(&hdmi.audio_lock, flags);
139}
140
141static bool hdmi_panel_audio_supported(struct omap_dss_device *dssdev)
142{
143 bool r = false;
144
145 mutex_lock(&hdmi.lock);
146
147 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
148 goto err;
149
150 if (!hdmi_mode_has_audio())
151 goto err;
152
153 r = true;
154err:
155 mutex_unlock(&hdmi.lock);
156 return r;
157}
158
159static int hdmi_panel_audio_config(struct omap_dss_device *dssdev,
160 struct omap_dss_audio *audio)
161{
162 unsigned long flags;
163 int r;
164
165 mutex_lock(&hdmi.lock);
166 spin_lock_irqsave(&hdmi.audio_lock, flags);
167
168 /* config audio only if the display is active and supports audio */
169 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE ||
170 !hdmi_mode_has_audio()) {
171 DSSERR("audio not supported or display is off\n");
172 r = -EPERM;
173 goto err;
174 }
175
176 r = hdmi_audio_config(audio);
177
178 if (!r)
179 dssdev->audio_state = OMAP_DSS_AUDIO_CONFIGURED;
180
181err:
182 spin_unlock_irqrestore(&hdmi.audio_lock, flags);
183 mutex_unlock(&hdmi.lock);
184 return r;
185}
186
187#else
188static int hdmi_panel_audio_enable(struct omap_dss_device *dssdev)
189{
190 return -EPERM;
191}
192
193static void hdmi_panel_audio_disable(struct omap_dss_device *dssdev)
194{
195}
196
197static int hdmi_panel_audio_start(struct omap_dss_device *dssdev)
198{
199 return -EPERM;
200}
201
202static void hdmi_panel_audio_stop(struct omap_dss_device *dssdev)
203{
204}
205
206static bool hdmi_panel_audio_supported(struct omap_dss_device *dssdev)
207{
208 return false;
209}
210
211static int hdmi_panel_audio_config(struct omap_dss_device *dssdev,
212 struct omap_dss_audio *audio)
213{
214 return -EPERM;
215}
216#endif
217
57static int hdmi_panel_enable(struct omap_dss_device *dssdev) 218static int hdmi_panel_enable(struct omap_dss_device *dssdev)
58{ 219{
59 int r = 0; 220 int r = 0;
60 DSSDBG("ENTER hdmi_panel_enable\n"); 221 DSSDBG("ENTER hdmi_panel_enable\n");
61 222
62 mutex_lock(&hdmi.hdmi_lock); 223 mutex_lock(&hdmi.lock);
63 224
64 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) { 225 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
65 r = -EINVAL; 226 r = -EINVAL;
@@ -75,40 +236,52 @@ static int hdmi_panel_enable(struct omap_dss_device *dssdev)
75 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; 236 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
76 237
77err: 238err:
78 mutex_unlock(&hdmi.hdmi_lock); 239 mutex_unlock(&hdmi.lock);
79 240
80 return r; 241 return r;
81} 242}
82 243
83static void hdmi_panel_disable(struct omap_dss_device *dssdev) 244static void hdmi_panel_disable(struct omap_dss_device *dssdev)
84{ 245{
85 mutex_lock(&hdmi.hdmi_lock); 246 mutex_lock(&hdmi.lock);
86 247
87 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) 248 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
249 /*
250 * TODO: notify audio users that the display was disabled. For
251 * now, disable audio locally to not break our audio state
252 * machine.
253 */
254 hdmi_panel_audio_disable(dssdev);
88 omapdss_hdmi_display_disable(dssdev); 255 omapdss_hdmi_display_disable(dssdev);
256 }
89 257
90 dssdev->state = OMAP_DSS_DISPLAY_DISABLED; 258 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
91 259
92 mutex_unlock(&hdmi.hdmi_lock); 260 mutex_unlock(&hdmi.lock);
93} 261}
94 262
95static int hdmi_panel_suspend(struct omap_dss_device *dssdev) 263static int hdmi_panel_suspend(struct omap_dss_device *dssdev)
96{ 264{
97 int r = 0; 265 int r = 0;
98 266
99 mutex_lock(&hdmi.hdmi_lock); 267 mutex_lock(&hdmi.lock);
100 268
101 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) { 269 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
102 r = -EINVAL; 270 r = -EINVAL;
103 goto err; 271 goto err;
104 } 272 }
105 273
106 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED; 274 /*
275 * TODO: notify audio users that the display was suspended. For now,
276 * disable audio locally to not break our audio state machine.
277 */
278 hdmi_panel_audio_disable(dssdev);
107 279
280 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
108 omapdss_hdmi_display_disable(dssdev); 281 omapdss_hdmi_display_disable(dssdev);
109 282
110err: 283err:
111 mutex_unlock(&hdmi.hdmi_lock); 284 mutex_unlock(&hdmi.lock);
112 285
113 return r; 286 return r;
114} 287}
@@ -117,7 +290,7 @@ static int hdmi_panel_resume(struct omap_dss_device *dssdev)
117{ 290{
118 int r = 0; 291 int r = 0;
119 292
120 mutex_lock(&hdmi.hdmi_lock); 293 mutex_lock(&hdmi.lock);
121 294
122 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) { 295 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
123 r = -EINVAL; 296 r = -EINVAL;
@@ -129,11 +302,12 @@ static int hdmi_panel_resume(struct omap_dss_device *dssdev)
129 DSSERR("failed to power on\n"); 302 DSSERR("failed to power on\n");
130 goto err; 303 goto err;
131 } 304 }
305 /* TODO: notify audio users that the panel resumed. */
132 306
133 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE; 307 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
134 308
135err: 309err:
136 mutex_unlock(&hdmi.hdmi_lock); 310 mutex_unlock(&hdmi.lock);
137 311
138 return r; 312 return r;
139} 313}
@@ -141,11 +315,11 @@ err:
141static void hdmi_get_timings(struct omap_dss_device *dssdev, 315static void hdmi_get_timings(struct omap_dss_device *dssdev,
142 struct omap_video_timings *timings) 316 struct omap_video_timings *timings)
143{ 317{
144 mutex_lock(&hdmi.hdmi_lock); 318 mutex_lock(&hdmi.lock);
145 319
146 *timings = dssdev->panel.timings; 320 *timings = dssdev->panel.timings;
147 321
148 mutex_unlock(&hdmi.hdmi_lock); 322 mutex_unlock(&hdmi.lock);
149} 323}
150 324
151static void hdmi_set_timings(struct omap_dss_device *dssdev, 325static void hdmi_set_timings(struct omap_dss_device *dssdev,
@@ -153,12 +327,18 @@ static void hdmi_set_timings(struct omap_dss_device *dssdev,
153{ 327{
154 DSSDBG("hdmi_set_timings\n"); 328 DSSDBG("hdmi_set_timings\n");
155 329
156 mutex_lock(&hdmi.hdmi_lock); 330 mutex_lock(&hdmi.lock);
331
332 /*
333 * TODO: notify audio users that there was a timings change. For
334 * now, disable audio locally to not break our audio state machine.
335 */
336 hdmi_panel_audio_disable(dssdev);
157 337
158 dssdev->panel.timings = *timings; 338 dssdev->panel.timings = *timings;
159 omapdss_hdmi_display_set_timing(dssdev); 339 omapdss_hdmi_display_set_timing(dssdev);
160 340
161 mutex_unlock(&hdmi.hdmi_lock); 341 mutex_unlock(&hdmi.lock);
162} 342}
163 343
164static int hdmi_check_timings(struct omap_dss_device *dssdev, 344static int hdmi_check_timings(struct omap_dss_device *dssdev,
@@ -168,11 +348,11 @@ static int hdmi_check_timings(struct omap_dss_device *dssdev,
168 348
169 DSSDBG("hdmi_check_timings\n"); 349 DSSDBG("hdmi_check_timings\n");
170 350
171 mutex_lock(&hdmi.hdmi_lock); 351 mutex_lock(&hdmi.lock);
172 352
173 r = omapdss_hdmi_display_check_timing(dssdev, timings); 353 r = omapdss_hdmi_display_check_timing(dssdev, timings);
174 354
175 mutex_unlock(&hdmi.hdmi_lock); 355 mutex_unlock(&hdmi.lock);
176 return r; 356 return r;
177} 357}
178 358
@@ -180,7 +360,7 @@ static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
180{ 360{
181 int r; 361 int r;
182 362
183 mutex_lock(&hdmi.hdmi_lock); 363 mutex_lock(&hdmi.lock);
184 364
185 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) { 365 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
186 r = omapdss_hdmi_display_enable(dssdev); 366 r = omapdss_hdmi_display_enable(dssdev);
@@ -194,7 +374,7 @@ static int hdmi_read_edid(struct omap_dss_device *dssdev, u8 *buf, int len)
194 dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED) 374 dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
195 omapdss_hdmi_display_disable(dssdev); 375 omapdss_hdmi_display_disable(dssdev);
196err: 376err:
197 mutex_unlock(&hdmi.hdmi_lock); 377 mutex_unlock(&hdmi.lock);
198 378
199 return r; 379 return r;
200} 380}
@@ -203,7 +383,7 @@ static bool hdmi_detect(struct omap_dss_device *dssdev)
203{ 383{
204 int r; 384 int r;
205 385
206 mutex_lock(&hdmi.hdmi_lock); 386 mutex_lock(&hdmi.lock);
207 387
208 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) { 388 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
209 r = omapdss_hdmi_display_enable(dssdev); 389 r = omapdss_hdmi_display_enable(dssdev);
@@ -217,7 +397,7 @@ static bool hdmi_detect(struct omap_dss_device *dssdev)
217 dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED) 397 dssdev->state == OMAP_DSS_DISPLAY_SUSPENDED)
218 omapdss_hdmi_display_disable(dssdev); 398 omapdss_hdmi_display_disable(dssdev);
219err: 399err:
220 mutex_unlock(&hdmi.hdmi_lock); 400 mutex_unlock(&hdmi.lock);
221 401
222 return r; 402 return r;
223} 403}
@@ -234,6 +414,12 @@ static struct omap_dss_driver hdmi_driver = {
234 .check_timings = hdmi_check_timings, 414 .check_timings = hdmi_check_timings,
235 .read_edid = hdmi_read_edid, 415 .read_edid = hdmi_read_edid,
236 .detect = hdmi_detect, 416 .detect = hdmi_detect,
417 .audio_enable = hdmi_panel_audio_enable,
418 .audio_disable = hdmi_panel_audio_disable,
419 .audio_start = hdmi_panel_audio_start,
420 .audio_stop = hdmi_panel_audio_stop,
421 .audio_supported = hdmi_panel_audio_supported,
422 .audio_config = hdmi_panel_audio_config,
237 .driver = { 423 .driver = {
238 .name = "hdmi_panel", 424 .name = "hdmi_panel",
239 .owner = THIS_MODULE, 425 .owner = THIS_MODULE,
@@ -242,7 +428,11 @@ static struct omap_dss_driver hdmi_driver = {
242 428
243int hdmi_panel_init(void) 429int hdmi_panel_init(void)
244{ 430{
245 mutex_init(&hdmi.hdmi_lock); 431 mutex_init(&hdmi.lock);
432
433#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
434 spin_lock_init(&hdmi.audio_lock);
435#endif
246 436
247 omap_dss_register_driver(&hdmi_driver); 437 omap_dss_register_driver(&hdmi_driver);
248 438
diff --git a/drivers/video/omap2/dss/manager.c b/drivers/video/omap2/dss/manager.c
index e7364603f6a1..0cbcde4c688a 100644
--- a/drivers/video/omap2/dss/manager.c
+++ b/drivers/video/omap2/dss/manager.c
@@ -654,9 +654,20 @@ static int dss_mgr_check_zorder(struct omap_overlay_manager *mgr,
654 return 0; 654 return 0;
655} 655}
656 656
657int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
658 const struct omap_video_timings *timings)
659{
660 if (!dispc_mgr_timings_ok(mgr->id, timings)) {
661 DSSERR("check_manager: invalid timings\n");
662 return -EINVAL;
663 }
664
665 return 0;
666}
667
657int dss_mgr_check(struct omap_overlay_manager *mgr, 668int dss_mgr_check(struct omap_overlay_manager *mgr,
658 struct omap_dss_device *dssdev,
659 struct omap_overlay_manager_info *info, 669 struct omap_overlay_manager_info *info,
670 const struct omap_video_timings *mgr_timings,
660 struct omap_overlay_info **overlay_infos) 671 struct omap_overlay_info **overlay_infos)
661{ 672{
662 struct omap_overlay *ovl; 673 struct omap_overlay *ovl;
@@ -668,6 +679,10 @@ int dss_mgr_check(struct omap_overlay_manager *mgr,
668 return r; 679 return r;
669 } 680 }
670 681
682 r = dss_mgr_check_timings(mgr, mgr_timings);
683 if (r)
684 return r;
685
671 list_for_each_entry(ovl, &mgr->overlays, list) { 686 list_for_each_entry(ovl, &mgr->overlays, list) {
672 struct omap_overlay_info *oi; 687 struct omap_overlay_info *oi;
673 int r; 688 int r;
@@ -677,7 +692,7 @@ int dss_mgr_check(struct omap_overlay_manager *mgr,
677 if (oi == NULL) 692 if (oi == NULL)
678 continue; 693 continue;
679 694
680 r = dss_ovl_check(ovl, oi, dssdev); 695 r = dss_ovl_check(ovl, oi, mgr_timings);
681 if (r) 696 if (r)
682 return r; 697 return r;
683 } 698 }
diff --git a/drivers/video/omap2/dss/overlay.c b/drivers/video/omap2/dss/overlay.c
index 6e821810deec..b0ba60f88dd2 100644
--- a/drivers/video/omap2/dss/overlay.c
+++ b/drivers/video/omap2/dss/overlay.c
@@ -628,19 +628,23 @@ int dss_ovl_simple_check(struct omap_overlay *ovl,
628 return -EINVAL; 628 return -EINVAL;
629 } 629 }
630 630
631 if (dss_feat_rotation_type_supported(info->rotation_type) == 0) {
632 DSSERR("check_overlay: rotation type %d not supported\n",
633 info->rotation_type);
634 return -EINVAL;
635 }
636
631 return 0; 637 return 0;
632} 638}
633 639
634int dss_ovl_check(struct omap_overlay *ovl, 640int dss_ovl_check(struct omap_overlay *ovl, struct omap_overlay_info *info,
635 struct omap_overlay_info *info, struct omap_dss_device *dssdev) 641 const struct omap_video_timings *mgr_timings)
636{ 642{
637 u16 outw, outh; 643 u16 outw, outh;
638 u16 dw, dh; 644 u16 dw, dh;
639 645
640 if (dssdev == NULL) 646 dw = mgr_timings->x_res;
641 return 0; 647 dh = mgr_timings->y_res;
642
643 dssdev->driver->get_resolution(dssdev, &dw, &dh);
644 648
645 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) { 649 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
646 outw = info->width; 650 outw = info->width;
diff --git a/drivers/video/omap2/dss/rfbi.c b/drivers/video/omap2/dss/rfbi.c
index 788a0ef6323a..3d8c206e90e5 100644
--- a/drivers/video/omap2/dss/rfbi.c
+++ b/drivers/video/omap2/dss/rfbi.c
@@ -304,13 +304,23 @@ static void rfbi_transfer_area(struct omap_dss_device *dssdev, u16 width,
304 u16 height, void (*callback)(void *data), void *data) 304 u16 height, void (*callback)(void *data), void *data)
305{ 305{
306 u32 l; 306 u32 l;
307 struct omap_video_timings timings = {
308 .hsw = 1,
309 .hfp = 1,
310 .hbp = 1,
311 .vsw = 1,
312 .vfp = 0,
313 .vbp = 0,
314 .x_res = width,
315 .y_res = height,
316 };
307 317
308 /*BUG_ON(callback == 0);*/ 318 /*BUG_ON(callback == 0);*/
309 BUG_ON(rfbi.framedone_callback != NULL); 319 BUG_ON(rfbi.framedone_callback != NULL);
310 320
311 DSSDBG("rfbi_transfer_area %dx%d\n", width, height); 321 DSSDBG("rfbi_transfer_area %dx%d\n", width, height);
312 322
313 dispc_mgr_set_lcd_size(dssdev->manager->id, width, height); 323 dss_mgr_set_timings(dssdev->manager, &timings);
314 324
315 dispc_mgr_enable(dssdev->manager->id, true); 325 dispc_mgr_enable(dssdev->manager->id, true);
316 326
@@ -766,6 +776,16 @@ int omap_rfbi_prepare_update(struct omap_dss_device *dssdev,
766 u16 *x, u16 *y, u16 *w, u16 *h) 776 u16 *x, u16 *y, u16 *w, u16 *h)
767{ 777{
768 u16 dw, dh; 778 u16 dw, dh;
779 struct omap_video_timings timings = {
780 .hsw = 1,
781 .hfp = 1,
782 .hbp = 1,
783 .vsw = 1,
784 .vfp = 0,
785 .vbp = 0,
786 .x_res = *w,
787 .y_res = *h,
788 };
769 789
770 dssdev->driver->get_resolution(dssdev, &dw, &dh); 790 dssdev->driver->get_resolution(dssdev, &dw, &dh);
771 791
@@ -784,7 +804,7 @@ int omap_rfbi_prepare_update(struct omap_dss_device *dssdev,
784 if (*w == 0 || *h == 0) 804 if (*w == 0 || *h == 0)
785 return -EINVAL; 805 return -EINVAL;
786 806
787 dispc_mgr_set_lcd_size(dssdev->manager->id, *w, *h); 807 dss_mgr_set_timings(dssdev->manager, &timings);
788 808
789 return 0; 809 return 0;
790} 810}
@@ -799,7 +819,7 @@ int omap_rfbi_update(struct omap_dss_device *dssdev,
799} 819}
800EXPORT_SYMBOL(omap_rfbi_update); 820EXPORT_SYMBOL(omap_rfbi_update);
801 821
802void rfbi_dump_regs(struct seq_file *s) 822static void rfbi_dump_regs(struct seq_file *s)
803{ 823{
804#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, rfbi_read_reg(r)) 824#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, rfbi_read_reg(r))
805 825
@@ -900,15 +920,39 @@ void omapdss_rfbi_display_disable(struct omap_dss_device *dssdev)
900} 920}
901EXPORT_SYMBOL(omapdss_rfbi_display_disable); 921EXPORT_SYMBOL(omapdss_rfbi_display_disable);
902 922
903int rfbi_init_display(struct omap_dss_device *dssdev) 923static int __init rfbi_init_display(struct omap_dss_device *dssdev)
904{ 924{
905 rfbi.dssdev[dssdev->phy.rfbi.channel] = dssdev; 925 rfbi.dssdev[dssdev->phy.rfbi.channel] = dssdev;
906 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE; 926 dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
907 return 0; 927 return 0;
908} 928}
909 929
930static void __init rfbi_probe_pdata(struct platform_device *pdev)
931{
932 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
933 int i, r;
934
935 for (i = 0; i < pdata->num_devices; ++i) {
936 struct omap_dss_device *dssdev = pdata->devices[i];
937
938 if (dssdev->type != OMAP_DISPLAY_TYPE_DBI)
939 continue;
940
941 r = rfbi_init_display(dssdev);
942 if (r) {
943 DSSERR("device %s init failed: %d\n", dssdev->name, r);
944 continue;
945 }
946
947 r = omap_dss_register_device(dssdev, &pdev->dev, i);
948 if (r)
949 DSSERR("device %s register failed: %d\n",
950 dssdev->name, r);
951 }
952}
953
910/* RFBI HW IP initialisation */ 954/* RFBI HW IP initialisation */
911static int omap_rfbihw_probe(struct platform_device *pdev) 955static int __init omap_rfbihw_probe(struct platform_device *pdev)
912{ 956{
913 u32 rev; 957 u32 rev;
914 struct resource *rfbi_mem; 958 struct resource *rfbi_mem;
@@ -956,6 +1000,10 @@ static int omap_rfbihw_probe(struct platform_device *pdev)
956 1000
957 rfbi_runtime_put(); 1001 rfbi_runtime_put();
958 1002
1003 dss_debugfs_create_file("rfbi", rfbi_dump_regs);
1004
1005 rfbi_probe_pdata(pdev);
1006
959 return 0; 1007 return 0;
960 1008
961err_runtime_get: 1009err_runtime_get:
@@ -963,8 +1011,9 @@ err_runtime_get:
963 return r; 1011 return r;
964} 1012}
965 1013
966static int omap_rfbihw_remove(struct platform_device *pdev) 1014static int __exit omap_rfbihw_remove(struct platform_device *pdev)
967{ 1015{
1016 omap_dss_unregister_child_devices(&pdev->dev);
968 pm_runtime_disable(&pdev->dev); 1017 pm_runtime_disable(&pdev->dev);
969 return 0; 1018 return 0;
970} 1019}
@@ -972,7 +1021,6 @@ static int omap_rfbihw_remove(struct platform_device *pdev)
972static int rfbi_runtime_suspend(struct device *dev) 1021static int rfbi_runtime_suspend(struct device *dev)
973{ 1022{
974 dispc_runtime_put(); 1023 dispc_runtime_put();
975 dss_runtime_put();
976 1024
977 return 0; 1025 return 0;
978} 1026}
@@ -981,20 +1029,11 @@ static int rfbi_runtime_resume(struct device *dev)
981{ 1029{
982 int r; 1030 int r;
983 1031
984 r = dss_runtime_get();
985 if (r < 0)
986 goto err_get_dss;
987
988 r = dispc_runtime_get(); 1032 r = dispc_runtime_get();
989 if (r < 0) 1033 if (r < 0)
990 goto err_get_dispc; 1034 return r;
991 1035
992 return 0; 1036 return 0;
993
994err_get_dispc:
995 dss_runtime_put();
996err_get_dss:
997 return r;
998} 1037}
999 1038
1000static const struct dev_pm_ops rfbi_pm_ops = { 1039static const struct dev_pm_ops rfbi_pm_ops = {
@@ -1003,8 +1042,7 @@ static const struct dev_pm_ops rfbi_pm_ops = {
1003}; 1042};
1004 1043
1005static struct platform_driver omap_rfbihw_driver = { 1044static struct platform_driver omap_rfbihw_driver = {
1006 .probe = omap_rfbihw_probe, 1045 .remove = __exit_p(omap_rfbihw_remove),
1007 .remove = omap_rfbihw_remove,
1008 .driver = { 1046 .driver = {
1009 .name = "omapdss_rfbi", 1047 .name = "omapdss_rfbi",
1010 .owner = THIS_MODULE, 1048 .owner = THIS_MODULE,
@@ -1012,12 +1050,12 @@ static struct platform_driver omap_rfbihw_driver = {
1012 }, 1050 },
1013}; 1051};
1014 1052
1015int rfbi_init_platform_driver(void) 1053int __init rfbi_init_platform_driver(void)
1016{ 1054{
1017 return platform_driver_register(&omap_rfbihw_driver); 1055 return platform_driver_probe(&omap_rfbihw_driver, omap_rfbihw_probe);
1018} 1056}
1019 1057
1020void rfbi_uninit_platform_driver(void) 1058void __exit rfbi_uninit_platform_driver(void)
1021{ 1059{
1022 return platform_driver_unregister(&omap_rfbihw_driver); 1060 platform_driver_unregister(&omap_rfbihw_driver);
1023} 1061}
diff --git a/drivers/video/omap2/dss/sdi.c b/drivers/video/omap2/dss/sdi.c
index 8266ca0d666b..3a43dc2a9b46 100644
--- a/drivers/video/omap2/dss/sdi.c
+++ b/drivers/video/omap2/dss/sdi.c
@@ -24,6 +24,7 @@
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/regulator/consumer.h> 25#include <linux/regulator/consumer.h>
26#include <linux/export.h> 26#include <linux/export.h>
27#include <linux/platform_device.h>
27 28
28#include <video/omapdss.h> 29#include <video/omapdss.h>
29#include "dss.h" 30#include "dss.h"
@@ -71,10 +72,6 @@ int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
71 if (r) 72 if (r)
72 goto err_reg_enable; 73 goto err_reg_enable;
73 74
74 r = dss_runtime_get();
75 if (r)
76 goto err_get_dss;
77
78 r = dispc_runtime_get(); 75 r = dispc_runtime_get();
79 if (r) 76 if (r)
80 goto err_get_dispc; 77 goto err_get_dispc;
@@ -107,7 +104,7 @@ int omapdss_sdi_display_enable(struct omap_dss_device *dssdev)
107 } 104 }
108 105
109 106
110 dispc_mgr_set_lcd_timings(dssdev->manager->id, t); 107 dss_mgr_set_timings(dssdev->manager, t);
111 108
112 r = dss_set_clock_div(&dss_cinfo); 109 r = dss_set_clock_div(&dss_cinfo);
113 if (r) 110 if (r)
@@ -137,8 +134,6 @@ err_set_dss_clock_div:
137err_calc_clock_div: 134err_calc_clock_div:
138 dispc_runtime_put(); 135 dispc_runtime_put();
139err_get_dispc: 136err_get_dispc:
140 dss_runtime_put();
141err_get_dss:
142 regulator_disable(sdi.vdds_sdi_reg); 137 regulator_disable(sdi.vdds_sdi_reg);
143err_reg_enable: 138err_reg_enable:
144 omap_dss_stop_device(dssdev); 139 omap_dss_stop_device(dssdev);
@@ -154,7 +149,6 @@ void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
154 dss_sdi_disable(); 149 dss_sdi_disable();
155 150
156 dispc_runtime_put(); 151 dispc_runtime_put();
157 dss_runtime_put();
158 152
159 regulator_disable(sdi.vdds_sdi_reg); 153 regulator_disable(sdi.vdds_sdi_reg);
160 154
@@ -162,7 +156,7 @@ void omapdss_sdi_display_disable(struct omap_dss_device *dssdev)
162} 156}
163EXPORT_SYMBOL(omapdss_sdi_display_disable); 157EXPORT_SYMBOL(omapdss_sdi_display_disable);
164 158
165int sdi_init_display(struct omap_dss_device *dssdev) 159static int __init sdi_init_display(struct omap_dss_device *dssdev)
166{ 160{
167 DSSDBG("SDI init\n"); 161 DSSDBG("SDI init\n");
168 162
@@ -182,11 +176,58 @@ int sdi_init_display(struct omap_dss_device *dssdev)
182 return 0; 176 return 0;
183} 177}
184 178
185int sdi_init(void) 179static void __init sdi_probe_pdata(struct platform_device *pdev)
180{
181 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
182 int i, r;
183
184 for (i = 0; i < pdata->num_devices; ++i) {
185 struct omap_dss_device *dssdev = pdata->devices[i];
186
187 if (dssdev->type != OMAP_DISPLAY_TYPE_SDI)
188 continue;
189
190 r = sdi_init_display(dssdev);
191 if (r) {
192 DSSERR("device %s init failed: %d\n", dssdev->name, r);
193 continue;
194 }
195
196 r = omap_dss_register_device(dssdev, &pdev->dev, i);
197 if (r)
198 DSSERR("device %s register failed: %d\n",
199 dssdev->name, r);
200 }
201}
202
203static int __init omap_sdi_probe(struct platform_device *pdev)
186{ 204{
205 sdi_probe_pdata(pdev);
206
207 return 0;
208}
209
210static int __exit omap_sdi_remove(struct platform_device *pdev)
211{
212 omap_dss_unregister_child_devices(&pdev->dev);
213
187 return 0; 214 return 0;
188} 215}
189 216
190void sdi_exit(void) 217static struct platform_driver omap_sdi_driver = {
218 .remove = __exit_p(omap_sdi_remove),
219 .driver = {
220 .name = "omapdss_sdi",
221 .owner = THIS_MODULE,
222 },
223};
224
225int __init sdi_init_platform_driver(void)
226{
227 return platform_driver_probe(&omap_sdi_driver, omap_sdi_probe);
228}
229
230void __exit sdi_uninit_platform_driver(void)
191{ 231{
232 platform_driver_unregister(&omap_sdi_driver);
192} 233}
diff --git a/drivers/video/omap2/dss/ti_hdmi.h b/drivers/video/omap2/dss/ti_hdmi.h
index 1f58b84d6901..e734cb444bc7 100644
--- a/drivers/video/omap2/dss/ti_hdmi.h
+++ b/drivers/video/omap2/dss/ti_hdmi.h
@@ -96,7 +96,9 @@ struct ti_hdmi_ip_ops {
96 96
97 void (*pll_disable)(struct hdmi_ip_data *ip_data); 97 void (*pll_disable)(struct hdmi_ip_data *ip_data);
98 98
99 void (*video_enable)(struct hdmi_ip_data *ip_data, bool start); 99 int (*video_enable)(struct hdmi_ip_data *ip_data);
100
101 void (*video_disable)(struct hdmi_ip_data *ip_data);
100 102
101 void (*dump_wrapper)(struct hdmi_ip_data *ip_data, struct seq_file *s); 103 void (*dump_wrapper)(struct hdmi_ip_data *ip_data, struct seq_file *s);
102 104
@@ -106,9 +108,17 @@ struct ti_hdmi_ip_ops {
106 108
107 void (*dump_phy)(struct hdmi_ip_data *ip_data, struct seq_file *s); 109 void (*dump_phy)(struct hdmi_ip_data *ip_data, struct seq_file *s);
108 110
109#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ 111#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
110 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE) 112 int (*audio_enable)(struct hdmi_ip_data *ip_data);
111 void (*audio_enable)(struct hdmi_ip_data *ip_data, bool start); 113
114 void (*audio_disable)(struct hdmi_ip_data *ip_data);
115
116 int (*audio_start)(struct hdmi_ip_data *ip_data);
117
118 void (*audio_stop)(struct hdmi_ip_data *ip_data);
119
120 int (*audio_config)(struct hdmi_ip_data *ip_data,
121 struct omap_dss_audio *audio);
112#endif 122#endif
113 123
114}; 124};
@@ -173,7 +183,8 @@ int ti_hdmi_4xxx_phy_enable(struct hdmi_ip_data *ip_data);
173void ti_hdmi_4xxx_phy_disable(struct hdmi_ip_data *ip_data); 183void ti_hdmi_4xxx_phy_disable(struct hdmi_ip_data *ip_data);
174int ti_hdmi_4xxx_read_edid(struct hdmi_ip_data *ip_data, u8 *edid, int len); 184int ti_hdmi_4xxx_read_edid(struct hdmi_ip_data *ip_data, u8 *edid, int len);
175bool ti_hdmi_4xxx_detect(struct hdmi_ip_data *ip_data); 185bool ti_hdmi_4xxx_detect(struct hdmi_ip_data *ip_data);
176void ti_hdmi_4xxx_wp_video_start(struct hdmi_ip_data *ip_data, bool start); 186int ti_hdmi_4xxx_wp_video_start(struct hdmi_ip_data *ip_data);
187void ti_hdmi_4xxx_wp_video_stop(struct hdmi_ip_data *ip_data);
177int ti_hdmi_4xxx_pll_enable(struct hdmi_ip_data *ip_data); 188int ti_hdmi_4xxx_pll_enable(struct hdmi_ip_data *ip_data);
178void ti_hdmi_4xxx_pll_disable(struct hdmi_ip_data *ip_data); 189void ti_hdmi_4xxx_pll_disable(struct hdmi_ip_data *ip_data);
179void ti_hdmi_4xxx_basic_configure(struct hdmi_ip_data *ip_data); 190void ti_hdmi_4xxx_basic_configure(struct hdmi_ip_data *ip_data);
@@ -181,8 +192,13 @@ void ti_hdmi_4xxx_wp_dump(struct hdmi_ip_data *ip_data, struct seq_file *s);
181void ti_hdmi_4xxx_pll_dump(struct hdmi_ip_data *ip_data, struct seq_file *s); 192void ti_hdmi_4xxx_pll_dump(struct hdmi_ip_data *ip_data, struct seq_file *s);
182void ti_hdmi_4xxx_core_dump(struct hdmi_ip_data *ip_data, struct seq_file *s); 193void ti_hdmi_4xxx_core_dump(struct hdmi_ip_data *ip_data, struct seq_file *s);
183void ti_hdmi_4xxx_phy_dump(struct hdmi_ip_data *ip_data, struct seq_file *s); 194void ti_hdmi_4xxx_phy_dump(struct hdmi_ip_data *ip_data, struct seq_file *s);
184#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ 195#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
185 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE) 196int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts);
186void ti_hdmi_4xxx_wp_audio_enable(struct hdmi_ip_data *ip_data, bool enable); 197int ti_hdmi_4xxx_wp_audio_enable(struct hdmi_ip_data *ip_data);
198void ti_hdmi_4xxx_wp_audio_disable(struct hdmi_ip_data *ip_data);
199int ti_hdmi_4xxx_audio_start(struct hdmi_ip_data *ip_data);
200void ti_hdmi_4xxx_audio_stop(struct hdmi_ip_data *ip_data);
201int ti_hdmi_4xxx_audio_config(struct hdmi_ip_data *ip_data,
202 struct omap_dss_audio *audio);
187#endif 203#endif
188#endif 204#endif
diff --git a/drivers/video/omap2/dss/ti_hdmi_4xxx_ip.c b/drivers/video/omap2/dss/ti_hdmi_4xxx_ip.c
index bfe6fe65c8be..4dae1b291079 100644
--- a/drivers/video/omap2/dss/ti_hdmi_4xxx_ip.c
+++ b/drivers/video/omap2/dss/ti_hdmi_4xxx_ip.c
@@ -29,9 +29,14 @@
29#include <linux/string.h> 29#include <linux/string.h>
30#include <linux/seq_file.h> 30#include <linux/seq_file.h>
31#include <linux/gpio.h> 31#include <linux/gpio.h>
32#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
33#include <sound/asound.h>
34#include <sound/asoundef.h>
35#endif
32 36
33#include "ti_hdmi_4xxx_ip.h" 37#include "ti_hdmi_4xxx_ip.h"
34#include "dss.h" 38#include "dss.h"
39#include "dss_features.h"
35 40
36static inline void hdmi_write_reg(void __iomem *base_addr, 41static inline void hdmi_write_reg(void __iomem *base_addr,
37 const u16 idx, u32 val) 42 const u16 idx, u32 val)
@@ -298,9 +303,9 @@ int ti_hdmi_4xxx_phy_enable(struct hdmi_ip_data *ip_data)
298 REG_FLD_MOD(phy_base, HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27); 303 REG_FLD_MOD(phy_base, HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
299 304
300 r = request_threaded_irq(gpio_to_irq(ip_data->hpd_gpio), 305 r = request_threaded_irq(gpio_to_irq(ip_data->hpd_gpio),
301 NULL, hpd_irq_handler, 306 NULL, hpd_irq_handler,
302 IRQF_DISABLED | IRQF_TRIGGER_RISING | 307 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
303 IRQF_TRIGGER_FALLING, "hpd", ip_data); 308 IRQF_ONESHOT, "hpd", ip_data);
304 if (r) { 309 if (r) {
305 DSSERR("HPD IRQ request failed\n"); 310 DSSERR("HPD IRQ request failed\n");
306 hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_OFF); 311 hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_OFF);
@@ -699,9 +704,15 @@ static void hdmi_wp_init(struct omap_video_timings *timings,
699 704
700} 705}
701 706
702void ti_hdmi_4xxx_wp_video_start(struct hdmi_ip_data *ip_data, bool start) 707int ti_hdmi_4xxx_wp_video_start(struct hdmi_ip_data *ip_data)
708{
709 REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, true, 31, 31);
710 return 0;
711}
712
713void ti_hdmi_4xxx_wp_video_stop(struct hdmi_ip_data *ip_data)
703{ 714{
704 REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, start, 31, 31); 715 REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, false, 31, 31);
705} 716}
706 717
707static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt, 718static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt,
@@ -886,10 +897,12 @@ void ti_hdmi_4xxx_core_dump(struct hdmi_ip_data *ip_data, struct seq_file *s)
886 897
887#define CORE_REG(i, name) name(i) 898#define CORE_REG(i, name) name(i)
888#define DUMPCORE(r) seq_printf(s, "%-35s %08x\n", #r,\ 899#define DUMPCORE(r) seq_printf(s, "%-35s %08x\n", #r,\
889 hdmi_read_reg(hdmi_pll_base(ip_data), r)) 900 hdmi_read_reg(hdmi_core_sys_base(ip_data), r))
890#define DUMPCOREAV(i, r) seq_printf(s, "%s[%d]%*s %08x\n", #r, i, \ 901#define DUMPCOREAV(r) seq_printf(s, "%-35s %08x\n", #r,\
902 hdmi_read_reg(hdmi_av_base(ip_data), r))
903#define DUMPCOREAV2(i, r) seq_printf(s, "%s[%d]%*s %08x\n", #r, i, \
891 (i < 10) ? 32 - strlen(#r) : 31 - strlen(#r), " ", \ 904 (i < 10) ? 32 - strlen(#r) : 31 - strlen(#r), " ", \
892 hdmi_read_reg(hdmi_pll_base(ip_data), CORE_REG(i, r))) 905 hdmi_read_reg(hdmi_av_base(ip_data), CORE_REG(i, r)))
893 906
894 DUMPCORE(HDMI_CORE_SYS_VND_IDL); 907 DUMPCORE(HDMI_CORE_SYS_VND_IDL);
895 DUMPCORE(HDMI_CORE_SYS_DEV_IDL); 908 DUMPCORE(HDMI_CORE_SYS_DEV_IDL);
@@ -898,6 +911,13 @@ void ti_hdmi_4xxx_core_dump(struct hdmi_ip_data *ip_data, struct seq_file *s)
898 DUMPCORE(HDMI_CORE_SYS_SRST); 911 DUMPCORE(HDMI_CORE_SYS_SRST);
899 DUMPCORE(HDMI_CORE_CTRL1); 912 DUMPCORE(HDMI_CORE_CTRL1);
900 DUMPCORE(HDMI_CORE_SYS_SYS_STAT); 913 DUMPCORE(HDMI_CORE_SYS_SYS_STAT);
914 DUMPCORE(HDMI_CORE_SYS_DE_DLY);
915 DUMPCORE(HDMI_CORE_SYS_DE_CTRL);
916 DUMPCORE(HDMI_CORE_SYS_DE_TOP);
917 DUMPCORE(HDMI_CORE_SYS_DE_CNTL);
918 DUMPCORE(HDMI_CORE_SYS_DE_CNTH);
919 DUMPCORE(HDMI_CORE_SYS_DE_LINL);
920 DUMPCORE(HDMI_CORE_SYS_DE_LINH_1);
901 DUMPCORE(HDMI_CORE_SYS_VID_ACEN); 921 DUMPCORE(HDMI_CORE_SYS_VID_ACEN);
902 DUMPCORE(HDMI_CORE_SYS_VID_MODE); 922 DUMPCORE(HDMI_CORE_SYS_VID_MODE);
903 DUMPCORE(HDMI_CORE_SYS_INTR_STATE); 923 DUMPCORE(HDMI_CORE_SYS_INTR_STATE);
@@ -907,102 +927,91 @@ void ti_hdmi_4xxx_core_dump(struct hdmi_ip_data *ip_data, struct seq_file *s)
907 DUMPCORE(HDMI_CORE_SYS_INTR4); 927 DUMPCORE(HDMI_CORE_SYS_INTR4);
908 DUMPCORE(HDMI_CORE_SYS_UMASK1); 928 DUMPCORE(HDMI_CORE_SYS_UMASK1);
909 DUMPCORE(HDMI_CORE_SYS_TMDS_CTRL); 929 DUMPCORE(HDMI_CORE_SYS_TMDS_CTRL);
910 DUMPCORE(HDMI_CORE_SYS_DE_DLY);
911 DUMPCORE(HDMI_CORE_SYS_DE_CTRL);
912 DUMPCORE(HDMI_CORE_SYS_DE_TOP);
913 DUMPCORE(HDMI_CORE_SYS_DE_CNTL);
914 DUMPCORE(HDMI_CORE_SYS_DE_CNTH);
915 DUMPCORE(HDMI_CORE_SYS_DE_LINL);
916 DUMPCORE(HDMI_CORE_SYS_DE_LINH_1);
917 930
918 DUMPCORE(HDMI_CORE_DDC_CMD);
919 DUMPCORE(HDMI_CORE_DDC_STATUS);
920 DUMPCORE(HDMI_CORE_DDC_ADDR); 931 DUMPCORE(HDMI_CORE_DDC_ADDR);
932 DUMPCORE(HDMI_CORE_DDC_SEGM);
921 DUMPCORE(HDMI_CORE_DDC_OFFSET); 933 DUMPCORE(HDMI_CORE_DDC_OFFSET);
922 DUMPCORE(HDMI_CORE_DDC_COUNT1); 934 DUMPCORE(HDMI_CORE_DDC_COUNT1);
923 DUMPCORE(HDMI_CORE_DDC_COUNT2); 935 DUMPCORE(HDMI_CORE_DDC_COUNT2);
936 DUMPCORE(HDMI_CORE_DDC_STATUS);
937 DUMPCORE(HDMI_CORE_DDC_CMD);
924 DUMPCORE(HDMI_CORE_DDC_DATA); 938 DUMPCORE(HDMI_CORE_DDC_DATA);
925 DUMPCORE(HDMI_CORE_DDC_SEGM);
926 939
927 DUMPCORE(HDMI_CORE_AV_HDMI_CTRL); 940 DUMPCOREAV(HDMI_CORE_AV_ACR_CTRL);
928 DUMPCORE(HDMI_CORE_AV_DPD); 941 DUMPCOREAV(HDMI_CORE_AV_FREQ_SVAL);
929 DUMPCORE(HDMI_CORE_AV_PB_CTRL1); 942 DUMPCOREAV(HDMI_CORE_AV_N_SVAL1);
930 DUMPCORE(HDMI_CORE_AV_PB_CTRL2); 943 DUMPCOREAV(HDMI_CORE_AV_N_SVAL2);
931 DUMPCORE(HDMI_CORE_AV_AVI_TYPE); 944 DUMPCOREAV(HDMI_CORE_AV_N_SVAL3);
932 DUMPCORE(HDMI_CORE_AV_AVI_VERS); 945 DUMPCOREAV(HDMI_CORE_AV_CTS_SVAL1);
933 DUMPCORE(HDMI_CORE_AV_AVI_LEN); 946 DUMPCOREAV(HDMI_CORE_AV_CTS_SVAL2);
934 DUMPCORE(HDMI_CORE_AV_AVI_CHSUM); 947 DUMPCOREAV(HDMI_CORE_AV_CTS_SVAL3);
948 DUMPCOREAV(HDMI_CORE_AV_CTS_HVAL1);
949 DUMPCOREAV(HDMI_CORE_AV_CTS_HVAL2);
950 DUMPCOREAV(HDMI_CORE_AV_CTS_HVAL3);
951 DUMPCOREAV(HDMI_CORE_AV_AUD_MODE);
952 DUMPCOREAV(HDMI_CORE_AV_SPDIF_CTRL);
953 DUMPCOREAV(HDMI_CORE_AV_HW_SPDIF_FS);
954 DUMPCOREAV(HDMI_CORE_AV_SWAP_I2S);
955 DUMPCOREAV(HDMI_CORE_AV_SPDIF_ERTH);
956 DUMPCOREAV(HDMI_CORE_AV_I2S_IN_MAP);
957 DUMPCOREAV(HDMI_CORE_AV_I2S_IN_CTRL);
958 DUMPCOREAV(HDMI_CORE_AV_I2S_CHST0);
959 DUMPCOREAV(HDMI_CORE_AV_I2S_CHST1);
960 DUMPCOREAV(HDMI_CORE_AV_I2S_CHST2);
961 DUMPCOREAV(HDMI_CORE_AV_I2S_CHST4);
962 DUMPCOREAV(HDMI_CORE_AV_I2S_CHST5);
963 DUMPCOREAV(HDMI_CORE_AV_ASRC);
964 DUMPCOREAV(HDMI_CORE_AV_I2S_IN_LEN);
965 DUMPCOREAV(HDMI_CORE_AV_HDMI_CTRL);
966 DUMPCOREAV(HDMI_CORE_AV_AUDO_TXSTAT);
967 DUMPCOREAV(HDMI_CORE_AV_AUD_PAR_BUSCLK_1);
968 DUMPCOREAV(HDMI_CORE_AV_AUD_PAR_BUSCLK_2);
969 DUMPCOREAV(HDMI_CORE_AV_AUD_PAR_BUSCLK_3);
970 DUMPCOREAV(HDMI_CORE_AV_TEST_TXCTRL);
971 DUMPCOREAV(HDMI_CORE_AV_DPD);
972 DUMPCOREAV(HDMI_CORE_AV_PB_CTRL1);
973 DUMPCOREAV(HDMI_CORE_AV_PB_CTRL2);
974 DUMPCOREAV(HDMI_CORE_AV_AVI_TYPE);
975 DUMPCOREAV(HDMI_CORE_AV_AVI_VERS);
976 DUMPCOREAV(HDMI_CORE_AV_AVI_LEN);
977 DUMPCOREAV(HDMI_CORE_AV_AVI_CHSUM);
935 978
936 for (i = 0; i < HDMI_CORE_AV_AVI_DBYTE_NELEMS; i++) 979 for (i = 0; i < HDMI_CORE_AV_AVI_DBYTE_NELEMS; i++)
937 DUMPCOREAV(i, HDMI_CORE_AV_AVI_DBYTE); 980 DUMPCOREAV2(i, HDMI_CORE_AV_AVI_DBYTE);
981
982 DUMPCOREAV(HDMI_CORE_AV_SPD_TYPE);
983 DUMPCOREAV(HDMI_CORE_AV_SPD_VERS);
984 DUMPCOREAV(HDMI_CORE_AV_SPD_LEN);
985 DUMPCOREAV(HDMI_CORE_AV_SPD_CHSUM);
938 986
939 for (i = 0; i < HDMI_CORE_AV_SPD_DBYTE_NELEMS; i++) 987 for (i = 0; i < HDMI_CORE_AV_SPD_DBYTE_NELEMS; i++)
940 DUMPCOREAV(i, HDMI_CORE_AV_SPD_DBYTE); 988 DUMPCOREAV2(i, HDMI_CORE_AV_SPD_DBYTE);
989
990 DUMPCOREAV(HDMI_CORE_AV_AUDIO_TYPE);
991 DUMPCOREAV(HDMI_CORE_AV_AUDIO_VERS);
992 DUMPCOREAV(HDMI_CORE_AV_AUDIO_LEN);
993 DUMPCOREAV(HDMI_CORE_AV_AUDIO_CHSUM);
941 994
942 for (i = 0; i < HDMI_CORE_AV_AUD_DBYTE_NELEMS; i++) 995 for (i = 0; i < HDMI_CORE_AV_AUD_DBYTE_NELEMS; i++)
943 DUMPCOREAV(i, HDMI_CORE_AV_AUD_DBYTE); 996 DUMPCOREAV2(i, HDMI_CORE_AV_AUD_DBYTE);
997
998 DUMPCOREAV(HDMI_CORE_AV_MPEG_TYPE);
999 DUMPCOREAV(HDMI_CORE_AV_MPEG_VERS);
1000 DUMPCOREAV(HDMI_CORE_AV_MPEG_LEN);
1001 DUMPCOREAV(HDMI_CORE_AV_MPEG_CHSUM);
944 1002
945 for (i = 0; i < HDMI_CORE_AV_MPEG_DBYTE_NELEMS; i++) 1003 for (i = 0; i < HDMI_CORE_AV_MPEG_DBYTE_NELEMS; i++)
946 DUMPCOREAV(i, HDMI_CORE_AV_MPEG_DBYTE); 1004 DUMPCOREAV2(i, HDMI_CORE_AV_MPEG_DBYTE);
947 1005
948 for (i = 0; i < HDMI_CORE_AV_GEN_DBYTE_NELEMS; i++) 1006 for (i = 0; i < HDMI_CORE_AV_GEN_DBYTE_NELEMS; i++)
949 DUMPCOREAV(i, HDMI_CORE_AV_GEN_DBYTE); 1007 DUMPCOREAV2(i, HDMI_CORE_AV_GEN_DBYTE);
1008
1009 DUMPCOREAV(HDMI_CORE_AV_CP_BYTE1);
950 1010
951 for (i = 0; i < HDMI_CORE_AV_GEN2_DBYTE_NELEMS; i++) 1011 for (i = 0; i < HDMI_CORE_AV_GEN2_DBYTE_NELEMS; i++)
952 DUMPCOREAV(i, HDMI_CORE_AV_GEN2_DBYTE); 1012 DUMPCOREAV2(i, HDMI_CORE_AV_GEN2_DBYTE);
953 1013
954 DUMPCORE(HDMI_CORE_AV_ACR_CTRL); 1014 DUMPCOREAV(HDMI_CORE_AV_CEC_ADDR_ID);
955 DUMPCORE(HDMI_CORE_AV_FREQ_SVAL);
956 DUMPCORE(HDMI_CORE_AV_N_SVAL1);
957 DUMPCORE(HDMI_CORE_AV_N_SVAL2);
958 DUMPCORE(HDMI_CORE_AV_N_SVAL3);
959 DUMPCORE(HDMI_CORE_AV_CTS_SVAL1);
960 DUMPCORE(HDMI_CORE_AV_CTS_SVAL2);
961 DUMPCORE(HDMI_CORE_AV_CTS_SVAL3);
962 DUMPCORE(HDMI_CORE_AV_CTS_HVAL1);
963 DUMPCORE(HDMI_CORE_AV_CTS_HVAL2);
964 DUMPCORE(HDMI_CORE_AV_CTS_HVAL3);
965 DUMPCORE(HDMI_CORE_AV_AUD_MODE);
966 DUMPCORE(HDMI_CORE_AV_SPDIF_CTRL);
967 DUMPCORE(HDMI_CORE_AV_HW_SPDIF_FS);
968 DUMPCORE(HDMI_CORE_AV_SWAP_I2S);
969 DUMPCORE(HDMI_CORE_AV_SPDIF_ERTH);
970 DUMPCORE(HDMI_CORE_AV_I2S_IN_MAP);
971 DUMPCORE(HDMI_CORE_AV_I2S_IN_CTRL);
972 DUMPCORE(HDMI_CORE_AV_I2S_CHST0);
973 DUMPCORE(HDMI_CORE_AV_I2S_CHST1);
974 DUMPCORE(HDMI_CORE_AV_I2S_CHST2);
975 DUMPCORE(HDMI_CORE_AV_I2S_CHST4);
976 DUMPCORE(HDMI_CORE_AV_I2S_CHST5);
977 DUMPCORE(HDMI_CORE_AV_ASRC);
978 DUMPCORE(HDMI_CORE_AV_I2S_IN_LEN);
979 DUMPCORE(HDMI_CORE_AV_HDMI_CTRL);
980 DUMPCORE(HDMI_CORE_AV_AUDO_TXSTAT);
981 DUMPCORE(HDMI_CORE_AV_AUD_PAR_BUSCLK_1);
982 DUMPCORE(HDMI_CORE_AV_AUD_PAR_BUSCLK_2);
983 DUMPCORE(HDMI_CORE_AV_AUD_PAR_BUSCLK_3);
984 DUMPCORE(HDMI_CORE_AV_TEST_TXCTRL);
985 DUMPCORE(HDMI_CORE_AV_DPD);
986 DUMPCORE(HDMI_CORE_AV_PB_CTRL1);
987 DUMPCORE(HDMI_CORE_AV_PB_CTRL2);
988 DUMPCORE(HDMI_CORE_AV_AVI_TYPE);
989 DUMPCORE(HDMI_CORE_AV_AVI_VERS);
990 DUMPCORE(HDMI_CORE_AV_AVI_LEN);
991 DUMPCORE(HDMI_CORE_AV_AVI_CHSUM);
992 DUMPCORE(HDMI_CORE_AV_SPD_TYPE);
993 DUMPCORE(HDMI_CORE_AV_SPD_VERS);
994 DUMPCORE(HDMI_CORE_AV_SPD_LEN);
995 DUMPCORE(HDMI_CORE_AV_SPD_CHSUM);
996 DUMPCORE(HDMI_CORE_AV_AUDIO_TYPE);
997 DUMPCORE(HDMI_CORE_AV_AUDIO_VERS);
998 DUMPCORE(HDMI_CORE_AV_AUDIO_LEN);
999 DUMPCORE(HDMI_CORE_AV_AUDIO_CHSUM);
1000 DUMPCORE(HDMI_CORE_AV_MPEG_TYPE);
1001 DUMPCORE(HDMI_CORE_AV_MPEG_VERS);
1002 DUMPCORE(HDMI_CORE_AV_MPEG_LEN);
1003 DUMPCORE(HDMI_CORE_AV_MPEG_CHSUM);
1004 DUMPCORE(HDMI_CORE_AV_CP_BYTE1);
1005 DUMPCORE(HDMI_CORE_AV_CEC_ADDR_ID);
1006} 1015}
1007 1016
1008void ti_hdmi_4xxx_phy_dump(struct hdmi_ip_data *ip_data, struct seq_file *s) 1017void ti_hdmi_4xxx_phy_dump(struct hdmi_ip_data *ip_data, struct seq_file *s)
@@ -1016,9 +1025,8 @@ void ti_hdmi_4xxx_phy_dump(struct hdmi_ip_data *ip_data, struct seq_file *s)
1016 DUMPPHY(HDMI_TXPHY_PAD_CFG_CTRL); 1025 DUMPPHY(HDMI_TXPHY_PAD_CFG_CTRL);
1017} 1026}
1018 1027
1019#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \ 1028#if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
1020 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE) 1029static void ti_hdmi_4xxx_wp_audio_config_format(struct hdmi_ip_data *ip_data,
1021void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
1022 struct hdmi_audio_format *aud_fmt) 1030 struct hdmi_audio_format *aud_fmt)
1023{ 1031{
1024 u32 r; 1032 u32 r;
@@ -1037,7 +1045,7 @@ void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
1037 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG, r); 1045 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG, r);
1038} 1046}
1039 1047
1040void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data, 1048static void ti_hdmi_4xxx_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
1041 struct hdmi_audio_dma *aud_dma) 1049 struct hdmi_audio_dma *aud_dma)
1042{ 1050{
1043 u32 r; 1051 u32 r;
@@ -1055,7 +1063,7 @@ void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
1055 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL, r); 1063 hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL, r);
1056} 1064}
1057 1065
1058void hdmi_core_audio_config(struct hdmi_ip_data *ip_data, 1066static void ti_hdmi_4xxx_core_audio_config(struct hdmi_ip_data *ip_data,
1059 struct hdmi_core_audio_config *cfg) 1067 struct hdmi_core_audio_config *cfg)
1060{ 1068{
1061 u32 r; 1069 u32 r;
@@ -1106,27 +1114,33 @@ void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
1106 REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL, 1114 REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL,
1107 cfg->fs_override, 1, 1); 1115 cfg->fs_override, 1, 1);
1108 1116
1109 /* I2S parameters */ 1117 /*
1110 REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_CHST4, 1118 * Set IEC-60958-3 channel status word. It is passed to the IP
1111 cfg->freq_sample, 3, 0); 1119 * just as it is received. The user of the driver is responsible
1112 1120 * for its contents.
1121 */
1122 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST0,
1123 cfg->iec60958_cfg->status[0]);
1124 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST1,
1125 cfg->iec60958_cfg->status[1]);
1126 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST2,
1127 cfg->iec60958_cfg->status[2]);
1128 /* yes, this is correct: status[3] goes to CHST4 register */
1129 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST4,
1130 cfg->iec60958_cfg->status[3]);
1131 /* yes, this is correct: status[4] goes to CHST5 register */
1132 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5,
1133 cfg->iec60958_cfg->status[4]);
1134
1135 /* set I2S parameters */
1113 r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL); 1136 r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL);
1114 r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
1115 r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6); 1137 r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
1116 r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
1117 r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4); 1138 r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
1118 r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
1119 r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2); 1139 r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
1120 r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1); 1140 r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
1121 r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0); 1141 r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
1122 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r); 1142 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r);
1123 1143
1124 r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_CHST5);
1125 r = FLD_MOD(r, cfg->freq_sample, 7, 4);
1126 r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
1127 r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
1128 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5, r);
1129
1130 REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN, 1144 REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN,
1131 cfg->i2s_cfg.in_length_bits, 3, 0); 1145 cfg->i2s_cfg.in_length_bits, 3, 0);
1132 1146
@@ -1138,12 +1152,19 @@ void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
1138 r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2); 1152 r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
1139 r = FLD_MOD(r, cfg->en_spdif, 1, 1); 1153 r = FLD_MOD(r, cfg->en_spdif, 1, 1);
1140 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r); 1154 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r);
1155
1156 /* Audio channel mappings */
1157 /* TODO: Make channel mapping dynamic. For now, map channels
1158 * in the ALSA order: FL/FR/RL/RR/C/LFE/SL/SR. Remapping is needed as
1159 * HDMI speaker order is different. See CEA-861 Section 6.6.2.
1160 */
1161 hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_MAP, 0x78);
1162 REG_FLD_MOD(av_base, HDMI_CORE_AV_SWAP_I2S, 1, 5, 5);
1141} 1163}
1142 1164
1143void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data, 1165static void ti_hdmi_4xxx_core_audio_infoframe_cfg(struct hdmi_ip_data *ip_data,
1144 struct hdmi_core_infoframe_audio *info_aud) 1166 struct snd_cea_861_aud_if *info_aud)
1145{ 1167{
1146 u8 val;
1147 u8 sum = 0, checksum = 0; 1168 u8 sum = 0, checksum = 0;
1148 void __iomem *av_base = hdmi_av_base(ip_data); 1169 void __iomem *av_base = hdmi_av_base(ip_data);
1149 1170
@@ -1157,24 +1178,23 @@ void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
1157 hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a); 1178 hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a);
1158 sum += 0x84 + 0x001 + 0x00a; 1179 sum += 0x84 + 0x001 + 0x00a;
1159 1180
1160 val = (info_aud->db1_coding_type << 4) 1181 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0),
1161 | (info_aud->db1_channel_count - 1); 1182 info_aud->db1_ct_cc);
1162 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0), val); 1183 sum += info_aud->db1_ct_cc;
1163 sum += val;
1164 1184
1165 val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size; 1185 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1),
1166 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1), val); 1186 info_aud->db2_sf_ss);
1167 sum += val; 1187 sum += info_aud->db2_sf_ss;
1168 1188
1169 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), 0x00); 1189 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), info_aud->db3);
1190 sum += info_aud->db3;
1170 1191
1171 val = info_aud->db4_channel_alloc; 1192 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), info_aud->db4_ca);
1172 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), val); 1193 sum += info_aud->db4_ca;
1173 sum += val;
1174 1194
1175 val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3); 1195 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4),
1176 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4), val); 1196 info_aud->db5_dminh_lsv);
1177 sum += val; 1197 sum += info_aud->db5_dminh_lsv;
1178 1198
1179 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00); 1199 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
1180 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00); 1200 hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
@@ -1192,70 +1212,212 @@ void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
1192 */ 1212 */
1193} 1213}
1194 1214
1195int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data, 1215int ti_hdmi_4xxx_audio_config(struct hdmi_ip_data *ip_data,
1196 u32 sample_freq, u32 *n, u32 *cts) 1216 struct omap_dss_audio *audio)
1197{ 1217{
1198 u32 r; 1218 struct hdmi_audio_format audio_format;
1199 u32 deep_color = 0; 1219 struct hdmi_audio_dma audio_dma;
1200 u32 pclk = ip_data->cfg.timings.pixel_clock; 1220 struct hdmi_core_audio_config core;
1201 1221 int err, n, cts, channel_count;
1202 if (n == NULL || cts == NULL) 1222 unsigned int fs_nr;
1223 bool word_length_16b = false;
1224
1225 if (!audio || !audio->iec || !audio->cea || !ip_data)
1203 return -EINVAL; 1226 return -EINVAL;
1227
1228 core.iec60958_cfg = audio->iec;
1204 /* 1229 /*
1205 * Obtain current deep color configuration. This needed 1230 * In the IEC-60958 status word, check if the audio sample word length
1206 * to calculate the TMDS clock based on the pixel clock. 1231 * is 16-bit as several optimizations can be performed in such case.
1207 */ 1232 */
1208 r = REG_GET(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, 1, 0); 1233 if (!(audio->iec->status[4] & IEC958_AES4_CON_MAX_WORDLEN_24))
1209 switch (r) { 1234 if (audio->iec->status[4] & IEC958_AES4_CON_WORDLEN_20_16)
1210 case 1: /* No deep color selected */ 1235 word_length_16b = true;
1211 deep_color = 100; 1236
1237 /* I2S configuration. See Phillips' specification */
1238 if (word_length_16b)
1239 core.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
1240 else
1241 core.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
1242 /*
1243 * The I2S input word length is twice the lenght given in the IEC-60958
1244 * status word. If the word size is greater than
1245 * 20 bits, increment by one.
1246 */
1247 core.i2s_cfg.in_length_bits = audio->iec->status[4]
1248 & IEC958_AES4_CON_WORDLEN;
1249 if (audio->iec->status[4] & IEC958_AES4_CON_MAX_WORDLEN_24)
1250 core.i2s_cfg.in_length_bits++;
1251 core.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
1252 core.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
1253 core.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
1254 core.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
1255
1256 /* convert sample frequency to a number */
1257 switch (audio->iec->status[3] & IEC958_AES3_CON_FS) {
1258 case IEC958_AES3_CON_FS_32000:
1259 fs_nr = 32000;
1260 break;
1261 case IEC958_AES3_CON_FS_44100:
1262 fs_nr = 44100;
1263 break;
1264 case IEC958_AES3_CON_FS_48000:
1265 fs_nr = 48000;
1212 break; 1266 break;
1213 case 2: /* 10-bit deep color selected */ 1267 case IEC958_AES3_CON_FS_88200:
1214 deep_color = 125; 1268 fs_nr = 88200;
1215 break; 1269 break;
1216 case 3: /* 12-bit deep color selected */ 1270 case IEC958_AES3_CON_FS_96000:
1217 deep_color = 150; 1271 fs_nr = 96000;
1272 break;
1273 case IEC958_AES3_CON_FS_176400:
1274 fs_nr = 176400;
1275 break;
1276 case IEC958_AES3_CON_FS_192000:
1277 fs_nr = 192000;
1218 break; 1278 break;
1219 default: 1279 default:
1220 return -EINVAL; 1280 return -EINVAL;
1221 } 1281 }
1222 1282
1223 switch (sample_freq) { 1283 err = hdmi_compute_acr(fs_nr, &n, &cts);
1224 case 32000: 1284
1225 if ((deep_color == 125) && ((pclk == 54054) 1285 /* Audio clock regeneration settings */
1226 || (pclk == 74250))) 1286 core.n = n;
1227 *n = 8192; 1287 core.cts = cts;
1228 else 1288 if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
1229 *n = 4096; 1289 core.aud_par_busclk = 0;
1290 core.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
1291 core.use_mclk = dss_has_feature(FEAT_HDMI_AUDIO_USE_MCLK);
1292 } else {
1293 core.aud_par_busclk = (((128 * 31) - 1) << 8);
1294 core.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
1295 core.use_mclk = true;
1296 }
1297
1298 if (core.use_mclk)
1299 core.mclk_mode = HDMI_AUDIO_MCLK_128FS;
1300
1301 /* Audio channels settings */
1302 channel_count = (audio->cea->db1_ct_cc &
1303 CEA861_AUDIO_INFOFRAME_DB1CC) + 1;
1304
1305 switch (channel_count) {
1306 case 2:
1307 audio_format.active_chnnls_msk = 0x03;
1308 break;
1309 case 3:
1310 audio_format.active_chnnls_msk = 0x07;
1311 break;
1312 case 4:
1313 audio_format.active_chnnls_msk = 0x0f;
1314 break;
1315 case 5:
1316 audio_format.active_chnnls_msk = 0x1f;
1230 break; 1317 break;
1231 case 44100: 1318 case 6:
1232 *n = 6272; 1319 audio_format.active_chnnls_msk = 0x3f;
1233 break; 1320 break;
1234 case 48000: 1321 case 7:
1235 if ((deep_color == 125) && ((pclk == 54054) 1322 audio_format.active_chnnls_msk = 0x7f;
1236 || (pclk == 74250))) 1323 break;
1237 *n = 8192; 1324 case 8:
1238 else 1325 audio_format.active_chnnls_msk = 0xff;
1239 *n = 6144;
1240 break; 1326 break;
1241 default: 1327 default:
1242 *n = 0;
1243 return -EINVAL; 1328 return -EINVAL;
1244 } 1329 }
1245 1330
1246 /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */ 1331 /*
1247 *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10); 1332 * the HDMI IP needs to enable four stereo channels when transmitting
1333 * more than 2 audio channels
1334 */
1335 if (channel_count == 2) {
1336 audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL;
1337 core.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
1338 core.layout = HDMI_AUDIO_LAYOUT_2CH;
1339 } else {
1340 audio_format.stereo_channels = HDMI_AUDIO_STEREO_FOURCHANNELS;
1341 core.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN |
1342 HDMI_AUDIO_I2S_SD1_EN | HDMI_AUDIO_I2S_SD2_EN |
1343 HDMI_AUDIO_I2S_SD3_EN;
1344 core.layout = HDMI_AUDIO_LAYOUT_8CH;
1345 }
1346
1347 core.en_spdif = false;
1348 /* use sample frequency from channel status word */
1349 core.fs_override = true;
1350 /* enable ACR packets */
1351 core.en_acr_pkt = true;
1352 /* disable direct streaming digital audio */
1353 core.en_dsd_audio = false;
1354 /* use parallel audio interface */
1355 core.en_parallel_aud_input = true;
1356
1357 /* DMA settings */
1358 if (word_length_16b)
1359 audio_dma.transfer_size = 0x10;
1360 else
1361 audio_dma.transfer_size = 0x20;
1362 audio_dma.block_size = 0xC0;
1363 audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
1364 audio_dma.fifo_threshold = 0x20; /* in number of samples */
1365
1366 /* audio FIFO format settings */
1367 if (word_length_16b) {
1368 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
1369 audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
1370 audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
1371 } else {
1372 audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
1373 audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
1374 audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
1375 }
1376 audio_format.type = HDMI_AUDIO_TYPE_LPCM;
1377 audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
1378 /* disable start/stop signals of IEC 60958 blocks */
1379 audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_ON;
1380
1381 /* configure DMA and audio FIFO format*/
1382 ti_hdmi_4xxx_wp_audio_config_dma(ip_data, &audio_dma);
1383 ti_hdmi_4xxx_wp_audio_config_format(ip_data, &audio_format);
1384
1385 /* configure the core*/
1386 ti_hdmi_4xxx_core_audio_config(ip_data, &core);
1387
1388 /* configure CEA 861 audio infoframe*/
1389 ti_hdmi_4xxx_core_audio_infoframe_cfg(ip_data, audio->cea);
1248 1390
1249 return 0; 1391 return 0;
1250} 1392}
1251 1393
1252void ti_hdmi_4xxx_wp_audio_enable(struct hdmi_ip_data *ip_data, bool enable) 1394int ti_hdmi_4xxx_wp_audio_enable(struct hdmi_ip_data *ip_data)
1395{
1396 REG_FLD_MOD(hdmi_wp_base(ip_data),
1397 HDMI_WP_AUDIO_CTRL, true, 31, 31);
1398 return 0;
1399}
1400
1401void ti_hdmi_4xxx_wp_audio_disable(struct hdmi_ip_data *ip_data)
1402{
1403 REG_FLD_MOD(hdmi_wp_base(ip_data),
1404 HDMI_WP_AUDIO_CTRL, false, 31, 31);
1405}
1406
1407int ti_hdmi_4xxx_audio_start(struct hdmi_ip_data *ip_data)
1253{ 1408{
1254 REG_FLD_MOD(hdmi_av_base(ip_data), 1409 REG_FLD_MOD(hdmi_av_base(ip_data),
1255 HDMI_CORE_AV_AUD_MODE, enable, 0, 0); 1410 HDMI_CORE_AV_AUD_MODE, true, 0, 0);
1256 REG_FLD_MOD(hdmi_wp_base(ip_data), 1411 REG_FLD_MOD(hdmi_wp_base(ip_data),
1257 HDMI_WP_AUDIO_CTRL, enable, 31, 31); 1412 HDMI_WP_AUDIO_CTRL, true, 30, 30);
1413 return 0;
1414}
1415
1416void ti_hdmi_4xxx_audio_stop(struct hdmi_ip_data *ip_data)
1417{
1418 REG_FLD_MOD(hdmi_av_base(ip_data),
1419 HDMI_CORE_AV_AUD_MODE, false, 0, 0);
1258 REG_FLD_MOD(hdmi_wp_base(ip_data), 1420 REG_FLD_MOD(hdmi_wp_base(ip_data),
1259 HDMI_WP_AUDIO_CTRL, enable, 30, 30); 1421 HDMI_WP_AUDIO_CTRL, false, 30, 30);
1260} 1422}
1261#endif 1423#endif
diff --git a/drivers/video/omap2/dss/ti_hdmi_4xxx_ip.h b/drivers/video/omap2/dss/ti_hdmi_4xxx_ip.h
index a14d1a0e6e41..8366ae19e82e 100644
--- a/drivers/video/omap2/dss/ti_hdmi_4xxx_ip.h
+++ b/drivers/video/omap2/dss/ti_hdmi_4xxx_ip.h
@@ -24,11 +24,6 @@
24#include <linux/string.h> 24#include <linux/string.h>
25#include <video/omapdss.h> 25#include <video/omapdss.h>
26#include "ti_hdmi.h" 26#include "ti_hdmi.h"
27#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
28 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
29#include <sound/soc.h>
30#include <sound/pcm_params.h>
31#endif
32 27
33/* HDMI Wrapper */ 28/* HDMI Wrapper */
34 29
@@ -57,6 +52,13 @@
57#define HDMI_CORE_SYS_SRST 0x14 52#define HDMI_CORE_SYS_SRST 0x14
58#define HDMI_CORE_CTRL1 0x20 53#define HDMI_CORE_CTRL1 0x20
59#define HDMI_CORE_SYS_SYS_STAT 0x24 54#define HDMI_CORE_SYS_SYS_STAT 0x24
55#define HDMI_CORE_SYS_DE_DLY 0xC8
56#define HDMI_CORE_SYS_DE_CTRL 0xCC
57#define HDMI_CORE_SYS_DE_TOP 0xD0
58#define HDMI_CORE_SYS_DE_CNTL 0xD8
59#define HDMI_CORE_SYS_DE_CNTH 0xDC
60#define HDMI_CORE_SYS_DE_LINL 0xE0
61#define HDMI_CORE_SYS_DE_LINH_1 0xE4
60#define HDMI_CORE_SYS_VID_ACEN 0x124 62#define HDMI_CORE_SYS_VID_ACEN 0x124
61#define HDMI_CORE_SYS_VID_MODE 0x128 63#define HDMI_CORE_SYS_VID_MODE 0x128
62#define HDMI_CORE_SYS_INTR_STATE 0x1C0 64#define HDMI_CORE_SYS_INTR_STATE 0x1C0
@@ -66,50 +68,24 @@
66#define HDMI_CORE_SYS_INTR4 0x1D0 68#define HDMI_CORE_SYS_INTR4 0x1D0
67#define HDMI_CORE_SYS_UMASK1 0x1D4 69#define HDMI_CORE_SYS_UMASK1 0x1D4
68#define HDMI_CORE_SYS_TMDS_CTRL 0x208 70#define HDMI_CORE_SYS_TMDS_CTRL 0x208
69#define HDMI_CORE_SYS_DE_DLY 0xC8 71
70#define HDMI_CORE_SYS_DE_CTRL 0xCC
71#define HDMI_CORE_SYS_DE_TOP 0xD0
72#define HDMI_CORE_SYS_DE_CNTL 0xD8
73#define HDMI_CORE_SYS_DE_CNTH 0xDC
74#define HDMI_CORE_SYS_DE_LINL 0xE0
75#define HDMI_CORE_SYS_DE_LINH_1 0xE4
76#define HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC 0x1 72#define HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC 0x1
77#define HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC 0x1 73#define HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC 0x1
78#define HDMI_CORE_CTRL1_BSEL_24BITBUS 0x1 74#define HDMI_CORE_CTRL1_BSEL_24BITBUS 0x1
79#define HDMI_CORE_CTRL1_EDGE_RISINGEDGE 0x1 75#define HDMI_CORE_CTRL1_EDGE_RISINGEDGE 0x1
80 76
81/* HDMI DDC E-DID */ 77/* HDMI DDC E-DID */
82#define HDMI_CORE_DDC_CMD 0x3CC
83#define HDMI_CORE_DDC_STATUS 0x3C8
84#define HDMI_CORE_DDC_ADDR 0x3B4 78#define HDMI_CORE_DDC_ADDR 0x3B4
79#define HDMI_CORE_DDC_SEGM 0x3B8
85#define HDMI_CORE_DDC_OFFSET 0x3BC 80#define HDMI_CORE_DDC_OFFSET 0x3BC
86#define HDMI_CORE_DDC_COUNT1 0x3C0 81#define HDMI_CORE_DDC_COUNT1 0x3C0
87#define HDMI_CORE_DDC_COUNT2 0x3C4 82#define HDMI_CORE_DDC_COUNT2 0x3C4
83#define HDMI_CORE_DDC_STATUS 0x3C8
84#define HDMI_CORE_DDC_CMD 0x3CC
88#define HDMI_CORE_DDC_DATA 0x3D0 85#define HDMI_CORE_DDC_DATA 0x3D0
89#define HDMI_CORE_DDC_SEGM 0x3B8
90 86
91/* HDMI IP Core Audio Video */ 87/* HDMI IP Core Audio Video */
92 88
93#define HDMI_CORE_AV_HDMI_CTRL 0xBC
94#define HDMI_CORE_AV_DPD 0xF4
95#define HDMI_CORE_AV_PB_CTRL1 0xF8
96#define HDMI_CORE_AV_PB_CTRL2 0xFC
97#define HDMI_CORE_AV_AVI_TYPE 0x100
98#define HDMI_CORE_AV_AVI_VERS 0x104
99#define HDMI_CORE_AV_AVI_LEN 0x108
100#define HDMI_CORE_AV_AVI_CHSUM 0x10C
101#define HDMI_CORE_AV_AVI_DBYTE(n) (n * 4 + 0x110)
102#define HDMI_CORE_AV_AVI_DBYTE_NELEMS 15
103#define HDMI_CORE_AV_SPD_DBYTE(n) (n * 4 + 0x190)
104#define HDMI_CORE_AV_SPD_DBYTE_NELEMS 27
105#define HDMI_CORE_AV_AUD_DBYTE(n) (n * 4 + 0x210)
106#define HDMI_CORE_AV_AUD_DBYTE_NELEMS 10
107#define HDMI_CORE_AV_MPEG_DBYTE(n) (n * 4 + 0x290)
108#define HDMI_CORE_AV_MPEG_DBYTE_NELEMS 27
109#define HDMI_CORE_AV_GEN_DBYTE(n) (n * 4 + 0x300)
110#define HDMI_CORE_AV_GEN_DBYTE_NELEMS 31
111#define HDMI_CORE_AV_GEN2_DBYTE(n) (n * 4 + 0x380)
112#define HDMI_CORE_AV_GEN2_DBYTE_NELEMS 31
113#define HDMI_CORE_AV_ACR_CTRL 0x4 89#define HDMI_CORE_AV_ACR_CTRL 0x4
114#define HDMI_CORE_AV_FREQ_SVAL 0x8 90#define HDMI_CORE_AV_FREQ_SVAL 0x8
115#define HDMI_CORE_AV_N_SVAL1 0xC 91#define HDMI_CORE_AV_N_SVAL1 0xC
@@ -148,25 +124,39 @@
148#define HDMI_CORE_AV_AVI_VERS 0x104 124#define HDMI_CORE_AV_AVI_VERS 0x104
149#define HDMI_CORE_AV_AVI_LEN 0x108 125#define HDMI_CORE_AV_AVI_LEN 0x108
150#define HDMI_CORE_AV_AVI_CHSUM 0x10C 126#define HDMI_CORE_AV_AVI_CHSUM 0x10C
127#define HDMI_CORE_AV_AVI_DBYTE(n) (n * 4 + 0x110)
151#define HDMI_CORE_AV_SPD_TYPE 0x180 128#define HDMI_CORE_AV_SPD_TYPE 0x180
152#define HDMI_CORE_AV_SPD_VERS 0x184 129#define HDMI_CORE_AV_SPD_VERS 0x184
153#define HDMI_CORE_AV_SPD_LEN 0x188 130#define HDMI_CORE_AV_SPD_LEN 0x188
154#define HDMI_CORE_AV_SPD_CHSUM 0x18C 131#define HDMI_CORE_AV_SPD_CHSUM 0x18C
132#define HDMI_CORE_AV_SPD_DBYTE(n) (n * 4 + 0x190)
155#define HDMI_CORE_AV_AUDIO_TYPE 0x200 133#define HDMI_CORE_AV_AUDIO_TYPE 0x200
156#define HDMI_CORE_AV_AUDIO_VERS 0x204 134#define HDMI_CORE_AV_AUDIO_VERS 0x204
157#define HDMI_CORE_AV_AUDIO_LEN 0x208 135#define HDMI_CORE_AV_AUDIO_LEN 0x208
158#define HDMI_CORE_AV_AUDIO_CHSUM 0x20C 136#define HDMI_CORE_AV_AUDIO_CHSUM 0x20C
137#define HDMI_CORE_AV_AUD_DBYTE(n) (n * 4 + 0x210)
159#define HDMI_CORE_AV_MPEG_TYPE 0x280 138#define HDMI_CORE_AV_MPEG_TYPE 0x280
160#define HDMI_CORE_AV_MPEG_VERS 0x284 139#define HDMI_CORE_AV_MPEG_VERS 0x284
161#define HDMI_CORE_AV_MPEG_LEN 0x288 140#define HDMI_CORE_AV_MPEG_LEN 0x288
162#define HDMI_CORE_AV_MPEG_CHSUM 0x28C 141#define HDMI_CORE_AV_MPEG_CHSUM 0x28C
142#define HDMI_CORE_AV_MPEG_DBYTE(n) (n * 4 + 0x290)
143#define HDMI_CORE_AV_GEN_DBYTE(n) (n * 4 + 0x300)
163#define HDMI_CORE_AV_CP_BYTE1 0x37C 144#define HDMI_CORE_AV_CP_BYTE1 0x37C
145#define HDMI_CORE_AV_GEN2_DBYTE(n) (n * 4 + 0x380)
164#define HDMI_CORE_AV_CEC_ADDR_ID 0x3FC 146#define HDMI_CORE_AV_CEC_ADDR_ID 0x3FC
147
165#define HDMI_CORE_AV_SPD_DBYTE_ELSIZE 0x4 148#define HDMI_CORE_AV_SPD_DBYTE_ELSIZE 0x4
166#define HDMI_CORE_AV_GEN2_DBYTE_ELSIZE 0x4 149#define HDMI_CORE_AV_GEN2_DBYTE_ELSIZE 0x4
167#define HDMI_CORE_AV_MPEG_DBYTE_ELSIZE 0x4 150#define HDMI_CORE_AV_MPEG_DBYTE_ELSIZE 0x4
168#define HDMI_CORE_AV_GEN_DBYTE_ELSIZE 0x4 151#define HDMI_CORE_AV_GEN_DBYTE_ELSIZE 0x4
169 152
153#define HDMI_CORE_AV_AVI_DBYTE_NELEMS 15
154#define HDMI_CORE_AV_SPD_DBYTE_NELEMS 27
155#define HDMI_CORE_AV_AUD_DBYTE_NELEMS 10
156#define HDMI_CORE_AV_MPEG_DBYTE_NELEMS 27
157#define HDMI_CORE_AV_GEN_DBYTE_NELEMS 31
158#define HDMI_CORE_AV_GEN2_DBYTE_NELEMS 31
159
170/* PLL */ 160/* PLL */
171 161
172#define PLLCTRL_PLL_CONTROL 0x0 162#define PLLCTRL_PLL_CONTROL 0x0
@@ -284,35 +274,6 @@ enum hdmi_core_infoframe {
284 HDMI_INFOFRAME_AVI_DB5PR_8 = 7, 274 HDMI_INFOFRAME_AVI_DB5PR_8 = 7,
285 HDMI_INFOFRAME_AVI_DB5PR_9 = 8, 275 HDMI_INFOFRAME_AVI_DB5PR_9 = 8,
286 HDMI_INFOFRAME_AVI_DB5PR_10 = 9, 276 HDMI_INFOFRAME_AVI_DB5PR_10 = 9,
287 HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM = 0,
288 HDMI_INFOFRAME_AUDIO_DB1CT_IEC60958 = 1,
289 HDMI_INFOFRAME_AUDIO_DB1CT_AC3 = 2,
290 HDMI_INFOFRAME_AUDIO_DB1CT_MPEG1 = 3,
291 HDMI_INFOFRAME_AUDIO_DB1CT_MP3 = 4,
292 HDMI_INFOFRAME_AUDIO_DB1CT_MPEG2_MULTICH = 5,
293 HDMI_INFOFRAME_AUDIO_DB1CT_AAC = 6,
294 HDMI_INFOFRAME_AUDIO_DB1CT_DTS = 7,
295 HDMI_INFOFRAME_AUDIO_DB1CT_ATRAC = 8,
296 HDMI_INFOFRAME_AUDIO_DB1CT_ONEBIT = 9,
297 HDMI_INFOFRAME_AUDIO_DB1CT_DOLBY_DIGITAL_PLUS = 10,
298 HDMI_INFOFRAME_AUDIO_DB1CT_DTS_HD = 11,
299 HDMI_INFOFRAME_AUDIO_DB1CT_MAT = 12,
300 HDMI_INFOFRAME_AUDIO_DB1CT_DST = 13,
301 HDMI_INFOFRAME_AUDIO_DB1CT_WMA_PRO = 14,
302 HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM = 0,
303 HDMI_INFOFRAME_AUDIO_DB2SF_32000 = 1,
304 HDMI_INFOFRAME_AUDIO_DB2SF_44100 = 2,
305 HDMI_INFOFRAME_AUDIO_DB2SF_48000 = 3,
306 HDMI_INFOFRAME_AUDIO_DB2SF_88200 = 4,
307 HDMI_INFOFRAME_AUDIO_DB2SF_96000 = 5,
308 HDMI_INFOFRAME_AUDIO_DB2SF_176400 = 6,
309 HDMI_INFOFRAME_AUDIO_DB2SF_192000 = 7,
310 HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM = 0,
311 HDMI_INFOFRAME_AUDIO_DB2SS_16BIT = 1,
312 HDMI_INFOFRAME_AUDIO_DB2SS_20BIT = 2,
313 HDMI_INFOFRAME_AUDIO_DB2SS_24BIT = 3,
314 HDMI_INFOFRAME_AUDIO_DB5_DM_INH_PERMITTED = 0,
315 HDMI_INFOFRAME_AUDIO_DB5_DM_INH_PROHIBITED = 1
316}; 277};
317 278
318enum hdmi_packing_mode { 279enum hdmi_packing_mode {
@@ -322,17 +283,6 @@ enum hdmi_packing_mode {
322 HDMI_PACK_ALREADYPACKED = 7 283 HDMI_PACK_ALREADYPACKED = 7
323}; 284};
324 285
325enum hdmi_core_audio_sample_freq {
326 HDMI_AUDIO_FS_32000 = 0x3,
327 HDMI_AUDIO_FS_44100 = 0x0,
328 HDMI_AUDIO_FS_48000 = 0x2,
329 HDMI_AUDIO_FS_88200 = 0x8,
330 HDMI_AUDIO_FS_96000 = 0xA,
331 HDMI_AUDIO_FS_176400 = 0xC,
332 HDMI_AUDIO_FS_192000 = 0xE,
333 HDMI_AUDIO_FS_NOT_INDICATED = 0x1
334};
335
336enum hdmi_core_audio_layout { 286enum hdmi_core_audio_layout {
337 HDMI_AUDIO_LAYOUT_2CH = 0, 287 HDMI_AUDIO_LAYOUT_2CH = 0,
338 HDMI_AUDIO_LAYOUT_8CH = 1 288 HDMI_AUDIO_LAYOUT_8CH = 1
@@ -387,37 +337,12 @@ enum hdmi_audio_blk_strt_end_sig {
387}; 337};
388 338
389enum hdmi_audio_i2s_config { 339enum hdmi_audio_i2s_config {
390 HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT = 0,
391 HDMI_AUDIO_I2S_WS_POLARIT_YLOW_IS_RIGHT = 1,
392 HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST = 0, 340 HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST = 0,
393 HDMI_AUDIO_I2S_LSB_SHIFTED_FIRST = 1, 341 HDMI_AUDIO_I2S_LSB_SHIFTED_FIRST = 1,
394 HDMI_AUDIO_I2S_MAX_WORD_20BITS = 0,
395 HDMI_AUDIO_I2S_MAX_WORD_24BITS = 1,
396 HDMI_AUDIO_I2S_CHST_WORD_NOT_SPECIFIED = 0,
397 HDMI_AUDIO_I2S_CHST_WORD_16_BITS = 1,
398 HDMI_AUDIO_I2S_CHST_WORD_17_BITS = 6,
399 HDMI_AUDIO_I2S_CHST_WORD_18_BITS = 2,
400 HDMI_AUDIO_I2S_CHST_WORD_19_BITS = 4,
401 HDMI_AUDIO_I2S_CHST_WORD_20_BITS_20MAX = 5,
402 HDMI_AUDIO_I2S_CHST_WORD_20_BITS_24MAX = 1,
403 HDMI_AUDIO_I2S_CHST_WORD_21_BITS = 6,
404 HDMI_AUDIO_I2S_CHST_WORD_22_BITS = 2,
405 HDMI_AUDIO_I2S_CHST_WORD_23_BITS = 4,
406 HDMI_AUDIO_I2S_CHST_WORD_24_BITS = 5,
407 HDMI_AUDIO_I2S_SCK_EDGE_FALLING = 0, 342 HDMI_AUDIO_I2S_SCK_EDGE_FALLING = 0,
408 HDMI_AUDIO_I2S_SCK_EDGE_RISING = 1, 343 HDMI_AUDIO_I2S_SCK_EDGE_RISING = 1,
409 HDMI_AUDIO_I2S_VBIT_FOR_PCM = 0, 344 HDMI_AUDIO_I2S_VBIT_FOR_PCM = 0,
410 HDMI_AUDIO_I2S_VBIT_FOR_COMPRESSED = 1, 345 HDMI_AUDIO_I2S_VBIT_FOR_COMPRESSED = 1,
411 HDMI_AUDIO_I2S_INPUT_LENGTH_NA = 0,
412 HDMI_AUDIO_I2S_INPUT_LENGTH_16 = 2,
413 HDMI_AUDIO_I2S_INPUT_LENGTH_17 = 12,
414 HDMI_AUDIO_I2S_INPUT_LENGTH_18 = 4,
415 HDMI_AUDIO_I2S_INPUT_LENGTH_19 = 8,
416 HDMI_AUDIO_I2S_INPUT_LENGTH_20 = 10,
417 HDMI_AUDIO_I2S_INPUT_LENGTH_21 = 13,
418 HDMI_AUDIO_I2S_INPUT_LENGTH_22 = 5,
419 HDMI_AUDIO_I2S_INPUT_LENGTH_23 = 9,
420 HDMI_AUDIO_I2S_INPUT_LENGTH_24 = 11,
421 HDMI_AUDIO_I2S_FIRST_BIT_SHIFT = 0, 346 HDMI_AUDIO_I2S_FIRST_BIT_SHIFT = 0,
422 HDMI_AUDIO_I2S_FIRST_BIT_NO_SHIFT = 1, 347 HDMI_AUDIO_I2S_FIRST_BIT_NO_SHIFT = 1,
423 HDMI_AUDIO_I2S_SD0_EN = 1, 348 HDMI_AUDIO_I2S_SD0_EN = 1,
@@ -446,20 +371,6 @@ struct hdmi_core_video_config {
446 enum hdmi_core_tclkselclkmult tclk_sel_clkmult; 371 enum hdmi_core_tclkselclkmult tclk_sel_clkmult;
447}; 372};
448 373
449/*
450 * Refer to section 8.2 in HDMI 1.3 specification for
451 * details about infoframe databytes
452 */
453struct hdmi_core_infoframe_audio {
454 u8 db1_coding_type;
455 u8 db1_channel_count;
456 u8 db2_sample_freq;
457 u8 db2_sample_size;
458 u8 db4_channel_alloc;
459 bool db5_downmix_inh;
460 u8 db5_lsv; /* Level shift values for downmix */
461};
462
463struct hdmi_core_packet_enable_repeat { 374struct hdmi_core_packet_enable_repeat {
464 u32 audio_pkt; 375 u32 audio_pkt;
465 u32 audio_pkt_repeat; 376 u32 audio_pkt_repeat;
@@ -496,15 +407,10 @@ struct hdmi_audio_dma {
496}; 407};
497 408
498struct hdmi_core_audio_i2s_config { 409struct hdmi_core_audio_i2s_config {
499 u8 word_max_length;
500 u8 word_length;
501 u8 in_length_bits; 410 u8 in_length_bits;
502 u8 justification; 411 u8 justification;
503 u8 en_high_bitrate_aud;
504 u8 sck_edge_mode; 412 u8 sck_edge_mode;
505 u8 cbit_order;
506 u8 vbit; 413 u8 vbit;
507 u8 ws_polarity;
508 u8 direction; 414 u8 direction;
509 u8 shift; 415 u8 shift;
510 u8 active_sds; 416 u8 active_sds;
@@ -512,7 +418,7 @@ struct hdmi_core_audio_i2s_config {
512 418
513struct hdmi_core_audio_config { 419struct hdmi_core_audio_config {
514 struct hdmi_core_audio_i2s_config i2s_cfg; 420 struct hdmi_core_audio_i2s_config i2s_cfg;
515 enum hdmi_core_audio_sample_freq freq_sample; 421 struct snd_aes_iec958 *iec60958_cfg;
516 bool fs_override; 422 bool fs_override;
517 u32 n; 423 u32 n;
518 u32 cts; 424 u32 cts;
@@ -527,17 +433,4 @@ struct hdmi_core_audio_config {
527 bool en_spdif; 433 bool en_spdif;
528}; 434};
529 435
530#if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
531 defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
532int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data,
533 u32 sample_freq, u32 *n, u32 *cts);
534void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
535 struct hdmi_core_infoframe_audio *info_aud);
536void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
537 struct hdmi_core_audio_config *cfg);
538void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
539 struct hdmi_audio_dma *aud_dma);
540void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
541 struct hdmi_audio_format *aud_fmt);
542#endif
543#endif 436#endif
diff --git a/drivers/video/omap2/dss/venc.c b/drivers/video/omap2/dss/venc.c
index 9c3daf71750c..2b8973931ff4 100644
--- a/drivers/video/omap2/dss/venc.c
+++ b/drivers/video/omap2/dss/venc.c
@@ -415,6 +415,7 @@ static const struct venc_config *venc_timings_to_config(
415 return &venc_config_ntsc_trm; 415 return &venc_config_ntsc_trm;
416 416
417 BUG(); 417 BUG();
418 return NULL;
418} 419}
419 420
420static int venc_power_on(struct omap_dss_device *dssdev) 421static int venc_power_on(struct omap_dss_device *dssdev)
@@ -440,10 +441,11 @@ static int venc_power_on(struct omap_dss_device *dssdev)
440 441
441 venc_write_reg(VENC_OUTPUT_CONTROL, l); 442 venc_write_reg(VENC_OUTPUT_CONTROL, l);
442 443
443 dispc_set_digit_size(dssdev->panel.timings.x_res, 444 dss_mgr_set_timings(dssdev->manager, &dssdev->panel.timings);
444 dssdev->panel.timings.y_res/2);
445 445
446 regulator_enable(venc.vdda_dac_reg); 446 r = regulator_enable(venc.vdda_dac_reg);
447 if (r)
448 goto err;
447 449
448 if (dssdev->platform_enable) 450 if (dssdev->platform_enable)
449 dssdev->platform_enable(dssdev); 451 dssdev->platform_enable(dssdev);
@@ -485,16 +487,68 @@ unsigned long venc_get_pixel_clock(void)
485 return 13500000; 487 return 13500000;
486} 488}
487 489
490static ssize_t display_output_type_show(struct device *dev,
491 struct device_attribute *attr, char *buf)
492{
493 struct omap_dss_device *dssdev = to_dss_device(dev);
494 const char *ret;
495
496 switch (dssdev->phy.venc.type) {
497 case OMAP_DSS_VENC_TYPE_COMPOSITE:
498 ret = "composite";
499 break;
500 case OMAP_DSS_VENC_TYPE_SVIDEO:
501 ret = "svideo";
502 break;
503 default:
504 return -EINVAL;
505 }
506
507 return snprintf(buf, PAGE_SIZE, "%s\n", ret);
508}
509
510static ssize_t display_output_type_store(struct device *dev,
511 struct device_attribute *attr, const char *buf, size_t size)
512{
513 struct omap_dss_device *dssdev = to_dss_device(dev);
514 enum omap_dss_venc_type new_type;
515
516 if (sysfs_streq("composite", buf))
517 new_type = OMAP_DSS_VENC_TYPE_COMPOSITE;
518 else if (sysfs_streq("svideo", buf))
519 new_type = OMAP_DSS_VENC_TYPE_SVIDEO;
520 else
521 return -EINVAL;
522
523 mutex_lock(&venc.venc_lock);
524
525 if (dssdev->phy.venc.type != new_type) {
526 dssdev->phy.venc.type = new_type;
527 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
528 venc_power_off(dssdev);
529 venc_power_on(dssdev);
530 }
531 }
532
533 mutex_unlock(&venc.venc_lock);
534
535 return size;
536}
537
538static DEVICE_ATTR(output_type, S_IRUGO | S_IWUSR,
539 display_output_type_show, display_output_type_store);
540
488/* driver */ 541/* driver */
489static int venc_panel_probe(struct omap_dss_device *dssdev) 542static int venc_panel_probe(struct omap_dss_device *dssdev)
490{ 543{
491 dssdev->panel.timings = omap_dss_pal_timings; 544 dssdev->panel.timings = omap_dss_pal_timings;
492 545
493 return 0; 546 return device_create_file(&dssdev->dev, &dev_attr_output_type);
494} 547}
495 548
496static void venc_panel_remove(struct omap_dss_device *dssdev) 549static void venc_panel_remove(struct omap_dss_device *dssdev)
497{ 550{
551 device_remove_file(&dssdev->dev, &dev_attr_output_type);
498} 552}
499 553
500static int venc_panel_enable(struct omap_dss_device *dssdev) 554static int venc_panel_enable(struct omap_dss_device *dssdev)
@@ -577,12 +631,6 @@ static int venc_panel_resume(struct omap_dss_device *dssdev)
577 return venc_panel_enable(dssdev); 631 return venc_panel_enable(dssdev);
578} 632}
579 633
580static void venc_get_timings(struct omap_dss_device *dssdev,
581 struct omap_video_timings *timings)
582{
583 *timings = dssdev->panel.timings;
584}
585
586static void venc_set_timings(struct omap_dss_device *dssdev, 634static void venc_set_timings(struct omap_dss_device *dssdev,
587 struct omap_video_timings *timings) 635 struct omap_video_timings *timings)
588{ 636{
@@ -597,6 +645,8 @@ static void venc_set_timings(struct omap_dss_device *dssdev,
597 /* turn the venc off and on to get new timings to use */ 645 /* turn the venc off and on to get new timings to use */
598 venc_panel_disable(dssdev); 646 venc_panel_disable(dssdev);
599 venc_panel_enable(dssdev); 647 venc_panel_enable(dssdev);
648 } else {
649 dss_mgr_set_timings(dssdev->manager, timings);
600 } 650 }
601} 651}
602 652
@@ -661,7 +711,6 @@ static struct omap_dss_driver venc_driver = {
661 .get_resolution = omapdss_default_get_resolution, 711 .get_resolution = omapdss_default_get_resolution,
662 .get_recommended_bpp = omapdss_default_get_recommended_bpp, 712 .get_recommended_bpp = omapdss_default_get_recommended_bpp,
663 713
664 .get_timings = venc_get_timings,
665 .set_timings = venc_set_timings, 714 .set_timings = venc_set_timings,
666 .check_timings = venc_check_timings, 715 .check_timings = venc_check_timings,
667 716
@@ -675,7 +724,7 @@ static struct omap_dss_driver venc_driver = {
675}; 724};
676/* driver end */ 725/* driver end */
677 726
678int venc_init_display(struct omap_dss_device *dssdev) 727static int __init venc_init_display(struct omap_dss_device *dssdev)
679{ 728{
680 DSSDBG("init_display\n"); 729 DSSDBG("init_display\n");
681 730
@@ -695,7 +744,7 @@ int venc_init_display(struct omap_dss_device *dssdev)
695 return 0; 744 return 0;
696} 745}
697 746
698void venc_dump_regs(struct seq_file *s) 747static void venc_dump_regs(struct seq_file *s)
699{ 748{
700#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, venc_read_reg(r)) 749#define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, venc_read_reg(r))
701 750
@@ -779,8 +828,32 @@ static void venc_put_clocks(void)
779 clk_put(venc.tv_dac_clk); 828 clk_put(venc.tv_dac_clk);
780} 829}
781 830
831static void __init venc_probe_pdata(struct platform_device *pdev)
832{
833 struct omap_dss_board_info *pdata = pdev->dev.platform_data;
834 int r, i;
835
836 for (i = 0; i < pdata->num_devices; ++i) {
837 struct omap_dss_device *dssdev = pdata->devices[i];
838
839 if (dssdev->type != OMAP_DISPLAY_TYPE_VENC)
840 continue;
841
842 r = venc_init_display(dssdev);
843 if (r) {
844 DSSERR("device %s init failed: %d\n", dssdev->name, r);
845 continue;
846 }
847
848 r = omap_dss_register_device(dssdev, &pdev->dev, i);
849 if (r)
850 DSSERR("device %s register failed: %d\n",
851 dssdev->name, r);
852 }
853}
854
782/* VENC HW IP initialisation */ 855/* VENC HW IP initialisation */
783static int omap_venchw_probe(struct platform_device *pdev) 856static int __init omap_venchw_probe(struct platform_device *pdev)
784{ 857{
785 u8 rev_id; 858 u8 rev_id;
786 struct resource *venc_mem; 859 struct resource *venc_mem;
@@ -824,6 +897,10 @@ static int omap_venchw_probe(struct platform_device *pdev)
824 if (r) 897 if (r)
825 goto err_reg_panel_driver; 898 goto err_reg_panel_driver;
826 899
900 dss_debugfs_create_file("venc", venc_dump_regs);
901
902 venc_probe_pdata(pdev);
903
827 return 0; 904 return 0;
828 905
829err_reg_panel_driver: 906err_reg_panel_driver:
@@ -833,12 +910,15 @@ err_runtime_get:
833 return r; 910 return r;
834} 911}
835 912
836static int omap_venchw_remove(struct platform_device *pdev) 913static int __exit omap_venchw_remove(struct platform_device *pdev)
837{ 914{
915 omap_dss_unregister_child_devices(&pdev->dev);
916
838 if (venc.vdda_dac_reg != NULL) { 917 if (venc.vdda_dac_reg != NULL) {
839 regulator_put(venc.vdda_dac_reg); 918 regulator_put(venc.vdda_dac_reg);
840 venc.vdda_dac_reg = NULL; 919 venc.vdda_dac_reg = NULL;
841 } 920 }
921
842 omap_dss_unregister_driver(&venc_driver); 922 omap_dss_unregister_driver(&venc_driver);
843 923
844 pm_runtime_disable(&pdev->dev); 924 pm_runtime_disable(&pdev->dev);
@@ -853,7 +933,6 @@ static int venc_runtime_suspend(struct device *dev)
853 clk_disable(venc.tv_dac_clk); 933 clk_disable(venc.tv_dac_clk);
854 934
855 dispc_runtime_put(); 935 dispc_runtime_put();
856 dss_runtime_put();
857 936
858 return 0; 937 return 0;
859} 938}
@@ -862,23 +941,14 @@ static int venc_runtime_resume(struct device *dev)
862{ 941{
863 int r; 942 int r;
864 943
865 r = dss_runtime_get();
866 if (r < 0)
867 goto err_get_dss;
868
869 r = dispc_runtime_get(); 944 r = dispc_runtime_get();
870 if (r < 0) 945 if (r < 0)
871 goto err_get_dispc; 946 return r;
872 947
873 if (venc.tv_dac_clk) 948 if (venc.tv_dac_clk)
874 clk_enable(venc.tv_dac_clk); 949 clk_enable(venc.tv_dac_clk);
875 950
876 return 0; 951 return 0;
877
878err_get_dispc:
879 dss_runtime_put();
880err_get_dss:
881 return r;
882} 952}
883 953
884static const struct dev_pm_ops venc_pm_ops = { 954static const struct dev_pm_ops venc_pm_ops = {
@@ -887,8 +957,7 @@ static const struct dev_pm_ops venc_pm_ops = {
887}; 957};
888 958
889static struct platform_driver omap_venchw_driver = { 959static struct platform_driver omap_venchw_driver = {
890 .probe = omap_venchw_probe, 960 .remove = __exit_p(omap_venchw_remove),
891 .remove = omap_venchw_remove,
892 .driver = { 961 .driver = {
893 .name = "omapdss_venc", 962 .name = "omapdss_venc",
894 .owner = THIS_MODULE, 963 .owner = THIS_MODULE,
@@ -896,18 +965,18 @@ static struct platform_driver omap_venchw_driver = {
896 }, 965 },
897}; 966};
898 967
899int venc_init_platform_driver(void) 968int __init venc_init_platform_driver(void)
900{ 969{
901 if (cpu_is_omap44xx()) 970 if (cpu_is_omap44xx())
902 return 0; 971 return 0;
903 972
904 return platform_driver_register(&omap_venchw_driver); 973 return platform_driver_probe(&omap_venchw_driver, omap_venchw_probe);
905} 974}
906 975
907void venc_uninit_platform_driver(void) 976void __exit venc_uninit_platform_driver(void)
908{ 977{
909 if (cpu_is_omap44xx()) 978 if (cpu_is_omap44xx())
910 return; 979 return;
911 980
912 return platform_driver_unregister(&omap_venchw_driver); 981 platform_driver_unregister(&omap_venchw_driver);
913} 982}
diff --git a/drivers/video/omap2/omapfb/omapfb-ioctl.c b/drivers/video/omap2/omapfb/omapfb-ioctl.c
index 6a09ef87e14f..c6cf372d22c5 100644
--- a/drivers/video/omap2/omapfb/omapfb-ioctl.c
+++ b/drivers/video/omap2/omapfb/omapfb-ioctl.c
@@ -70,7 +70,7 @@ static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
70 70
71 DBG("omapfb_setup_plane\n"); 71 DBG("omapfb_setup_plane\n");
72 72
73 if (ofbi->num_overlays != 1) { 73 if (ofbi->num_overlays == 0) {
74 r = -EINVAL; 74 r = -EINVAL;
75 goto out; 75 goto out;
76 } 76 }
@@ -185,7 +185,7 @@ static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
185{ 185{
186 struct omapfb_info *ofbi = FB2OFB(fbi); 186 struct omapfb_info *ofbi = FB2OFB(fbi);
187 187
188 if (ofbi->num_overlays != 1) { 188 if (ofbi->num_overlays == 0) {
189 memset(pi, 0, sizeof(*pi)); 189 memset(pi, 0, sizeof(*pi));
190 } else { 190 } else {
191 struct omap_overlay *ovl; 191 struct omap_overlay *ovl;
@@ -225,6 +225,9 @@ static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
225 down_write_nested(&rg->lock, rg->id); 225 down_write_nested(&rg->lock, rg->id);
226 atomic_inc(&rg->lock_count); 226 atomic_inc(&rg->lock_count);
227 227
228 if (rg->size == size && rg->type == mi->type)
229 goto out;
230
228 if (atomic_read(&rg->map_count)) { 231 if (atomic_read(&rg->map_count)) {
229 r = -EBUSY; 232 r = -EBUSY;
230 goto out; 233 goto out;
@@ -247,12 +250,10 @@ static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
247 } 250 }
248 } 251 }
249 252
250 if (rg->size != size || rg->type != mi->type) { 253 r = omapfb_realloc_fbmem(fbi, size, mi->type);
251 r = omapfb_realloc_fbmem(fbi, size, mi->type); 254 if (r) {
252 if (r) { 255 dev_err(fbdev->dev, "realloc fbmem failed\n");
253 dev_err(fbdev->dev, "realloc fbmem failed\n"); 256 goto out;
254 goto out;
255 }
256 } 257 }
257 258
258 out: 259 out:
diff --git a/drivers/video/omap2/omapfb/omapfb-main.c b/drivers/video/omap2/omapfb/omapfb-main.c
index b00db4068d21..3450ea0966c9 100644
--- a/drivers/video/omap2/omapfb/omapfb-main.c
+++ b/drivers/video/omap2/omapfb/omapfb-main.c
@@ -179,6 +179,7 @@ static unsigned omapfb_get_vrfb_offset(const struct omapfb_info *ofbi, int rot)
179 break; 179 break;
180 default: 180 default:
181 BUG(); 181 BUG();
182 return 0;
182 } 183 }
183 184
184 offset *= vrfb->bytespp; 185 offset *= vrfb->bytespp;
@@ -1502,7 +1503,7 @@ static int omapfb_parse_vram_param(const char *param, int max_entries,
1502 1503
1503 fbnum = simple_strtoul(p, &p, 10); 1504 fbnum = simple_strtoul(p, &p, 10);
1504 1505
1505 if (p == param) 1506 if (p == start)
1506 return -EINVAL; 1507 return -EINVAL;
1507 1508
1508 if (*p != ':') 1509 if (*p != ':')
@@ -2307,7 +2308,7 @@ static int omapfb_init_display(struct omapfb2_device *fbdev,
2307 return 0; 2308 return 0;
2308} 2309}
2309 2310
2310static int omapfb_probe(struct platform_device *pdev) 2311static int __init omapfb_probe(struct platform_device *pdev)
2311{ 2312{
2312 struct omapfb2_device *fbdev = NULL; 2313 struct omapfb2_device *fbdev = NULL;
2313 int r = 0; 2314 int r = 0;
@@ -2448,7 +2449,7 @@ err0:
2448 return r; 2449 return r;
2449} 2450}
2450 2451
2451static int omapfb_remove(struct platform_device *pdev) 2452static int __exit omapfb_remove(struct platform_device *pdev)
2452{ 2453{
2453 struct omapfb2_device *fbdev = platform_get_drvdata(pdev); 2454 struct omapfb2_device *fbdev = platform_get_drvdata(pdev);
2454 2455
@@ -2462,8 +2463,7 @@ static int omapfb_remove(struct platform_device *pdev)
2462} 2463}
2463 2464
2464static struct platform_driver omapfb_driver = { 2465static struct platform_driver omapfb_driver = {
2465 .probe = omapfb_probe, 2466 .remove = __exit_p(omapfb_remove),
2466 .remove = omapfb_remove,
2467 .driver = { 2467 .driver = {
2468 .name = "omapfb", 2468 .name = "omapfb",
2469 .owner = THIS_MODULE, 2469 .owner = THIS_MODULE,
@@ -2474,7 +2474,7 @@ static int __init omapfb_init(void)
2474{ 2474{
2475 DBG("omapfb_init\n"); 2475 DBG("omapfb_init\n");
2476 2476
2477 if (platform_driver_register(&omapfb_driver)) { 2477 if (platform_driver_probe(&omapfb_driver, omapfb_probe)) {
2478 printk(KERN_ERR "failed to register omapfb driver\n"); 2478 printk(KERN_ERR "failed to register omapfb driver\n");
2479 return -ENODEV; 2479 return -ENODEV;
2480 } 2480 }
diff --git a/drivers/video/omap2/omapfb/omapfb.h b/drivers/video/omap2/omapfb/omapfb.h
index c0bdc9b54ecf..30361a09aecd 100644
--- a/drivers/video/omap2/omapfb/omapfb.h
+++ b/drivers/video/omap2/omapfb/omapfb.h
@@ -166,6 +166,7 @@ static inline struct omapfb_display_data *get_display_data(
166 166
167 /* This should never happen */ 167 /* This should never happen */
168 BUG(); 168 BUG();
169 return NULL;
169} 170}
170 171
171static inline void omapfb_lock(struct omapfb2_device *fbdev) 172static inline void omapfb_lock(struct omapfb2_device *fbdev)
diff --git a/drivers/video/omap2/vrfb.c b/drivers/video/omap2/vrfb.c
index 4e5b960c32c8..7e990220ad2a 100644
--- a/drivers/video/omap2/vrfb.c
+++ b/drivers/video/omap2/vrfb.c
@@ -179,8 +179,10 @@ void omap_vrfb_setup(struct vrfb *vrfb, unsigned long paddr,
179 pixel_size_exp = 2; 179 pixel_size_exp = 2;
180 else if (bytespp == 2) 180 else if (bytespp == 2)
181 pixel_size_exp = 1; 181 pixel_size_exp = 1;
182 else 182 else {
183 BUG(); 183 BUG();
184 return;
185 }
184 186
185 vrfb_width = ALIGN(width * bytespp, VRFB_PAGE_WIDTH) / bytespp; 187 vrfb_width = ALIGN(width * bytespp, VRFB_PAGE_WIDTH) / bytespp;
186 vrfb_height = ALIGN(height, VRFB_PAGE_HEIGHT); 188 vrfb_height = ALIGN(height, VRFB_PAGE_HEIGHT);
diff --git a/drivers/video/pxa3xx-gcu.c b/drivers/video/pxa3xx-gcu.c
index 1d71c08a818f..0b4ae0cebeda 100644
--- a/drivers/video/pxa3xx-gcu.c
+++ b/drivers/video/pxa3xx-gcu.c
@@ -316,12 +316,9 @@ pxa3xx_gcu_wait_idle(struct pxa3xx_gcu_priv *priv)
316 ret = wait_event_interruptible_timeout(priv->wait_idle, 316 ret = wait_event_interruptible_timeout(priv->wait_idle,
317 !priv->shared->hw_running, HZ*4); 317 !priv->shared->hw_running, HZ*4);
318 318
319 if (ret < 0) 319 if (ret != 0)
320 break; 320 break;
321 321
322 if (ret > 0)
323 continue;
324
325 if (gc_readl(priv, REG_GCRBEXHR) == rbexhr && 322 if (gc_readl(priv, REG_GCRBEXHR) == rbexhr &&
326 priv->shared->num_interrupts == num) { 323 priv->shared->num_interrupts == num) {
327 QERROR("TIMEOUT"); 324 QERROR("TIMEOUT");
diff --git a/drivers/video/s3c-fb.c b/drivers/video/s3c-fb.c
index f3105160bf98..5f9d8e69029e 100644
--- a/drivers/video/s3c-fb.c
+++ b/drivers/video/s3c-fb.c
@@ -47,7 +47,7 @@
47#ifdef CONFIG_FB_S3C_DEBUG_REGWRITE 47#ifdef CONFIG_FB_S3C_DEBUG_REGWRITE
48#undef writel 48#undef writel
49#define writel(v, r) do { \ 49#define writel(v, r) do { \
50 printk(KERN_DEBUG "%s: %08x => %p\n", __func__, (unsigned int)v, r); \ 50 pr_debug("%s: %08x => %p\n", __func__, (unsigned int)v, r); \
51 __raw_writel(v, r); \ 51 __raw_writel(v, r); \
52} while (0) 52} while (0)
53#endif /* FB_S3C_DEBUG_REGWRITE */ 53#endif /* FB_S3C_DEBUG_REGWRITE */
@@ -495,7 +495,6 @@ static int s3c_fb_set_par(struct fb_info *info)
495 u32 alpha = 0; 495 u32 alpha = 0;
496 u32 data; 496 u32 data;
497 u32 pagewidth; 497 u32 pagewidth;
498 int clkdiv;
499 498
500 dev_dbg(sfb->dev, "setting framebuffer parameters\n"); 499 dev_dbg(sfb->dev, "setting framebuffer parameters\n");
501 500
@@ -532,48 +531,9 @@ static int s3c_fb_set_par(struct fb_info *info)
532 /* disable the window whilst we update it */ 531 /* disable the window whilst we update it */
533 writel(0, regs + WINCON(win_no)); 532 writel(0, regs + WINCON(win_no));
534 533
535 /* use platform specified window as the basis for the lcd timings */ 534 if (!sfb->output_on)
536
537 if (win_no == sfb->pdata->default_win) {
538 clkdiv = s3c_fb_calc_pixclk(sfb, var->pixclock);
539
540 data = sfb->pdata->vidcon0;
541 data &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
542
543 if (clkdiv > 1)
544 data |= VIDCON0_CLKVAL_F(clkdiv-1) | VIDCON0_CLKDIR;
545 else
546 data &= ~VIDCON0_CLKDIR; /* 1:1 clock */
547
548 /* write the timing data to the panel */
549
550 if (sfb->variant.is_2443)
551 data |= (1 << 5);
552
553 writel(data, regs + VIDCON0);
554
555 s3c_fb_enable(sfb, 1); 535 s3c_fb_enable(sfb, 1);
556 536
557 data = VIDTCON0_VBPD(var->upper_margin - 1) |
558 VIDTCON0_VFPD(var->lower_margin - 1) |
559 VIDTCON0_VSPW(var->vsync_len - 1);
560
561 writel(data, regs + sfb->variant.vidtcon);
562
563 data = VIDTCON1_HBPD(var->left_margin - 1) |
564 VIDTCON1_HFPD(var->right_margin - 1) |
565 VIDTCON1_HSPW(var->hsync_len - 1);
566
567 /* VIDTCON1 */
568 writel(data, regs + sfb->variant.vidtcon + 4);
569
570 data = VIDTCON2_LINEVAL(var->yres - 1) |
571 VIDTCON2_HOZVAL(var->xres - 1) |
572 VIDTCON2_LINEVAL_E(var->yres - 1) |
573 VIDTCON2_HOZVAL_E(var->xres - 1);
574 writel(data, regs + sfb->variant.vidtcon + 8);
575 }
576
577 /* write the buffer address */ 537 /* write the buffer address */
578 538
579 /* start and end registers stride is 8 */ 539 /* start and end registers stride is 8 */
@@ -839,6 +799,7 @@ static int s3c_fb_blank(int blank_mode, struct fb_info *info)
839 struct s3c_fb *sfb = win->parent; 799 struct s3c_fb *sfb = win->parent;
840 unsigned int index = win->index; 800 unsigned int index = win->index;
841 u32 wincon; 801 u32 wincon;
802 u32 output_on = sfb->output_on;
842 803
843 dev_dbg(sfb->dev, "blank mode %d\n", blank_mode); 804 dev_dbg(sfb->dev, "blank mode %d\n", blank_mode);
844 805
@@ -877,34 +838,18 @@ static int s3c_fb_blank(int blank_mode, struct fb_info *info)
877 838
878 shadow_protect_win(win, 1); 839 shadow_protect_win(win, 1);
879 writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4)); 840 writel(wincon, sfb->regs + sfb->variant.wincon + (index * 4));
880 shadow_protect_win(win, 0);
881 841
882 /* Check the enabled state to see if we need to be running the 842 /* Check the enabled state to see if we need to be running the
883 * main LCD interface, as if there are no active windows then 843 * main LCD interface, as if there are no active windows then
884 * it is highly likely that we also do not need to output 844 * it is highly likely that we also do not need to output
885 * anything. 845 * anything.
886 */ 846 */
887 847 s3c_fb_enable(sfb, sfb->enabled ? 1 : 0);
888 /* We could do something like the following code, but the current 848 shadow_protect_win(win, 0);
889 * system of using framebuffer events means that we cannot make
890 * the distinction between just window 0 being inactive and all
891 * the windows being down.
892 *
893 * s3c_fb_enable(sfb, sfb->enabled ? 1 : 0);
894 */
895
896 /* we're stuck with this until we can do something about overriding
897 * the power control using the blanking event for a single fb.
898 */
899 if (index == sfb->pdata->default_win) {
900 shadow_protect_win(win, 1);
901 s3c_fb_enable(sfb, blank_mode != FB_BLANK_POWERDOWN ? 1 : 0);
902 shadow_protect_win(win, 0);
903 }
904 849
905 pm_runtime_put_sync(sfb->dev); 850 pm_runtime_put_sync(sfb->dev);
906 851
907 return 0; 852 return output_on == sfb->output_on;
908} 853}
909 854
910/** 855/**
@@ -1111,7 +1056,7 @@ static struct fb_ops s3c_fb_ops = {
1111 * 1056 *
1112 * Calculate the pixel clock when none has been given through platform data. 1057 * Calculate the pixel clock when none has been given through platform data.
1113 */ 1058 */
1114static void __devinit s3c_fb_missing_pixclock(struct fb_videomode *mode) 1059static void s3c_fb_missing_pixclock(struct fb_videomode *mode)
1115{ 1060{
1116 u64 pixclk = 1000000000000ULL; 1061 u64 pixclk = 1000000000000ULL;
1117 u32 div; 1062 u32 div;
@@ -1144,11 +1089,11 @@ static int __devinit s3c_fb_alloc_memory(struct s3c_fb *sfb,
1144 1089
1145 dev_dbg(sfb->dev, "allocating memory for display\n"); 1090 dev_dbg(sfb->dev, "allocating memory for display\n");
1146 1091
1147 real_size = windata->win_mode.xres * windata->win_mode.yres; 1092 real_size = windata->xres * windata->yres;
1148 virt_size = windata->virtual_x * windata->virtual_y; 1093 virt_size = windata->virtual_x * windata->virtual_y;
1149 1094
1150 dev_dbg(sfb->dev, "real_size=%u (%u.%u), virt_size=%u (%u.%u)\n", 1095 dev_dbg(sfb->dev, "real_size=%u (%u.%u), virt_size=%u (%u.%u)\n",
1151 real_size, windata->win_mode.xres, windata->win_mode.yres, 1096 real_size, windata->xres, windata->yres,
1152 virt_size, windata->virtual_x, windata->virtual_y); 1097 virt_size, windata->virtual_x, windata->virtual_y);
1153 1098
1154 size = (real_size > virt_size) ? real_size : virt_size; 1099 size = (real_size > virt_size) ? real_size : virt_size;
@@ -1230,7 +1175,7 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
1230 struct s3c_fb_win **res) 1175 struct s3c_fb_win **res)
1231{ 1176{
1232 struct fb_var_screeninfo *var; 1177 struct fb_var_screeninfo *var;
1233 struct fb_videomode *initmode; 1178 struct fb_videomode initmode;
1234 struct s3c_fb_pd_win *windata; 1179 struct s3c_fb_pd_win *windata;
1235 struct s3c_fb_win *win; 1180 struct s3c_fb_win *win;
1236 struct fb_info *fbinfo; 1181 struct fb_info *fbinfo;
@@ -1251,11 +1196,11 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
1251 } 1196 }
1252 1197
1253 windata = sfb->pdata->win[win_no]; 1198 windata = sfb->pdata->win[win_no];
1254 initmode = &windata->win_mode; 1199 initmode = *sfb->pdata->vtiming;
1255 1200
1256 WARN_ON(windata->max_bpp == 0); 1201 WARN_ON(windata->max_bpp == 0);
1257 WARN_ON(windata->win_mode.xres == 0); 1202 WARN_ON(windata->xres == 0);
1258 WARN_ON(windata->win_mode.yres == 0); 1203 WARN_ON(windata->yres == 0);
1259 1204
1260 win = fbinfo->par; 1205 win = fbinfo->par;
1261 *res = win; 1206 *res = win;
@@ -1294,7 +1239,9 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
1294 } 1239 }
1295 1240
1296 /* setup the initial video mode from the window */ 1241 /* setup the initial video mode from the window */
1297 fb_videomode_to_var(&fbinfo->var, initmode); 1242 initmode.xres = windata->xres;
1243 initmode.yres = windata->yres;
1244 fb_videomode_to_var(&fbinfo->var, &initmode);
1298 1245
1299 fbinfo->fix.type = FB_TYPE_PACKED_PIXELS; 1246 fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
1300 fbinfo->fix.accel = FB_ACCEL_NONE; 1247 fbinfo->fix.accel = FB_ACCEL_NONE;
@@ -1339,6 +1286,53 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
1339} 1286}
1340 1287
1341/** 1288/**
1289 * s3c_fb_set_rgb_timing() - set video timing for rgb interface.
1290 * @sfb: The base resources for the hardware.
1291 *
1292 * Set horizontal and vertical lcd rgb interface timing.
1293 */
1294static void s3c_fb_set_rgb_timing(struct s3c_fb *sfb)
1295{
1296 struct fb_videomode *vmode = sfb->pdata->vtiming;
1297 void __iomem *regs = sfb->regs;
1298 int clkdiv;
1299 u32 data;
1300
1301 if (!vmode->pixclock)
1302 s3c_fb_missing_pixclock(vmode);
1303
1304 clkdiv = s3c_fb_calc_pixclk(sfb, vmode->pixclock);
1305
1306 data = sfb->pdata->vidcon0;
1307 data &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
1308
1309 if (clkdiv > 1)
1310 data |= VIDCON0_CLKVAL_F(clkdiv-1) | VIDCON0_CLKDIR;
1311 else
1312 data &= ~VIDCON0_CLKDIR; /* 1:1 clock */
1313
1314 if (sfb->variant.is_2443)
1315 data |= (1 << 5);
1316 writel(data, regs + VIDCON0);
1317
1318 data = VIDTCON0_VBPD(vmode->upper_margin - 1) |
1319 VIDTCON0_VFPD(vmode->lower_margin - 1) |
1320 VIDTCON0_VSPW(vmode->vsync_len - 1);
1321 writel(data, regs + sfb->variant.vidtcon);
1322
1323 data = VIDTCON1_HBPD(vmode->left_margin - 1) |
1324 VIDTCON1_HFPD(vmode->right_margin - 1) |
1325 VIDTCON1_HSPW(vmode->hsync_len - 1);
1326 writel(data, regs + sfb->variant.vidtcon + 4);
1327
1328 data = VIDTCON2_LINEVAL(vmode->yres - 1) |
1329 VIDTCON2_HOZVAL(vmode->xres - 1) |
1330 VIDTCON2_LINEVAL_E(vmode->yres - 1) |
1331 VIDTCON2_HOZVAL_E(vmode->xres - 1);
1332 writel(data, regs + sfb->variant.vidtcon + 8);
1333}
1334
1335/**
1342 * s3c_fb_clear_win() - clear hardware window registers. 1336 * s3c_fb_clear_win() - clear hardware window registers.
1343 * @sfb: The base resources for the hardware. 1337 * @sfb: The base resources for the hardware.
1344 * @win: The window to process. 1338 * @win: The window to process.
@@ -1481,15 +1475,14 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
1481 writel(0xffffff, regs + WKEYCON1); 1475 writel(0xffffff, regs + WKEYCON1);
1482 } 1476 }
1483 1477
1478 s3c_fb_set_rgb_timing(sfb);
1479
1484 /* we have the register setup, start allocating framebuffers */ 1480 /* we have the register setup, start allocating framebuffers */
1485 1481
1486 for (win = 0; win < fbdrv->variant.nr_windows; win++) { 1482 for (win = 0; win < fbdrv->variant.nr_windows; win++) {
1487 if (!pd->win[win]) 1483 if (!pd->win[win])
1488 continue; 1484 continue;
1489 1485
1490 if (!pd->win[win]->win_mode.pixclock)
1491 s3c_fb_missing_pixclock(&pd->win[win]->win_mode);
1492
1493 ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win], 1486 ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win],
1494 &sfb->windows[win]); 1487 &sfb->windows[win]);
1495 if (ret < 0) { 1488 if (ret < 0) {
@@ -1564,6 +1557,8 @@ static int s3c_fb_suspend(struct device *dev)
1564 struct s3c_fb_win *win; 1557 struct s3c_fb_win *win;
1565 int win_no; 1558 int win_no;
1566 1559
1560 pm_runtime_get_sync(sfb->dev);
1561
1567 for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) { 1562 for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) {
1568 win = sfb->windows[win_no]; 1563 win = sfb->windows[win_no];
1569 if (!win) 1564 if (!win)
@@ -1577,6 +1572,9 @@ static int s3c_fb_suspend(struct device *dev)
1577 clk_disable(sfb->lcd_clk); 1572 clk_disable(sfb->lcd_clk);
1578 1573
1579 clk_disable(sfb->bus_clk); 1574 clk_disable(sfb->bus_clk);
1575
1576 pm_runtime_put_sync(sfb->dev);
1577
1580 return 0; 1578 return 0;
1581} 1579}
1582 1580
@@ -1589,6 +1587,8 @@ static int s3c_fb_resume(struct device *dev)
1589 int win_no; 1587 int win_no;
1590 u32 reg; 1588 u32 reg;
1591 1589
1590 pm_runtime_get_sync(sfb->dev);
1591
1592 clk_enable(sfb->bus_clk); 1592 clk_enable(sfb->bus_clk);
1593 1593
1594 if (!sfb->variant.has_clksel) 1594 if (!sfb->variant.has_clksel)
@@ -1623,6 +1623,8 @@ static int s3c_fb_resume(struct device *dev)
1623 shadow_protect_win(win, 0); 1623 shadow_protect_win(win, 0);
1624 } 1624 }
1625 1625
1626 s3c_fb_set_rgb_timing(sfb);
1627
1626 /* restore framebuffers */ 1628 /* restore framebuffers */
1627 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) { 1629 for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
1628 win = sfb->windows[win_no]; 1630 win = sfb->windows[win_no];
@@ -1633,6 +1635,8 @@ static int s3c_fb_resume(struct device *dev)
1633 s3c_fb_set_par(win->fbinfo); 1635 s3c_fb_set_par(win->fbinfo);
1634 } 1636 }
1635 1637
1638 pm_runtime_put_sync(sfb->dev);
1639
1636 return 0; 1640 return 0;
1637} 1641}
1638#endif 1642#endif
diff --git a/drivers/video/sh_mobile_hdmi.c b/drivers/video/sh_mobile_hdmi.c
index eafb19da2c07..930e550e752a 100644
--- a/drivers/video/sh_mobile_hdmi.c
+++ b/drivers/video/sh_mobile_hdmi.c
@@ -31,6 +31,7 @@
31 31
32#include "sh_mobile_lcdcfb.h" 32#include "sh_mobile_lcdcfb.h"
33 33
34/* HDMI Core Control Register (HTOP0) */
34#define HDMI_SYSTEM_CTRL 0x00 /* System control */ 35#define HDMI_SYSTEM_CTRL 0x00 /* System control */
35#define HDMI_L_R_DATA_SWAP_CTRL_RPKT 0x01 /* L/R data swap control, 36#define HDMI_L_R_DATA_SWAP_CTRL_RPKT 0x01 /* L/R data swap control,
36 bits 19..16 of 20-bit N for Audio Clock Regeneration packet */ 37 bits 19..16 of 20-bit N for Audio Clock Regeneration packet */
@@ -201,6 +202,68 @@
201#define HDMI_REVISION_ID 0xF1 /* Revision ID */ 202#define HDMI_REVISION_ID 0xF1 /* Revision ID */
202#define HDMI_TEST_MODE 0xFE /* Test mode */ 203#define HDMI_TEST_MODE 0xFE /* Test mode */
203 204
205/* HDMI Control Register (HTOP1) */
206#define HDMI_HTOP1_TEST_MODE 0x0000 /* Test mode */
207#define HDMI_HTOP1_VIDEO_INPUT 0x0008 /* VideoInput */
208#define HDMI_HTOP1_CORE_RSTN 0x000C /* CoreResetn */
209#define HDMI_HTOP1_PLLBW 0x0018 /* PLLBW */
210#define HDMI_HTOP1_CLK_TO_PHY 0x001C /* Clk to Phy */
211#define HDMI_HTOP1_VIDEO_INPUT2 0x0020 /* VideoInput2 */
212#define HDMI_HTOP1_TISEMP0_1 0x0024 /* tisemp0-1 */
213#define HDMI_HTOP1_TISEMP2_C 0x0028 /* tisemp2-c */
214#define HDMI_HTOP1_TISIDRV 0x002C /* tisidrv */
215#define HDMI_HTOP1_TISEN 0x0034 /* tisen */
216#define HDMI_HTOP1_TISDREN 0x0038 /* tisdren */
217#define HDMI_HTOP1_CISRANGE 0x003C /* cisrange */
218#define HDMI_HTOP1_ENABLE_SELECTOR 0x0040 /* Enable Selector */
219#define HDMI_HTOP1_MACRO_RESET 0x0044 /* Macro reset */
220#define HDMI_HTOP1_PLL_CALIBRATION 0x0048 /* PLL calibration */
221#define HDMI_HTOP1_RE_CALIBRATION 0x004C /* Re-calibration */
222#define HDMI_HTOP1_CURRENT 0x0050 /* Current */
223#define HDMI_HTOP1_PLL_LOCK_DETECT 0x0054 /* PLL lock detect */
224#define HDMI_HTOP1_PHY_TEST_MODE 0x0058 /* PHY Test Mode */
225#define HDMI_HTOP1_CLK_SET 0x0080 /* Clock Set */
226#define HDMI_HTOP1_DDC_FAIL_SAFE 0x0084 /* DDC fail safe */
227#define HDMI_HTOP1_PRBS 0x0088 /* PRBS */
228#define HDMI_HTOP1_EDID_AINC_CONTROL 0x008C /* EDID ainc Control */
229#define HDMI_HTOP1_HTOP_DCL_MODE 0x00FC /* Deep Coloer Mode */
230#define HDMI_HTOP1_HTOP_DCL_FRC_COEF0 0x0100 /* Deep Color:FRC COEF0 */
231#define HDMI_HTOP1_HTOP_DCL_FRC_COEF1 0x0104 /* Deep Color:FRC COEF1 */
232#define HDMI_HTOP1_HTOP_DCL_FRC_COEF2 0x0108 /* Deep Color:FRC COEF2 */
233#define HDMI_HTOP1_HTOP_DCL_FRC_COEF3 0x010C /* Deep Color:FRC COEF3 */
234#define HDMI_HTOP1_HTOP_DCL_FRC_COEF0_C 0x0110 /* Deep Color:FRC COEF0C */
235#define HDMI_HTOP1_HTOP_DCL_FRC_COEF1_C 0x0114 /* Deep Color:FRC COEF1C */
236#define HDMI_HTOP1_HTOP_DCL_FRC_COEF2_C 0x0118 /* Deep Color:FRC COEF2C */
237#define HDMI_HTOP1_HTOP_DCL_FRC_COEF3_C 0x011C /* Deep Color:FRC COEF3C */
238#define HDMI_HTOP1_HTOP_DCL_FRC_MODE 0x0120 /* Deep Color:FRC Mode */
239#define HDMI_HTOP1_HTOP_DCL_RECT_START1 0x0124 /* Deep Color:Rect Start1 */
240#define HDMI_HTOP1_HTOP_DCL_RECT_SIZE1 0x0128 /* Deep Color:Rect Size1 */
241#define HDMI_HTOP1_HTOP_DCL_RECT_START2 0x012C /* Deep Color:Rect Start2 */
242#define HDMI_HTOP1_HTOP_DCL_RECT_SIZE2 0x0130 /* Deep Color:Rect Size2 */
243#define HDMI_HTOP1_HTOP_DCL_RECT_START3 0x0134 /* Deep Color:Rect Start3 */
244#define HDMI_HTOP1_HTOP_DCL_RECT_SIZE3 0x0138 /* Deep Color:Rect Size3 */
245#define HDMI_HTOP1_HTOP_DCL_RECT_START4 0x013C /* Deep Color:Rect Start4 */
246#define HDMI_HTOP1_HTOP_DCL_RECT_SIZE4 0x0140 /* Deep Color:Rect Size4 */
247#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y1_1 0x0144 /* Deep Color:Fil Para Y1_1 */
248#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y1_2 0x0148 /* Deep Color:Fil Para Y1_2 */
249#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB1_1 0x014C /* Deep Color:Fil Para CB1_1 */
250#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB1_2 0x0150 /* Deep Color:Fil Para CB1_2 */
251#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR1_1 0x0154 /* Deep Color:Fil Para CR1_1 */
252#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR1_2 0x0158 /* Deep Color:Fil Para CR1_2 */
253#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y2_1 0x015C /* Deep Color:Fil Para Y2_1 */
254#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y2_2 0x0160 /* Deep Color:Fil Para Y2_2 */
255#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB2_1 0x0164 /* Deep Color:Fil Para CB2_1 */
256#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB2_2 0x0168 /* Deep Color:Fil Para CB2_2 */
257#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR2_1 0x016C /* Deep Color:Fil Para CR2_1 */
258#define HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR2_2 0x0170 /* Deep Color:Fil Para CR2_2 */
259#define HDMI_HTOP1_HTOP_DCL_COR_PARA_Y1 0x0174 /* Deep Color:Cor Para Y1 */
260#define HDMI_HTOP1_HTOP_DCL_COR_PARA_CB1 0x0178 /* Deep Color:Cor Para CB1 */
261#define HDMI_HTOP1_HTOP_DCL_COR_PARA_CR1 0x017C /* Deep Color:Cor Para CR1 */
262#define HDMI_HTOP1_HTOP_DCL_COR_PARA_Y2 0x0180 /* Deep Color:Cor Para Y2 */
263#define HDMI_HTOP1_HTOP_DCL_COR_PARA_CB2 0x0184 /* Deep Color:Cor Para CB2 */
264#define HDMI_HTOP1_HTOP_DCL_COR_PARA_CR2 0x0188 /* Deep Color:Cor Para CR2 */
265#define HDMI_HTOP1_EDID_DATA_READ 0x0200 /* EDID Data Read 128Byte:0x03FC */
266
204enum hotplug_state { 267enum hotplug_state {
205 HDMI_HOTPLUG_DISCONNECTED, 268 HDMI_HOTPLUG_DISCONNECTED,
206 HDMI_HOTPLUG_CONNECTED, 269 HDMI_HOTPLUG_CONNECTED,
@@ -211,6 +274,7 @@ struct sh_hdmi {
211 struct sh_mobile_lcdc_entity entity; 274 struct sh_mobile_lcdc_entity entity;
212 275
213 void __iomem *base; 276 void __iomem *base;
277 void __iomem *htop1;
214 enum hotplug_state hp_state; /* hot-plug status */ 278 enum hotplug_state hp_state; /* hot-plug status */
215 u8 preprogrammed_vic; /* use a pre-programmed VIC or 279 u8 preprogrammed_vic; /* use a pre-programmed VIC or
216 the external mode */ 280 the external mode */
@@ -222,20 +286,66 @@ struct sh_hdmi {
222 struct delayed_work edid_work; 286 struct delayed_work edid_work;
223 struct fb_videomode mode; 287 struct fb_videomode mode;
224 struct fb_monspecs monspec; 288 struct fb_monspecs monspec;
289
290 /* register access functions */
291 void (*write)(struct sh_hdmi *hdmi, u8 data, u8 reg);
292 u8 (*read)(struct sh_hdmi *hdmi, u8 reg);
225}; 293};
226 294
227#define entity_to_sh_hdmi(e) container_of(e, struct sh_hdmi, entity) 295#define entity_to_sh_hdmi(e) container_of(e, struct sh_hdmi, entity)
228 296
229static void hdmi_write(struct sh_hdmi *hdmi, u8 data, u8 reg) 297static void __hdmi_write8(struct sh_hdmi *hdmi, u8 data, u8 reg)
230{ 298{
231 iowrite8(data, hdmi->base + reg); 299 iowrite8(data, hdmi->base + reg);
232} 300}
233 301
234static u8 hdmi_read(struct sh_hdmi *hdmi, u8 reg) 302static u8 __hdmi_read8(struct sh_hdmi *hdmi, u8 reg)
235{ 303{
236 return ioread8(hdmi->base + reg); 304 return ioread8(hdmi->base + reg);
237} 305}
238 306
307static void __hdmi_write32(struct sh_hdmi *hdmi, u8 data, u8 reg)
308{
309 iowrite32((u32)data, hdmi->base + (reg * 4));
310 udelay(100);
311}
312
313static u8 __hdmi_read32(struct sh_hdmi *hdmi, u8 reg)
314{
315 return (u8)ioread32(hdmi->base + (reg * 4));
316}
317
318static void hdmi_write(struct sh_hdmi *hdmi, u8 data, u8 reg)
319{
320 hdmi->write(hdmi, data, reg);
321}
322
323static u8 hdmi_read(struct sh_hdmi *hdmi, u8 reg)
324{
325 return hdmi->read(hdmi, reg);
326}
327
328static void hdmi_bit_set(struct sh_hdmi *hdmi, u8 mask, u8 data, u8 reg)
329{
330 u8 val = hdmi_read(hdmi, reg);
331
332 val &= ~mask;
333 val |= (data & mask);
334
335 hdmi_write(hdmi, val, reg);
336}
337
338static void hdmi_htop1_write(struct sh_hdmi *hdmi, u32 data, u32 reg)
339{
340 iowrite32(data, hdmi->htop1 + reg);
341 udelay(100);
342}
343
344static u32 hdmi_htop1_read(struct sh_hdmi *hdmi, u32 reg)
345{
346 return ioread32(hdmi->htop1 + reg);
347}
348
239/* 349/*
240 * HDMI sound 350 * HDMI sound
241 */ 351 */
@@ -693,11 +803,11 @@ static void sh_hdmi_configure(struct sh_hdmi *hdmi)
693 msleep(10); 803 msleep(10);
694 804
695 /* PS mode b->d, reset PLLA and PLLB */ 805 /* PS mode b->d, reset PLLA and PLLB */
696 hdmi_write(hdmi, 0x4C, HDMI_SYSTEM_CTRL); 806 hdmi_bit_set(hdmi, 0xFC, 0x4C, HDMI_SYSTEM_CTRL);
697 807
698 udelay(10); 808 udelay(10);
699 809
700 hdmi_write(hdmi, 0x40, HDMI_SYSTEM_CTRL); 810 hdmi_bit_set(hdmi, 0xFC, 0x40, HDMI_SYSTEM_CTRL);
701} 811}
702 812
703static unsigned long sh_hdmi_rate_error(struct sh_hdmi *hdmi, 813static unsigned long sh_hdmi_rate_error(struct sh_hdmi *hdmi,
@@ -746,7 +856,9 @@ static int sh_hdmi_read_edid(struct sh_hdmi *hdmi, unsigned long *hdmi_rate,
746 /* Read EDID */ 856 /* Read EDID */
747 dev_dbg(hdmi->dev, "Read back EDID code:"); 857 dev_dbg(hdmi->dev, "Read back EDID code:");
748 for (i = 0; i < 128; i++) { 858 for (i = 0; i < 128; i++) {
749 edid[i] = hdmi_read(hdmi, HDMI_EDID_KSV_FIFO_ACCESS_WINDOW); 859 edid[i] = (hdmi->htop1) ?
860 (u8)hdmi_htop1_read(hdmi, HDMI_HTOP1_EDID_DATA_READ + (i * 4)) :
861 hdmi_read(hdmi, HDMI_EDID_KSV_FIFO_ACCESS_WINDOW);
750#ifdef DEBUG 862#ifdef DEBUG
751 if ((i % 16) == 0) { 863 if ((i % 16) == 0) {
752 printk(KERN_CONT "\n"); 864 printk(KERN_CONT "\n");
@@ -917,13 +1029,13 @@ static irqreturn_t sh_hdmi_hotplug(int irq, void *dev_id)
917 u8 status1, status2, mask1, mask2; 1029 u8 status1, status2, mask1, mask2;
918 1030
919 /* mode_b and PLLA and PLLB reset */ 1031 /* mode_b and PLLA and PLLB reset */
920 hdmi_write(hdmi, 0x2C, HDMI_SYSTEM_CTRL); 1032 hdmi_bit_set(hdmi, 0xFC, 0x2C, HDMI_SYSTEM_CTRL);
921 1033
922 /* How long shall reset be held? */ 1034 /* How long shall reset be held? */
923 udelay(10); 1035 udelay(10);
924 1036
925 /* mode_b and PLLA and PLLB reset release */ 1037 /* mode_b and PLLA and PLLB reset release */
926 hdmi_write(hdmi, 0x20, HDMI_SYSTEM_CTRL); 1038 hdmi_bit_set(hdmi, 0xFC, 0x20, HDMI_SYSTEM_CTRL);
927 1039
928 status1 = hdmi_read(hdmi, HDMI_INTERRUPT_STATUS_1); 1040 status1 = hdmi_read(hdmi, HDMI_INTERRUPT_STATUS_1);
929 status2 = hdmi_read(hdmi, HDMI_INTERRUPT_STATUS_2); 1041 status2 = hdmi_read(hdmi, HDMI_INTERRUPT_STATUS_2);
@@ -1001,7 +1113,7 @@ static int sh_hdmi_display_on(struct sh_mobile_lcdc_entity *entity)
1001 */ 1113 */
1002 if (hdmi->hp_state == HDMI_HOTPLUG_EDID_DONE) { 1114 if (hdmi->hp_state == HDMI_HOTPLUG_EDID_DONE) {
1003 /* PS mode d->e. All functions are active */ 1115 /* PS mode d->e. All functions are active */
1004 hdmi_write(hdmi, 0x80, HDMI_SYSTEM_CTRL); 1116 hdmi_bit_set(hdmi, 0xFC, 0x80, HDMI_SYSTEM_CTRL);
1005 dev_dbg(hdmi->dev, "HDMI running\n"); 1117 dev_dbg(hdmi->dev, "HDMI running\n");
1006 } 1118 }
1007 1119
@@ -1016,7 +1128,7 @@ static void sh_hdmi_display_off(struct sh_mobile_lcdc_entity *entity)
1016 1128
1017 dev_dbg(hdmi->dev, "%s(%p)\n", __func__, hdmi); 1129 dev_dbg(hdmi->dev, "%s(%p)\n", __func__, hdmi);
1018 /* PS mode e->a */ 1130 /* PS mode e->a */
1019 hdmi_write(hdmi, 0x10, HDMI_SYSTEM_CTRL); 1131 hdmi_bit_set(hdmi, 0xFC, 0x10, HDMI_SYSTEM_CTRL);
1020} 1132}
1021 1133
1022static const struct sh_mobile_lcdc_entity_ops sh_hdmi_ops = { 1134static const struct sh_mobile_lcdc_entity_ops sh_hdmi_ops = {
@@ -1110,10 +1222,58 @@ out:
1110 dev_dbg(hdmi->dev, "%s(%p): end\n", __func__, hdmi); 1222 dev_dbg(hdmi->dev, "%s(%p): end\n", __func__, hdmi);
1111} 1223}
1112 1224
1225static void sh_hdmi_htop1_init(struct sh_hdmi *hdmi)
1226{
1227 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_MODE);
1228 hdmi_htop1_write(hdmi, 0x0000000b, 0x0010);
1229 hdmi_htop1_write(hdmi, 0x00006710, HDMI_HTOP1_HTOP_DCL_FRC_MODE);
1230 hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y1_1);
1231 hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y1_2);
1232 hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB1_1);
1233 hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB1_2);
1234 hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR1_1);
1235 hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR1_2);
1236 hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y2_1);
1237 hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_Y2_2);
1238 hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB2_1);
1239 hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CB2_2);
1240 hdmi_htop1_write(hdmi, 0x01020406, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR2_1);
1241 hdmi_htop1_write(hdmi, 0x07080806, HDMI_HTOP1_HTOP_DCL_FIL_PARA_CR2_2);
1242 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_Y1);
1243 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_CB1);
1244 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_CR1);
1245 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_Y2);
1246 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_CB2);
1247 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_HTOP_DCL_COR_PARA_CR2);
1248 hdmi_htop1_write(hdmi, 0x00000008, HDMI_HTOP1_CURRENT);
1249 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_TISEMP0_1);
1250 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_TISEMP2_C);
1251 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_PHY_TEST_MODE);
1252 hdmi_htop1_write(hdmi, 0x00000081, HDMI_HTOP1_TISIDRV);
1253 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_PLLBW);
1254 hdmi_htop1_write(hdmi, 0x0000000f, HDMI_HTOP1_TISEN);
1255 hdmi_htop1_write(hdmi, 0x0000000f, HDMI_HTOP1_TISDREN);
1256 hdmi_htop1_write(hdmi, 0x00000003, HDMI_HTOP1_ENABLE_SELECTOR);
1257 hdmi_htop1_write(hdmi, 0x00000001, HDMI_HTOP1_MACRO_RESET);
1258 hdmi_htop1_write(hdmi, 0x00000016, HDMI_HTOP1_CISRANGE);
1259 msleep(100);
1260 hdmi_htop1_write(hdmi, 0x00000001, HDMI_HTOP1_ENABLE_SELECTOR);
1261 msleep(100);
1262 hdmi_htop1_write(hdmi, 0x00000003, HDMI_HTOP1_ENABLE_SELECTOR);
1263 hdmi_htop1_write(hdmi, 0x00000001, HDMI_HTOP1_MACRO_RESET);
1264 hdmi_htop1_write(hdmi, 0x0000000f, HDMI_HTOP1_TISEN);
1265 hdmi_htop1_write(hdmi, 0x0000000f, HDMI_HTOP1_TISDREN);
1266 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_VIDEO_INPUT);
1267 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_CLK_TO_PHY);
1268 hdmi_htop1_write(hdmi, 0x00000000, HDMI_HTOP1_VIDEO_INPUT2);
1269 hdmi_htop1_write(hdmi, 0x0000000a, HDMI_HTOP1_CLK_SET);
1270}
1271
1113static int __init sh_hdmi_probe(struct platform_device *pdev) 1272static int __init sh_hdmi_probe(struct platform_device *pdev)
1114{ 1273{
1115 struct sh_mobile_hdmi_info *pdata = pdev->dev.platform_data; 1274 struct sh_mobile_hdmi_info *pdata = pdev->dev.platform_data;
1116 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1275 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1276 struct resource *htop1_res;
1117 int irq = platform_get_irq(pdev, 0), ret; 1277 int irq = platform_get_irq(pdev, 0), ret;
1118 struct sh_hdmi *hdmi; 1278 struct sh_hdmi *hdmi;
1119 long rate; 1279 long rate;
@@ -1121,6 +1281,15 @@ static int __init sh_hdmi_probe(struct platform_device *pdev)
1121 if (!res || !pdata || irq < 0) 1281 if (!res || !pdata || irq < 0)
1122 return -ENODEV; 1282 return -ENODEV;
1123 1283
1284 htop1_res = NULL;
1285 if (pdata->flags & HDMI_HAS_HTOP1) {
1286 htop1_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1287 if (!htop1_res) {
1288 dev_err(&pdev->dev, "htop1 needs register base\n");
1289 return -EINVAL;
1290 }
1291 }
1292
1124 hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL); 1293 hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL);
1125 if (!hdmi) { 1294 if (!hdmi) {
1126 dev_err(&pdev->dev, "Cannot allocate device data\n"); 1295 dev_err(&pdev->dev, "Cannot allocate device data\n");
@@ -1138,6 +1307,15 @@ static int __init sh_hdmi_probe(struct platform_device *pdev)
1138 goto egetclk; 1307 goto egetclk;
1139 } 1308 }
1140 1309
1310 /* select register access functions */
1311 if (pdata->flags & HDMI_32BIT_REG) {
1312 hdmi->write = __hdmi_write32;
1313 hdmi->read = __hdmi_read32;
1314 } else {
1315 hdmi->write = __hdmi_write8;
1316 hdmi->read = __hdmi_read8;
1317 }
1318
1141 /* An arbitrary relaxed pixclock just to get things started: from standard 480p */ 1319 /* An arbitrary relaxed pixclock just to get things started: from standard 480p */
1142 rate = clk_round_rate(hdmi->hdmi_clk, PICOS2KHZ(37037)); 1320 rate = clk_round_rate(hdmi->hdmi_clk, PICOS2KHZ(37037));
1143 if (rate > 0) 1321 if (rate > 0)
@@ -1176,6 +1354,24 @@ static int __init sh_hdmi_probe(struct platform_device *pdev)
1176 pm_runtime_enable(&pdev->dev); 1354 pm_runtime_enable(&pdev->dev);
1177 pm_runtime_get_sync(&pdev->dev); 1355 pm_runtime_get_sync(&pdev->dev);
1178 1356
1357 /* init interrupt polarity */
1358 if (pdata->flags & HDMI_OUTPUT_PUSH_PULL)
1359 hdmi_bit_set(hdmi, 0x02, 0x02, HDMI_SYSTEM_CTRL);
1360
1361 if (pdata->flags & HDMI_OUTPUT_POLARITY_HI)
1362 hdmi_bit_set(hdmi, 0x01, 0x01, HDMI_SYSTEM_CTRL);
1363
1364 /* enable htop1 register if needed */
1365 if (htop1_res) {
1366 hdmi->htop1 = ioremap(htop1_res->start, resource_size(htop1_res));
1367 if (!hdmi->htop1) {
1368 dev_err(&pdev->dev, "control register region already claimed\n");
1369 ret = -ENOMEM;
1370 goto emap_htop1;
1371 }
1372 sh_hdmi_htop1_init(hdmi);
1373 }
1374
1179 /* Product and revision IDs are 0 in sh-mobile version */ 1375 /* Product and revision IDs are 0 in sh-mobile version */
1180 dev_info(&pdev->dev, "Detected HDMI controller 0x%x:0x%x\n", 1376 dev_info(&pdev->dev, "Detected HDMI controller 0x%x:0x%x\n",
1181 hdmi_read(hdmi, HDMI_PRODUCT_ID), hdmi_read(hdmi, HDMI_REVISION_ID)); 1377 hdmi_read(hdmi, HDMI_PRODUCT_ID), hdmi_read(hdmi, HDMI_REVISION_ID));
@@ -1199,6 +1395,9 @@ static int __init sh_hdmi_probe(struct platform_device *pdev)
1199ecodec: 1395ecodec:
1200 free_irq(irq, hdmi); 1396 free_irq(irq, hdmi);
1201ereqirq: 1397ereqirq:
1398 if (hdmi->htop1)
1399 iounmap(hdmi->htop1);
1400emap_htop1:
1202 pm_runtime_put(&pdev->dev); 1401 pm_runtime_put(&pdev->dev);
1203 pm_runtime_disable(&pdev->dev); 1402 pm_runtime_disable(&pdev->dev);
1204 iounmap(hdmi->base); 1403 iounmap(hdmi->base);
@@ -1230,6 +1429,8 @@ static int __exit sh_hdmi_remove(struct platform_device *pdev)
1230 pm_runtime_disable(&pdev->dev); 1429 pm_runtime_disable(&pdev->dev);
1231 clk_disable(hdmi->hdmi_clk); 1430 clk_disable(hdmi->hdmi_clk);
1232 clk_put(hdmi->hdmi_clk); 1431 clk_put(hdmi->hdmi_clk);
1432 if (hdmi->htop1)
1433 iounmap(hdmi->htop1);
1233 iounmap(hdmi->base); 1434 iounmap(hdmi->base);
1234 release_mem_region(res->start, resource_size(res)); 1435 release_mem_region(res->start, resource_size(res));
1235 kfree(hdmi); 1436 kfree(hdmi);
diff --git a/drivers/video/sis/init.h b/drivers/video/sis/init.h
index aff73842d877..85d6738b6c64 100644
--- a/drivers/video/sis/init.h
+++ b/drivers/video/sis/init.h
@@ -105,51 +105,6 @@ static const unsigned short ModeIndex_1920x1440[] = {0x68, 0x69, 0x00, 0x6b};
105static const unsigned short ModeIndex_300_2048x1536[]= {0x6c, 0x6d, 0x00, 0x00}; 105static const unsigned short ModeIndex_300_2048x1536[]= {0x6c, 0x6d, 0x00, 0x00};
106static const unsigned short ModeIndex_310_2048x1536[]= {0x6c, 0x6d, 0x00, 0x6e}; 106static const unsigned short ModeIndex_310_2048x1536[]= {0x6c, 0x6d, 0x00, 0x6e};
107 107
108static const unsigned short SiS_DRAMType[17][5]={
109 {0x0C,0x0A,0x02,0x40,0x39},
110 {0x0D,0x0A,0x01,0x40,0x48},
111 {0x0C,0x09,0x02,0x20,0x35},
112 {0x0D,0x09,0x01,0x20,0x44},
113 {0x0C,0x08,0x02,0x10,0x31},
114 {0x0D,0x08,0x01,0x10,0x40},
115 {0x0C,0x0A,0x01,0x20,0x34},
116 {0x0C,0x09,0x01,0x08,0x32},
117 {0x0B,0x08,0x02,0x08,0x21},
118 {0x0C,0x08,0x01,0x08,0x30},
119 {0x0A,0x08,0x02,0x04,0x11},
120 {0x0B,0x0A,0x01,0x10,0x28},
121 {0x09,0x08,0x02,0x02,0x01},
122 {0x0B,0x09,0x01,0x08,0x24},
123 {0x0B,0x08,0x01,0x04,0x20},
124 {0x0A,0x08,0x01,0x02,0x10},
125 {0x09,0x08,0x01,0x01,0x00}
126};
127
128static const unsigned short SiS_SDRDRAM_TYPE[13][5] =
129{
130 { 2,12, 9,64,0x35},
131 { 1,13, 9,64,0x44},
132 { 2,12, 8,32,0x31},
133 { 2,11, 9,32,0x25},
134 { 1,12, 9,32,0x34},
135 { 1,13, 8,32,0x40},
136 { 2,11, 8,16,0x21},
137 { 1,12, 8,16,0x30},
138 { 1,11, 9,16,0x24},
139 { 1,11, 8, 8,0x20},
140 { 2, 9, 8, 4,0x01},
141 { 1,10, 8, 4,0x10},
142 { 1, 9, 8, 2,0x00}
143};
144
145static const unsigned short SiS_DDRDRAM_TYPE[4][5] =
146{
147 { 2,12, 9,64,0x35},
148 { 2,12, 8,32,0x31},
149 { 2,11, 8,16,0x21},
150 { 2, 9, 8, 4,0x01}
151};
152
153static const unsigned char SiS_MDA_DAC[] = 108static const unsigned char SiS_MDA_DAC[] =
154{ 109{
155 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 110 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index 078ca2167d6f..a7a48db64ce2 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -4222,6 +4222,26 @@ sisfb_post_300_buswidth(struct sis_video_info *ivideo)
4222 return 1; /* 32bit */ 4222 return 1; /* 32bit */
4223} 4223}
4224 4224
4225static const unsigned short __devinitconst SiS_DRAMType[17][5] = {
4226 {0x0C,0x0A,0x02,0x40,0x39},
4227 {0x0D,0x0A,0x01,0x40,0x48},
4228 {0x0C,0x09,0x02,0x20,0x35},
4229 {0x0D,0x09,0x01,0x20,0x44},
4230 {0x0C,0x08,0x02,0x10,0x31},
4231 {0x0D,0x08,0x01,0x10,0x40},
4232 {0x0C,0x0A,0x01,0x20,0x34},
4233 {0x0C,0x09,0x01,0x08,0x32},
4234 {0x0B,0x08,0x02,0x08,0x21},
4235 {0x0C,0x08,0x01,0x08,0x30},
4236 {0x0A,0x08,0x02,0x04,0x11},
4237 {0x0B,0x0A,0x01,0x10,0x28},
4238 {0x09,0x08,0x02,0x02,0x01},
4239 {0x0B,0x09,0x01,0x08,0x24},
4240 {0x0B,0x08,0x01,0x04,0x20},
4241 {0x0A,0x08,0x01,0x02,0x10},
4242 {0x09,0x08,0x01,0x01,0x00}
4243};
4244
4225static int __devinit 4245static int __devinit
4226sisfb_post_300_rwtest(struct sis_video_info *ivideo, int iteration, int buswidth, 4246sisfb_post_300_rwtest(struct sis_video_info *ivideo, int iteration, int buswidth,
4227 int PseudoRankCapacity, int PseudoAdrPinCount, 4247 int PseudoRankCapacity, int PseudoAdrPinCount,
@@ -4231,27 +4251,8 @@ sisfb_post_300_rwtest(struct sis_video_info *ivideo, int iteration, int buswidth
4231 unsigned short sr14; 4251 unsigned short sr14;
4232 unsigned int k, RankCapacity, PageCapacity, BankNumHigh, BankNumMid; 4252 unsigned int k, RankCapacity, PageCapacity, BankNumHigh, BankNumMid;
4233 unsigned int PhysicalAdrOtherPage, PhysicalAdrHigh, PhysicalAdrHalfPage; 4253 unsigned int PhysicalAdrOtherPage, PhysicalAdrHigh, PhysicalAdrHalfPage;
4234 static const unsigned short SiS_DRAMType[17][5] = {
4235 {0x0C,0x0A,0x02,0x40,0x39},
4236 {0x0D,0x0A,0x01,0x40,0x48},
4237 {0x0C,0x09,0x02,0x20,0x35},
4238 {0x0D,0x09,0x01,0x20,0x44},
4239 {0x0C,0x08,0x02,0x10,0x31},
4240 {0x0D,0x08,0x01,0x10,0x40},
4241 {0x0C,0x0A,0x01,0x20,0x34},
4242 {0x0C,0x09,0x01,0x08,0x32},
4243 {0x0B,0x08,0x02,0x08,0x21},
4244 {0x0C,0x08,0x01,0x08,0x30},
4245 {0x0A,0x08,0x02,0x04,0x11},
4246 {0x0B,0x0A,0x01,0x10,0x28},
4247 {0x09,0x08,0x02,0x02,0x01},
4248 {0x0B,0x09,0x01,0x08,0x24},
4249 {0x0B,0x08,0x01,0x04,0x20},
4250 {0x0A,0x08,0x01,0x02,0x10},
4251 {0x09,0x08,0x01,0x01,0x00}
4252 };
4253 4254
4254 for(k = 0; k <= 16; k++) { 4255 for(k = 0; k < ARRAY_SIZE(SiS_DRAMType); k++) {
4255 4256
4256 RankCapacity = buswidth * SiS_DRAMType[k][3]; 4257 RankCapacity = buswidth * SiS_DRAMType[k][3];
4257 4258
diff --git a/drivers/video/skeletonfb.c b/drivers/video/skeletonfb.c
index 30f7a815a62b..5b6abc6de84b 100644
--- a/drivers/video/skeletonfb.c
+++ b/drivers/video/skeletonfb.c
@@ -1036,6 +1036,6 @@ static void __exit xxxfb_exit(void)
1036 */ 1036 */
1037 1037
1038module_init(xxxfb_init); 1038module_init(xxxfb_init);
1039module_exit(xxxfb_remove); 1039module_exit(xxxfb_exit);
1040 1040
1041MODULE_LICENSE("GPL"); 1041MODULE_LICENSE("GPL");
diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
index ccbfef5e828f..af3ef27ad36c 100644
--- a/drivers/video/smscufx.c
+++ b/drivers/video/smscufx.c
@@ -846,7 +846,7 @@ static void ufx_raw_rect(struct ufx_data *dev, u16 *cmd, int x, int y,
846 } 846 }
847} 847}
848 848
849int ufx_handle_damage(struct ufx_data *dev, int x, int y, 849static int ufx_handle_damage(struct ufx_data *dev, int x, int y,
850 int width, int height) 850 int width, int height)
851{ 851{
852 size_t packed_line_len = ALIGN((width * 2), 4); 852 size_t packed_line_len = ALIGN((width * 2), 4);
@@ -1083,7 +1083,7 @@ static int ufx_ops_open(struct fb_info *info, int user)
1083 1083
1084 struct fb_deferred_io *fbdefio; 1084 struct fb_deferred_io *fbdefio;
1085 1085
1086 fbdefio = kmalloc(sizeof(struct fb_deferred_io), GFP_KERNEL); 1086 fbdefio = kzalloc(sizeof(struct fb_deferred_io), GFP_KERNEL);
1087 1087
1088 if (fbdefio) { 1088 if (fbdefio) {
1089 fbdefio->delay = UFX_DEFIO_WRITE_DELAY; 1089 fbdefio->delay = UFX_DEFIO_WRITE_DELAY;
diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
index 7af1e8166182..8af64148294b 100644
--- a/drivers/video/udlfb.c
+++ b/drivers/video/udlfb.c
@@ -893,7 +893,7 @@ static int dlfb_ops_open(struct fb_info *info, int user)
893 893
894 struct fb_deferred_io *fbdefio; 894 struct fb_deferred_io *fbdefio;
895 895
896 fbdefio = kmalloc(sizeof(struct fb_deferred_io), GFP_KERNEL); 896 fbdefio = kzalloc(sizeof(struct fb_deferred_io), GFP_KERNEL);
897 897
898 if (fbdefio) { 898 if (fbdefio) {
899 fbdefio->delay = DL_DEFIO_WRITE_DELAY; 899 fbdefio->delay = DL_DEFIO_WRITE_DELAY;
diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c
index 0c8837565bc7..c80e770e1800 100644
--- a/drivers/video/via/viafbdev.c
+++ b/drivers/video/via/viafbdev.c
@@ -1276,17 +1276,12 @@ static int viafb_dfph_proc_open(struct inode *inode, struct file *file)
1276static ssize_t viafb_dfph_proc_write(struct file *file, 1276static ssize_t viafb_dfph_proc_write(struct file *file,
1277 const char __user *buffer, size_t count, loff_t *pos) 1277 const char __user *buffer, size_t count, loff_t *pos)
1278{ 1278{
1279 char buf[20]; 1279 int err;
1280 u8 reg_val = 0; 1280 u8 reg_val;
1281 unsigned long length; 1281 err = kstrtou8_from_user(buffer, count, 0, &reg_val);
1282 if (count < 1) 1282 if (err)
1283 return -EINVAL; 1283 return err;
1284 length = count > 20 ? 20 : count; 1284
1285 if (copy_from_user(&buf[0], buffer, length))
1286 return -EFAULT;
1287 buf[length - 1] = '\0'; /*Ensure end string */
1288 if (kstrtou8(buf, 0, &reg_val) < 0)
1289 return -EINVAL;
1290 viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f); 1285 viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
1291 return count; 1286 return count;
1292} 1287}
@@ -1316,17 +1311,12 @@ static int viafb_dfpl_proc_open(struct inode *inode, struct file *file)
1316static ssize_t viafb_dfpl_proc_write(struct file *file, 1311static ssize_t viafb_dfpl_proc_write(struct file *file,
1317 const char __user *buffer, size_t count, loff_t *pos) 1312 const char __user *buffer, size_t count, loff_t *pos)
1318{ 1313{
1319 char buf[20]; 1314 int err;
1320 u8 reg_val = 0; 1315 u8 reg_val;
1321 unsigned long length; 1316 err = kstrtou8_from_user(buffer, count, 0, &reg_val);
1322 if (count < 1) 1317 if (err)
1323 return -EINVAL; 1318 return err;
1324 length = count > 20 ? 20 : count; 1319
1325 if (copy_from_user(&buf[0], buffer, length))
1326 return -EFAULT;
1327 buf[length - 1] = '\0'; /*Ensure end string */
1328 if (kstrtou8(buf, 0, &reg_val) < 0)
1329 return -EINVAL;
1330 viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f); 1320 viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
1331 return count; 1321 return count;
1332} 1322}
diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c
index a1e6c990cd41..e3dd2a1e2bfc 100644
--- a/fs/9p/vfs_inode_dotl.c
+++ b/fs/9p/vfs_inode_dotl.c
@@ -68,24 +68,6 @@ static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
68 return current_fsgid(); 68 return current_fsgid();
69} 69}
70 70
71/**
72 * v9fs_dentry_from_dir_inode - helper function to get the dentry from
73 * dir inode.
74 *
75 */
76
77static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
78{
79 struct dentry *dentry;
80
81 spin_lock(&inode->i_lock);
82 /* Directory should have only one entry. */
83 BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry));
84 dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
85 spin_unlock(&inode->i_lock);
86 return dentry;
87}
88
89static int v9fs_test_inode_dotl(struct inode *inode, void *data) 71static int v9fs_test_inode_dotl(struct inode *inode, void *data)
90{ 72{
91 struct v9fs_inode *v9inode = V9FS_I(inode); 73 struct v9fs_inode *v9inode = V9FS_I(inode);
@@ -415,7 +397,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,
415 if (dir->i_mode & S_ISGID) 397 if (dir->i_mode & S_ISGID)
416 omode |= S_ISGID; 398 omode |= S_ISGID;
417 399
418 dir_dentry = v9fs_dentry_from_dir_inode(dir); 400 dir_dentry = dentry->d_parent;
419 dfid = v9fs_fid_lookup(dir_dentry); 401 dfid = v9fs_fid_lookup(dir_dentry);
420 if (IS_ERR(dfid)) { 402 if (IS_ERR(dfid)) {
421 err = PTR_ERR(dfid); 403 err = PTR_ERR(dfid);
@@ -793,7 +775,7 @@ v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
793 dir->i_ino, old_dentry->d_name.name, dentry->d_name.name); 775 dir->i_ino, old_dentry->d_name.name, dentry->d_name.name);
794 776
795 v9ses = v9fs_inode2v9ses(dir); 777 v9ses = v9fs_inode2v9ses(dir);
796 dir_dentry = v9fs_dentry_from_dir_inode(dir); 778 dir_dentry = dentry->d_parent;
797 dfid = v9fs_fid_lookup(dir_dentry); 779 dfid = v9fs_fid_lookup(dir_dentry);
798 if (IS_ERR(dfid)) 780 if (IS_ERR(dfid))
799 return PTR_ERR(dfid); 781 return PTR_ERR(dfid);
@@ -858,7 +840,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
858 return -EINVAL; 840 return -EINVAL;
859 841
860 v9ses = v9fs_inode2v9ses(dir); 842 v9ses = v9fs_inode2v9ses(dir);
861 dir_dentry = v9fs_dentry_from_dir_inode(dir); 843 dir_dentry = dentry->d_parent;
862 dfid = v9fs_fid_lookup(dir_dentry); 844 dfid = v9fs_fid_lookup(dir_dentry);
863 if (IS_ERR(dfid)) { 845 if (IS_ERR(dfid)) {
864 err = PTR_ERR(dfid); 846 err = PTR_ERR(dfid);
diff --git a/fs/affs/affs.h b/fs/affs/affs.h
index 45a0ce45d7b4..1fceb320d2f2 100644
--- a/fs/affs/affs.h
+++ b/fs/affs/affs.h
@@ -18,14 +18,6 @@
18#define AFFS_GET_HASHENTRY(data,hashkey) be32_to_cpu(((struct dir_front *)data)->hashtable[hashkey]) 18#define AFFS_GET_HASHENTRY(data,hashkey) be32_to_cpu(((struct dir_front *)data)->hashtable[hashkey])
19#define AFFS_BLOCK(sb, bh, blk) (AFFS_HEAD(bh)->table[AFFS_SB(sb)->s_hashsize-1-(blk)]) 19#define AFFS_BLOCK(sb, bh, blk) (AFFS_HEAD(bh)->table[AFFS_SB(sb)->s_hashsize-1-(blk)])
20 20
21#ifdef __LITTLE_ENDIAN
22#define BO_EXBITS 0x18UL
23#elif defined(__BIG_ENDIAN)
24#define BO_EXBITS 0x00UL
25#else
26#error Endianness must be known for affs to work.
27#endif
28
29#define AFFS_HEAD(bh) ((struct affs_head *)(bh)->b_data) 21#define AFFS_HEAD(bh) ((struct affs_head *)(bh)->b_data)
30#define AFFS_TAIL(sb, bh) ((struct affs_tail *)((bh)->b_data+(sb)->s_blocksize-sizeof(struct affs_tail))) 22#define AFFS_TAIL(sb, bh) ((struct affs_tail *)((bh)->b_data+(sb)->s_blocksize-sizeof(struct affs_tail)))
31#define AFFS_ROOT_HEAD(bh) ((struct affs_root_head *)(bh)->b_data) 23#define AFFS_ROOT_HEAD(bh) ((struct affs_root_head *)(bh)->b_data)
diff --git a/fs/aio.c b/fs/aio.c
index e7f2fad7b4ce..55c4c7656053 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -134,9 +134,9 @@ static int aio_setup_ring(struct kioctx *ctx)
134 info->mmap_size = nr_pages * PAGE_SIZE; 134 info->mmap_size = nr_pages * PAGE_SIZE;
135 dprintk("attempting mmap of %lu bytes\n", info->mmap_size); 135 dprintk("attempting mmap of %lu bytes\n", info->mmap_size);
136 down_write(&ctx->mm->mmap_sem); 136 down_write(&ctx->mm->mmap_sem);
137 info->mmap_base = do_mmap(NULL, 0, info->mmap_size, 137 info->mmap_base = do_mmap_pgoff(NULL, 0, info->mmap_size,
138 PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, 138 PROT_READ|PROT_WRITE,
139 0); 139 MAP_ANONYMOUS|MAP_PRIVATE, 0);
140 if (IS_ERR((void *)info->mmap_base)) { 140 if (IS_ERR((void *)info->mmap_base)) {
141 up_write(&ctx->mm->mmap_sem); 141 up_write(&ctx->mm->mmap_sem);
142 info->mmap_size = 0; 142 info->mmap_size = 0;
@@ -1446,13 +1446,13 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
1446 ret = compat_rw_copy_check_uvector(type, 1446 ret = compat_rw_copy_check_uvector(type,
1447 (struct compat_iovec __user *)kiocb->ki_buf, 1447 (struct compat_iovec __user *)kiocb->ki_buf,
1448 kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec, 1448 kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
1449 &kiocb->ki_iovec, 1); 1449 &kiocb->ki_iovec);
1450 else 1450 else
1451#endif 1451#endif
1452 ret = rw_copy_check_uvector(type, 1452 ret = rw_copy_check_uvector(type,
1453 (struct iovec __user *)kiocb->ki_buf, 1453 (struct iovec __user *)kiocb->ki_buf,
1454 kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec, 1454 kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
1455 &kiocb->ki_iovec, 1); 1455 &kiocb->ki_iovec);
1456 if (ret < 0) 1456 if (ret < 0)
1457 goto out; 1457 goto out;
1458 1458
diff --git a/fs/attr.c b/fs/attr.c
index 584620e5dee5..0da90951d277 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -176,6 +176,11 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
176 return -EPERM; 176 return -EPERM;
177 } 177 }
178 178
179 if ((ia_valid & ATTR_SIZE) && IS_I_VERSION(inode)) {
180 if (attr->ia_size != inode->i_size)
181 inode_inc_iversion(inode);
182 }
183
179 if ((ia_valid & ATTR_MODE)) { 184 if ((ia_valid & ATTR_MODE)) {
180 umode_t amode = attr->ia_mode; 185 umode_t amode = attr->ia_mode;
181 /* Flag setting protected by i_mutex */ 186 /* Flag setting protected by i_mutex */
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index e658dd134b95..1b52956afe33 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -329,7 +329,6 @@ static unsigned long elf_map(struct file *filep, unsigned long addr,
329 if (!size) 329 if (!size)
330 return addr; 330 return addr;
331 331
332 down_write(&current->mm->mmap_sem);
333 /* 332 /*
334 * total_size is the size of the ELF (interpreter) image. 333 * total_size is the size of the ELF (interpreter) image.
335 * The _first_ mmap needs to know the full size, otherwise 334 * The _first_ mmap needs to know the full size, otherwise
@@ -340,13 +339,12 @@ static unsigned long elf_map(struct file *filep, unsigned long addr,
340 */ 339 */
341 if (total_size) { 340 if (total_size) {
342 total_size = ELF_PAGEALIGN(total_size); 341 total_size = ELF_PAGEALIGN(total_size);
343 map_addr = do_mmap(filep, addr, total_size, prot, type, off); 342 map_addr = vm_mmap(filep, addr, total_size, prot, type, off);
344 if (!BAD_ADDR(map_addr)) 343 if (!BAD_ADDR(map_addr))
345 do_munmap(current->mm, map_addr+size, total_size-size); 344 vm_munmap(map_addr+size, total_size-size);
346 } else 345 } else
347 map_addr = do_mmap(filep, addr, size, prot, type, off); 346 map_addr = vm_mmap(filep, addr, size, prot, type, off);
348 347
349 up_write(&current->mm->mmap_sem);
350 return(map_addr); 348 return(map_addr);
351} 349}
352 350
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index 6b2daf99fab8..178cb70acc26 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -562,7 +562,7 @@ static int load_flat_file(struct linux_binprm * bprm,
562 realdatastart = (unsigned long) -ENOMEM; 562 realdatastart = (unsigned long) -ENOMEM;
563 printk("Unable to allocate RAM for process data, errno %d\n", 563 printk("Unable to allocate RAM for process data, errno %d\n",
564 (int)-realdatastart); 564 (int)-realdatastart);
565 do_munmap(current->mm, textpos, text_len); 565 vm_munmap(textpos, text_len);
566 ret = realdatastart; 566 ret = realdatastart;
567 goto err; 567 goto err;
568 } 568 }
@@ -586,8 +586,8 @@ static int load_flat_file(struct linux_binprm * bprm,
586 } 586 }
587 if (IS_ERR_VALUE(result)) { 587 if (IS_ERR_VALUE(result)) {
588 printk("Unable to read data+bss, errno %d\n", (int)-result); 588 printk("Unable to read data+bss, errno %d\n", (int)-result);
589 do_munmap(current->mm, textpos, text_len); 589 vm_munmap(textpos, text_len);
590 do_munmap(current->mm, realdatastart, len); 590 vm_munmap(realdatastart, len);
591 ret = result; 591 ret = result;
592 goto err; 592 goto err;
593 } 593 }
@@ -654,7 +654,7 @@ static int load_flat_file(struct linux_binprm * bprm,
654 } 654 }
655 if (IS_ERR_VALUE(result)) { 655 if (IS_ERR_VALUE(result)) {
656 printk("Unable to read code+data+bss, errno %d\n",(int)-result); 656 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
657 do_munmap(current->mm, textpos, text_len + data_len + extra + 657 vm_munmap(textpos, text_len + data_len + extra +
658 MAX_SHARED_LIBS * sizeof(unsigned long)); 658 MAX_SHARED_LIBS * sizeof(unsigned long));
659 ret = result; 659 ret = result;
660 goto err; 660 goto err;
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
index 89b156d85d63..761e2cd8fed1 100644
--- a/fs/btrfs/acl.c
+++ b/fs/btrfs/acl.c
@@ -227,7 +227,11 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans,
227 if (ret > 0) { 227 if (ret > 0) {
228 /* we need an acl */ 228 /* we need an acl */
229 ret = btrfs_set_acl(trans, inode, acl, ACL_TYPE_ACCESS); 229 ret = btrfs_set_acl(trans, inode, acl, ACL_TYPE_ACCESS);
230 } else {
231 cache_no_acl(inode);
230 } 232 }
233 } else {
234 cache_no_acl(inode);
231 } 235 }
232failed: 236failed:
233 posix_acl_release(acl); 237 posix_acl_release(acl);
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index bcec06750232..3f75895c919b 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -24,22 +24,135 @@
24#include "delayed-ref.h" 24#include "delayed-ref.h"
25#include "locking.h" 25#include "locking.h"
26 26
27struct extent_inode_elem {
28 u64 inum;
29 u64 offset;
30 struct extent_inode_elem *next;
31};
32
33static int check_extent_in_eb(struct btrfs_key *key, struct extent_buffer *eb,
34 struct btrfs_file_extent_item *fi,
35 u64 extent_item_pos,
36 struct extent_inode_elem **eie)
37{
38 u64 data_offset;
39 u64 data_len;
40 struct extent_inode_elem *e;
41
42 data_offset = btrfs_file_extent_offset(eb, fi);
43 data_len = btrfs_file_extent_num_bytes(eb, fi);
44
45 if (extent_item_pos < data_offset ||
46 extent_item_pos >= data_offset + data_len)
47 return 1;
48
49 e = kmalloc(sizeof(*e), GFP_NOFS);
50 if (!e)
51 return -ENOMEM;
52
53 e->next = *eie;
54 e->inum = key->objectid;
55 e->offset = key->offset + (extent_item_pos - data_offset);
56 *eie = e;
57
58 return 0;
59}
60
61static int find_extent_in_eb(struct extent_buffer *eb, u64 wanted_disk_byte,
62 u64 extent_item_pos,
63 struct extent_inode_elem **eie)
64{
65 u64 disk_byte;
66 struct btrfs_key key;
67 struct btrfs_file_extent_item *fi;
68 int slot;
69 int nritems;
70 int extent_type;
71 int ret;
72
73 /*
74 * from the shared data ref, we only have the leaf but we need
75 * the key. thus, we must look into all items and see that we
76 * find one (some) with a reference to our extent item.
77 */
78 nritems = btrfs_header_nritems(eb);
79 for (slot = 0; slot < nritems; ++slot) {
80 btrfs_item_key_to_cpu(eb, &key, slot);
81 if (key.type != BTRFS_EXTENT_DATA_KEY)
82 continue;
83 fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item);
84 extent_type = btrfs_file_extent_type(eb, fi);
85 if (extent_type == BTRFS_FILE_EXTENT_INLINE)
86 continue;
87 /* don't skip BTRFS_FILE_EXTENT_PREALLOC, we can handle that */
88 disk_byte = btrfs_file_extent_disk_bytenr(eb, fi);
89 if (disk_byte != wanted_disk_byte)
90 continue;
91
92 ret = check_extent_in_eb(&key, eb, fi, extent_item_pos, eie);
93 if (ret < 0)
94 return ret;
95 }
96
97 return 0;
98}
99
27/* 100/*
28 * this structure records all encountered refs on the way up to the root 101 * this structure records all encountered refs on the way up to the root
29 */ 102 */
30struct __prelim_ref { 103struct __prelim_ref {
31 struct list_head list; 104 struct list_head list;
32 u64 root_id; 105 u64 root_id;
33 struct btrfs_key key; 106 struct btrfs_key key_for_search;
34 int level; 107 int level;
35 int count; 108 int count;
109 struct extent_inode_elem *inode_list;
36 u64 parent; 110 u64 parent;
37 u64 wanted_disk_byte; 111 u64 wanted_disk_byte;
38}; 112};
39 113
114/*
115 * the rules for all callers of this function are:
116 * - obtaining the parent is the goal
117 * - if you add a key, you must know that it is a correct key
118 * - if you cannot add the parent or a correct key, then we will look into the
119 * block later to set a correct key
120 *
121 * delayed refs
122 * ============
123 * backref type | shared | indirect | shared | indirect
124 * information | tree | tree | data | data
125 * --------------------+--------+----------+--------+----------
126 * parent logical | y | - | - | -
127 * key to resolve | - | y | y | y
128 * tree block logical | - | - | - | -
129 * root for resolving | y | y | y | y
130 *
131 * - column 1: we've the parent -> done
132 * - column 2, 3, 4: we use the key to find the parent
133 *
134 * on disk refs (inline or keyed)
135 * ==============================
136 * backref type | shared | indirect | shared | indirect
137 * information | tree | tree | data | data
138 * --------------------+--------+----------+--------+----------
139 * parent logical | y | - | y | -
140 * key to resolve | - | - | - | y
141 * tree block logical | y | y | y | y
142 * root for resolving | - | y | y | y
143 *
144 * - column 1, 3: we've the parent -> done
145 * - column 2: we take the first key from the block to find the parent
146 * (see __add_missing_keys)
147 * - column 4: we use the key to find the parent
148 *
149 * additional information that's available but not required to find the parent
150 * block might help in merging entries to gain some speed.
151 */
152
40static int __add_prelim_ref(struct list_head *head, u64 root_id, 153static int __add_prelim_ref(struct list_head *head, u64 root_id,
41 struct btrfs_key *key, int level, u64 parent, 154 struct btrfs_key *key, int level,
42 u64 wanted_disk_byte, int count) 155 u64 parent, u64 wanted_disk_byte, int count)
43{ 156{
44 struct __prelim_ref *ref; 157 struct __prelim_ref *ref;
45 158
@@ -50,10 +163,11 @@ static int __add_prelim_ref(struct list_head *head, u64 root_id,
50 163
51 ref->root_id = root_id; 164 ref->root_id = root_id;
52 if (key) 165 if (key)
53 ref->key = *key; 166 ref->key_for_search = *key;
54 else 167 else
55 memset(&ref->key, 0, sizeof(ref->key)); 168 memset(&ref->key_for_search, 0, sizeof(ref->key_for_search));
56 169
170 ref->inode_list = NULL;
57 ref->level = level; 171 ref->level = level;
58 ref->count = count; 172 ref->count = count;
59 ref->parent = parent; 173 ref->parent = parent;
@@ -64,18 +178,26 @@ static int __add_prelim_ref(struct list_head *head, u64 root_id,
64} 178}
65 179
66static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path, 180static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
67 struct ulist *parents, 181 struct ulist *parents, int level,
68 struct extent_buffer *eb, int level, 182 struct btrfs_key *key, u64 wanted_disk_byte,
69 u64 wanted_objectid, u64 wanted_disk_byte) 183 const u64 *extent_item_pos)
70{ 184{
71 int ret; 185 int ret;
72 int slot; 186 int slot = path->slots[level];
187 struct extent_buffer *eb = path->nodes[level];
73 struct btrfs_file_extent_item *fi; 188 struct btrfs_file_extent_item *fi;
74 struct btrfs_key key; 189 struct extent_inode_elem *eie = NULL;
75 u64 disk_byte; 190 u64 disk_byte;
191 u64 wanted_objectid = key->objectid;
76 192
77add_parent: 193add_parent:
78 ret = ulist_add(parents, eb->start, 0, GFP_NOFS); 194 if (level == 0 && extent_item_pos) {
195 fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item);
196 ret = check_extent_in_eb(key, eb, fi, *extent_item_pos, &eie);
197 if (ret < 0)
198 return ret;
199 }
200 ret = ulist_add(parents, eb->start, (unsigned long)eie, GFP_NOFS);
79 if (ret < 0) 201 if (ret < 0)
80 return ret; 202 return ret;
81 203
@@ -89,6 +211,7 @@ add_parent:
89 * repeat this until we don't find any additional EXTENT_DATA items. 211 * repeat this until we don't find any additional EXTENT_DATA items.
90 */ 212 */
91 while (1) { 213 while (1) {
214 eie = NULL;
92 ret = btrfs_next_leaf(root, path); 215 ret = btrfs_next_leaf(root, path);
93 if (ret < 0) 216 if (ret < 0)
94 return ret; 217 return ret;
@@ -97,9 +220,9 @@ add_parent:
97 220
98 eb = path->nodes[0]; 221 eb = path->nodes[0];
99 for (slot = 0; slot < btrfs_header_nritems(eb); ++slot) { 222 for (slot = 0; slot < btrfs_header_nritems(eb); ++slot) {
100 btrfs_item_key_to_cpu(eb, &key, slot); 223 btrfs_item_key_to_cpu(eb, key, slot);
101 if (key.objectid != wanted_objectid || 224 if (key->objectid != wanted_objectid ||
102 key.type != BTRFS_EXTENT_DATA_KEY) 225 key->type != BTRFS_EXTENT_DATA_KEY)
103 return 0; 226 return 0;
104 fi = btrfs_item_ptr(eb, slot, 227 fi = btrfs_item_ptr(eb, slot,
105 struct btrfs_file_extent_item); 228 struct btrfs_file_extent_item);
@@ -118,8 +241,10 @@ add_parent:
118 */ 241 */
119static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info, 242static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
120 int search_commit_root, 243 int search_commit_root,
244 u64 time_seq,
121 struct __prelim_ref *ref, 245 struct __prelim_ref *ref,
122 struct ulist *parents) 246 struct ulist *parents,
247 const u64 *extent_item_pos)
123{ 248{
124 struct btrfs_path *path; 249 struct btrfs_path *path;
125 struct btrfs_root *root; 250 struct btrfs_root *root;
@@ -152,12 +277,13 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
152 goto out; 277 goto out;
153 278
154 path->lowest_level = level; 279 path->lowest_level = level;
155 ret = btrfs_search_slot(NULL, root, &ref->key, path, 0, 0); 280 ret = btrfs_search_old_slot(root, &ref->key_for_search, path, time_seq);
156 pr_debug("search slot in root %llu (level %d, ref count %d) returned " 281 pr_debug("search slot in root %llu (level %d, ref count %d) returned "
157 "%d for key (%llu %u %llu)\n", 282 "%d for key (%llu %u %llu)\n",
158 (unsigned long long)ref->root_id, level, ref->count, ret, 283 (unsigned long long)ref->root_id, level, ref->count, ret,
159 (unsigned long long)ref->key.objectid, ref->key.type, 284 (unsigned long long)ref->key_for_search.objectid,
160 (unsigned long long)ref->key.offset); 285 ref->key_for_search.type,
286 (unsigned long long)ref->key_for_search.offset);
161 if (ret < 0) 287 if (ret < 0)
162 goto out; 288 goto out;
163 289
@@ -179,9 +305,8 @@ static int __resolve_indirect_ref(struct btrfs_fs_info *fs_info,
179 btrfs_item_key_to_cpu(eb, &key, path->slots[0]); 305 btrfs_item_key_to_cpu(eb, &key, path->slots[0]);
180 } 306 }
181 307
182 /* the last two parameters will only be used for level == 0 */ 308 ret = add_all_parents(root, path, parents, level, &key,
183 ret = add_all_parents(root, path, parents, eb, level, key.objectid, 309 ref->wanted_disk_byte, extent_item_pos);
184 ref->wanted_disk_byte);
185out: 310out:
186 btrfs_free_path(path); 311 btrfs_free_path(path);
187 return ret; 312 return ret;
@@ -191,8 +316,9 @@ out:
191 * resolve all indirect backrefs from the list 316 * resolve all indirect backrefs from the list
192 */ 317 */
193static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info, 318static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
194 int search_commit_root, 319 int search_commit_root, u64 time_seq,
195 struct list_head *head) 320 struct list_head *head,
321 const u64 *extent_item_pos)
196{ 322{
197 int err; 323 int err;
198 int ret = 0; 324 int ret = 0;
@@ -201,6 +327,7 @@ static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
201 struct __prelim_ref *new_ref; 327 struct __prelim_ref *new_ref;
202 struct ulist *parents; 328 struct ulist *parents;
203 struct ulist_node *node; 329 struct ulist_node *node;
330 struct ulist_iterator uiter;
204 331
205 parents = ulist_alloc(GFP_NOFS); 332 parents = ulist_alloc(GFP_NOFS);
206 if (!parents) 333 if (!parents)
@@ -217,7 +344,8 @@ static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
217 if (ref->count == 0) 344 if (ref->count == 0)
218 continue; 345 continue;
219 err = __resolve_indirect_ref(fs_info, search_commit_root, 346 err = __resolve_indirect_ref(fs_info, search_commit_root,
220 ref, parents); 347 time_seq, ref, parents,
348 extent_item_pos);
221 if (err) { 349 if (err) {
222 if (ret == 0) 350 if (ret == 0)
223 ret = err; 351 ret = err;
@@ -225,11 +353,14 @@ static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
225 } 353 }
226 354
227 /* we put the first parent into the ref at hand */ 355 /* we put the first parent into the ref at hand */
228 node = ulist_next(parents, NULL); 356 ULIST_ITER_INIT(&uiter);
357 node = ulist_next(parents, &uiter);
229 ref->parent = node ? node->val : 0; 358 ref->parent = node ? node->val : 0;
359 ref->inode_list =
360 node ? (struct extent_inode_elem *)node->aux : 0;
230 361
231 /* additional parents require new refs being added here */ 362 /* additional parents require new refs being added here */
232 while ((node = ulist_next(parents, node))) { 363 while ((node = ulist_next(parents, &uiter))) {
233 new_ref = kmalloc(sizeof(*new_ref), GFP_NOFS); 364 new_ref = kmalloc(sizeof(*new_ref), GFP_NOFS);
234 if (!new_ref) { 365 if (!new_ref) {
235 ret = -ENOMEM; 366 ret = -ENOMEM;
@@ -237,6 +368,8 @@ static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
237 } 368 }
238 memcpy(new_ref, ref, sizeof(*ref)); 369 memcpy(new_ref, ref, sizeof(*ref));
239 new_ref->parent = node->val; 370 new_ref->parent = node->val;
371 new_ref->inode_list =
372 (struct extent_inode_elem *)node->aux;
240 list_add(&new_ref->list, &ref->list); 373 list_add(&new_ref->list, &ref->list);
241 } 374 }
242 ulist_reinit(parents); 375 ulist_reinit(parents);
@@ -246,10 +379,65 @@ static int __resolve_indirect_refs(struct btrfs_fs_info *fs_info,
246 return ret; 379 return ret;
247} 380}
248 381
382static inline int ref_for_same_block(struct __prelim_ref *ref1,
383 struct __prelim_ref *ref2)
384{
385 if (ref1->level != ref2->level)
386 return 0;
387 if (ref1->root_id != ref2->root_id)
388 return 0;
389 if (ref1->key_for_search.type != ref2->key_for_search.type)
390 return 0;
391 if (ref1->key_for_search.objectid != ref2->key_for_search.objectid)
392 return 0;
393 if (ref1->key_for_search.offset != ref2->key_for_search.offset)
394 return 0;
395 if (ref1->parent != ref2->parent)
396 return 0;
397
398 return 1;
399}
400
401/*
402 * read tree blocks and add keys where required.
403 */
404static int __add_missing_keys(struct btrfs_fs_info *fs_info,
405 struct list_head *head)
406{
407 struct list_head *pos;
408 struct extent_buffer *eb;
409
410 list_for_each(pos, head) {
411 struct __prelim_ref *ref;
412 ref = list_entry(pos, struct __prelim_ref, list);
413
414 if (ref->parent)
415 continue;
416 if (ref->key_for_search.type)
417 continue;
418 BUG_ON(!ref->wanted_disk_byte);
419 eb = read_tree_block(fs_info->tree_root, ref->wanted_disk_byte,
420 fs_info->tree_root->leafsize, 0);
421 BUG_ON(!eb);
422 btrfs_tree_read_lock(eb);
423 if (btrfs_header_level(eb) == 0)
424 btrfs_item_key_to_cpu(eb, &ref->key_for_search, 0);
425 else
426 btrfs_node_key_to_cpu(eb, &ref->key_for_search, 0);
427 btrfs_tree_read_unlock(eb);
428 free_extent_buffer(eb);
429 }
430 return 0;
431}
432
249/* 433/*
250 * merge two lists of backrefs and adjust counts accordingly 434 * merge two lists of backrefs and adjust counts accordingly
251 * 435 *
252 * mode = 1: merge identical keys, if key is set 436 * mode = 1: merge identical keys, if key is set
437 * FIXME: if we add more keys in __add_prelim_ref, we can merge more here.
438 * additionally, we could even add a key range for the blocks we
439 * looked into to merge even more (-> replace unresolved refs by those
440 * having a parent).
253 * mode = 2: merge identical parents 441 * mode = 2: merge identical parents
254 */ 442 */
255static int __merge_refs(struct list_head *head, int mode) 443static int __merge_refs(struct list_head *head, int mode)
@@ -263,20 +451,21 @@ static int __merge_refs(struct list_head *head, int mode)
263 451
264 ref1 = list_entry(pos1, struct __prelim_ref, list); 452 ref1 = list_entry(pos1, struct __prelim_ref, list);
265 453
266 if (mode == 1 && ref1->key.type == 0)
267 continue;
268 for (pos2 = pos1->next, n2 = pos2->next; pos2 != head; 454 for (pos2 = pos1->next, n2 = pos2->next; pos2 != head;
269 pos2 = n2, n2 = pos2->next) { 455 pos2 = n2, n2 = pos2->next) {
270 struct __prelim_ref *ref2; 456 struct __prelim_ref *ref2;
457 struct __prelim_ref *xchg;
271 458
272 ref2 = list_entry(pos2, struct __prelim_ref, list); 459 ref2 = list_entry(pos2, struct __prelim_ref, list);
273 460
274 if (mode == 1) { 461 if (mode == 1) {
275 if (memcmp(&ref1->key, &ref2->key, 462 if (!ref_for_same_block(ref1, ref2))
276 sizeof(ref1->key)) ||
277 ref1->level != ref2->level ||
278 ref1->root_id != ref2->root_id)
279 continue; 463 continue;
464 if (!ref1->parent && ref2->parent) {
465 xchg = ref1;
466 ref1 = ref2;
467 ref2 = xchg;
468 }
280 ref1->count += ref2->count; 469 ref1->count += ref2->count;
281 } else { 470 } else {
282 if (ref1->parent != ref2->parent) 471 if (ref1->parent != ref2->parent)
@@ -296,16 +485,17 @@ static int __merge_refs(struct list_head *head, int mode)
296 * smaller or equal that seq to the list 485 * smaller or equal that seq to the list
297 */ 486 */
298static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq, 487static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
299 struct btrfs_key *info_key,
300 struct list_head *prefs) 488 struct list_head *prefs)
301{ 489{
302 struct btrfs_delayed_extent_op *extent_op = head->extent_op; 490 struct btrfs_delayed_extent_op *extent_op = head->extent_op;
303 struct rb_node *n = &head->node.rb_node; 491 struct rb_node *n = &head->node.rb_node;
492 struct btrfs_key key;
493 struct btrfs_key op_key = {0};
304 int sgn; 494 int sgn;
305 int ret = 0; 495 int ret = 0;
306 496
307 if (extent_op && extent_op->update_key) 497 if (extent_op && extent_op->update_key)
308 btrfs_disk_key_to_cpu(info_key, &extent_op->key); 498 btrfs_disk_key_to_cpu(&op_key, &extent_op->key);
309 499
310 while ((n = rb_prev(n))) { 500 while ((n = rb_prev(n))) {
311 struct btrfs_delayed_ref_node *node; 501 struct btrfs_delayed_ref_node *node;
@@ -337,7 +527,7 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
337 struct btrfs_delayed_tree_ref *ref; 527 struct btrfs_delayed_tree_ref *ref;
338 528
339 ref = btrfs_delayed_node_to_tree_ref(node); 529 ref = btrfs_delayed_node_to_tree_ref(node);
340 ret = __add_prelim_ref(prefs, ref->root, info_key, 530 ret = __add_prelim_ref(prefs, ref->root, &op_key,
341 ref->level + 1, 0, node->bytenr, 531 ref->level + 1, 0, node->bytenr,
342 node->ref_mod * sgn); 532 node->ref_mod * sgn);
343 break; 533 break;
@@ -346,7 +536,7 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
346 struct btrfs_delayed_tree_ref *ref; 536 struct btrfs_delayed_tree_ref *ref;
347 537
348 ref = btrfs_delayed_node_to_tree_ref(node); 538 ref = btrfs_delayed_node_to_tree_ref(node);
349 ret = __add_prelim_ref(prefs, ref->root, info_key, 539 ret = __add_prelim_ref(prefs, ref->root, NULL,
350 ref->level + 1, ref->parent, 540 ref->level + 1, ref->parent,
351 node->bytenr, 541 node->bytenr,
352 node->ref_mod * sgn); 542 node->ref_mod * sgn);
@@ -354,8 +544,6 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
354 } 544 }
355 case BTRFS_EXTENT_DATA_REF_KEY: { 545 case BTRFS_EXTENT_DATA_REF_KEY: {
356 struct btrfs_delayed_data_ref *ref; 546 struct btrfs_delayed_data_ref *ref;
357 struct btrfs_key key;
358
359 ref = btrfs_delayed_node_to_data_ref(node); 547 ref = btrfs_delayed_node_to_data_ref(node);
360 548
361 key.objectid = ref->objectid; 549 key.objectid = ref->objectid;
@@ -368,7 +556,6 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
368 } 556 }
369 case BTRFS_SHARED_DATA_REF_KEY: { 557 case BTRFS_SHARED_DATA_REF_KEY: {
370 struct btrfs_delayed_data_ref *ref; 558 struct btrfs_delayed_data_ref *ref;
371 struct btrfs_key key;
372 559
373 ref = btrfs_delayed_node_to_data_ref(node); 560 ref = btrfs_delayed_node_to_data_ref(node);
374 561
@@ -394,8 +581,7 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
394 */ 581 */
395static int __add_inline_refs(struct btrfs_fs_info *fs_info, 582static int __add_inline_refs(struct btrfs_fs_info *fs_info,
396 struct btrfs_path *path, u64 bytenr, 583 struct btrfs_path *path, u64 bytenr,
397 struct btrfs_key *info_key, int *info_level, 584 int *info_level, struct list_head *prefs)
398 struct list_head *prefs)
399{ 585{
400 int ret = 0; 586 int ret = 0;
401 int slot; 587 int slot;
@@ -411,7 +597,7 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
411 * enumerate all inline refs 597 * enumerate all inline refs
412 */ 598 */
413 leaf = path->nodes[0]; 599 leaf = path->nodes[0];
414 slot = path->slots[0] - 1; 600 slot = path->slots[0];
415 601
416 item_size = btrfs_item_size_nr(leaf, slot); 602 item_size = btrfs_item_size_nr(leaf, slot);
417 BUG_ON(item_size < sizeof(*ei)); 603 BUG_ON(item_size < sizeof(*ei));
@@ -424,12 +610,9 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
424 610
425 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { 611 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
426 struct btrfs_tree_block_info *info; 612 struct btrfs_tree_block_info *info;
427 struct btrfs_disk_key disk_key;
428 613
429 info = (struct btrfs_tree_block_info *)ptr; 614 info = (struct btrfs_tree_block_info *)ptr;
430 *info_level = btrfs_tree_block_level(leaf, info); 615 *info_level = btrfs_tree_block_level(leaf, info);
431 btrfs_tree_block_key(leaf, info, &disk_key);
432 btrfs_disk_key_to_cpu(info_key, &disk_key);
433 ptr += sizeof(struct btrfs_tree_block_info); 616 ptr += sizeof(struct btrfs_tree_block_info);
434 BUG_ON(ptr > end); 617 BUG_ON(ptr > end);
435 } else { 618 } else {
@@ -447,7 +630,7 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
447 630
448 switch (type) { 631 switch (type) {
449 case BTRFS_SHARED_BLOCK_REF_KEY: 632 case BTRFS_SHARED_BLOCK_REF_KEY:
450 ret = __add_prelim_ref(prefs, 0, info_key, 633 ret = __add_prelim_ref(prefs, 0, NULL,
451 *info_level + 1, offset, 634 *info_level + 1, offset,
452 bytenr, 1); 635 bytenr, 1);
453 break; 636 break;
@@ -462,8 +645,9 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
462 break; 645 break;
463 } 646 }
464 case BTRFS_TREE_BLOCK_REF_KEY: 647 case BTRFS_TREE_BLOCK_REF_KEY:
465 ret = __add_prelim_ref(prefs, offset, info_key, 648 ret = __add_prelim_ref(prefs, offset, NULL,
466 *info_level + 1, 0, bytenr, 1); 649 *info_level + 1, 0,
650 bytenr, 1);
467 break; 651 break;
468 case BTRFS_EXTENT_DATA_REF_KEY: { 652 case BTRFS_EXTENT_DATA_REF_KEY: {
469 struct btrfs_extent_data_ref *dref; 653 struct btrfs_extent_data_ref *dref;
@@ -477,8 +661,8 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
477 key.type = BTRFS_EXTENT_DATA_KEY; 661 key.type = BTRFS_EXTENT_DATA_KEY;
478 key.offset = btrfs_extent_data_ref_offset(leaf, dref); 662 key.offset = btrfs_extent_data_ref_offset(leaf, dref);
479 root = btrfs_extent_data_ref_root(leaf, dref); 663 root = btrfs_extent_data_ref_root(leaf, dref);
480 ret = __add_prelim_ref(prefs, root, &key, 0, 0, bytenr, 664 ret = __add_prelim_ref(prefs, root, &key, 0, 0,
481 count); 665 bytenr, count);
482 break; 666 break;
483 } 667 }
484 default: 668 default:
@@ -496,8 +680,7 @@ static int __add_inline_refs(struct btrfs_fs_info *fs_info,
496 */ 680 */
497static int __add_keyed_refs(struct btrfs_fs_info *fs_info, 681static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
498 struct btrfs_path *path, u64 bytenr, 682 struct btrfs_path *path, u64 bytenr,
499 struct btrfs_key *info_key, int info_level, 683 int info_level, struct list_head *prefs)
500 struct list_head *prefs)
501{ 684{
502 struct btrfs_root *extent_root = fs_info->extent_root; 685 struct btrfs_root *extent_root = fs_info->extent_root;
503 int ret; 686 int ret;
@@ -527,7 +710,7 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
527 710
528 switch (key.type) { 711 switch (key.type) {
529 case BTRFS_SHARED_BLOCK_REF_KEY: 712 case BTRFS_SHARED_BLOCK_REF_KEY:
530 ret = __add_prelim_ref(prefs, 0, info_key, 713 ret = __add_prelim_ref(prefs, 0, NULL,
531 info_level + 1, key.offset, 714 info_level + 1, key.offset,
532 bytenr, 1); 715 bytenr, 1);
533 break; 716 break;
@@ -543,8 +726,9 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
543 break; 726 break;
544 } 727 }
545 case BTRFS_TREE_BLOCK_REF_KEY: 728 case BTRFS_TREE_BLOCK_REF_KEY:
546 ret = __add_prelim_ref(prefs, key.offset, info_key, 729 ret = __add_prelim_ref(prefs, key.offset, NULL,
547 info_level + 1, 0, bytenr, 1); 730 info_level + 1, 0,
731 bytenr, 1);
548 break; 732 break;
549 case BTRFS_EXTENT_DATA_REF_KEY: { 733 case BTRFS_EXTENT_DATA_REF_KEY: {
550 struct btrfs_extent_data_ref *dref; 734 struct btrfs_extent_data_ref *dref;
@@ -560,7 +744,7 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
560 key.offset = btrfs_extent_data_ref_offset(leaf, dref); 744 key.offset = btrfs_extent_data_ref_offset(leaf, dref);
561 root = btrfs_extent_data_ref_root(leaf, dref); 745 root = btrfs_extent_data_ref_root(leaf, dref);
562 ret = __add_prelim_ref(prefs, root, &key, 0, 0, 746 ret = __add_prelim_ref(prefs, root, &key, 0, 0,
563 bytenr, count); 747 bytenr, count);
564 break; 748 break;
565 } 749 }
566 default: 750 default:
@@ -582,11 +766,12 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,
582 */ 766 */
583static int find_parent_nodes(struct btrfs_trans_handle *trans, 767static int find_parent_nodes(struct btrfs_trans_handle *trans,
584 struct btrfs_fs_info *fs_info, u64 bytenr, 768 struct btrfs_fs_info *fs_info, u64 bytenr,
585 u64 seq, struct ulist *refs, struct ulist *roots) 769 u64 delayed_ref_seq, u64 time_seq,
770 struct ulist *refs, struct ulist *roots,
771 const u64 *extent_item_pos)
586{ 772{
587 struct btrfs_key key; 773 struct btrfs_key key;
588 struct btrfs_path *path; 774 struct btrfs_path *path;
589 struct btrfs_key info_key = { 0 };
590 struct btrfs_delayed_ref_root *delayed_refs = NULL; 775 struct btrfs_delayed_ref_root *delayed_refs = NULL;
591 struct btrfs_delayed_ref_head *head; 776 struct btrfs_delayed_ref_head *head;
592 int info_level = 0; 777 int info_level = 0;
@@ -645,7 +830,7 @@ again:
645 btrfs_put_delayed_ref(&head->node); 830 btrfs_put_delayed_ref(&head->node);
646 goto again; 831 goto again;
647 } 832 }
648 ret = __add_delayed_refs(head, seq, &info_key, 833 ret = __add_delayed_refs(head, delayed_ref_seq,
649 &prefs_delayed); 834 &prefs_delayed);
650 if (ret) { 835 if (ret) {
651 spin_unlock(&delayed_refs->lock); 836 spin_unlock(&delayed_refs->lock);
@@ -659,16 +844,17 @@ again:
659 struct extent_buffer *leaf; 844 struct extent_buffer *leaf;
660 int slot; 845 int slot;
661 846
847 path->slots[0]--;
662 leaf = path->nodes[0]; 848 leaf = path->nodes[0];
663 slot = path->slots[0] - 1; 849 slot = path->slots[0];
664 btrfs_item_key_to_cpu(leaf, &key, slot); 850 btrfs_item_key_to_cpu(leaf, &key, slot);
665 if (key.objectid == bytenr && 851 if (key.objectid == bytenr &&
666 key.type == BTRFS_EXTENT_ITEM_KEY) { 852 key.type == BTRFS_EXTENT_ITEM_KEY) {
667 ret = __add_inline_refs(fs_info, path, bytenr, 853 ret = __add_inline_refs(fs_info, path, bytenr,
668 &info_key, &info_level, &prefs); 854 &info_level, &prefs);
669 if (ret) 855 if (ret)
670 goto out; 856 goto out;
671 ret = __add_keyed_refs(fs_info, path, bytenr, &info_key, 857 ret = __add_keyed_refs(fs_info, path, bytenr,
672 info_level, &prefs); 858 info_level, &prefs);
673 if (ret) 859 if (ret)
674 goto out; 860 goto out;
@@ -676,21 +862,18 @@ again:
676 } 862 }
677 btrfs_release_path(path); 863 btrfs_release_path(path);
678 864
679 /*
680 * when adding the delayed refs above, the info_key might not have
681 * been known yet. Go over the list and replace the missing keys
682 */
683 list_for_each_entry(ref, &prefs_delayed, list) {
684 if ((ref->key.offset | ref->key.type | ref->key.objectid) == 0)
685 memcpy(&ref->key, &info_key, sizeof(ref->key));
686 }
687 list_splice_init(&prefs_delayed, &prefs); 865 list_splice_init(&prefs_delayed, &prefs);
688 866
867 ret = __add_missing_keys(fs_info, &prefs);
868 if (ret)
869 goto out;
870
689 ret = __merge_refs(&prefs, 1); 871 ret = __merge_refs(&prefs, 1);
690 if (ret) 872 if (ret)
691 goto out; 873 goto out;
692 874
693 ret = __resolve_indirect_refs(fs_info, search_commit_root, &prefs); 875 ret = __resolve_indirect_refs(fs_info, search_commit_root, time_seq,
876 &prefs, extent_item_pos);
694 if (ret) 877 if (ret)
695 goto out; 878 goto out;
696 879
@@ -709,7 +892,33 @@ again:
709 BUG_ON(ret < 0); 892 BUG_ON(ret < 0);
710 } 893 }
711 if (ref->count && ref->parent) { 894 if (ref->count && ref->parent) {
712 ret = ulist_add(refs, ref->parent, 0, GFP_NOFS); 895 struct extent_inode_elem *eie = NULL;
896 if (extent_item_pos && !ref->inode_list) {
897 u32 bsz;
898 struct extent_buffer *eb;
899 bsz = btrfs_level_size(fs_info->extent_root,
900 info_level);
901 eb = read_tree_block(fs_info->extent_root,
902 ref->parent, bsz, 0);
903 BUG_ON(!eb);
904 ret = find_extent_in_eb(eb, bytenr,
905 *extent_item_pos, &eie);
906 ref->inode_list = eie;
907 free_extent_buffer(eb);
908 }
909 ret = ulist_add_merge(refs, ref->parent,
910 (unsigned long)ref->inode_list,
911 (unsigned long *)&eie, GFP_NOFS);
912 if (!ret && extent_item_pos) {
913 /*
914 * we've recorded that parent, so we must extend
915 * its inode list here
916 */
917 BUG_ON(!eie);
918 while (eie->next)
919 eie = eie->next;
920 eie->next = ref->inode_list;
921 }
713 BUG_ON(ret < 0); 922 BUG_ON(ret < 0);
714 } 923 }
715 kfree(ref); 924 kfree(ref);
@@ -734,6 +943,28 @@ out:
734 return ret; 943 return ret;
735} 944}
736 945
946static void free_leaf_list(struct ulist *blocks)
947{
948 struct ulist_node *node = NULL;
949 struct extent_inode_elem *eie;
950 struct extent_inode_elem *eie_next;
951 struct ulist_iterator uiter;
952
953 ULIST_ITER_INIT(&uiter);
954 while ((node = ulist_next(blocks, &uiter))) {
955 if (!node->aux)
956 continue;
957 eie = (struct extent_inode_elem *)node->aux;
958 for (; eie; eie = eie_next) {
959 eie_next = eie->next;
960 kfree(eie);
961 }
962 node->aux = 0;
963 }
964
965 ulist_free(blocks);
966}
967
737/* 968/*
738 * Finds all leafs with a reference to the specified combination of bytenr and 969 * Finds all leafs with a reference to the specified combination of bytenr and
739 * offset. key_list_head will point to a list of corresponding keys (caller must 970 * offset. key_list_head will point to a list of corresponding keys (caller must
@@ -744,7 +975,9 @@ out:
744 */ 975 */
745static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans, 976static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
746 struct btrfs_fs_info *fs_info, u64 bytenr, 977 struct btrfs_fs_info *fs_info, u64 bytenr,
747 u64 num_bytes, u64 seq, struct ulist **leafs) 978 u64 delayed_ref_seq, u64 time_seq,
979 struct ulist **leafs,
980 const u64 *extent_item_pos)
748{ 981{
749 struct ulist *tmp; 982 struct ulist *tmp;
750 int ret; 983 int ret;
@@ -758,11 +991,12 @@ static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
758 return -ENOMEM; 991 return -ENOMEM;
759 } 992 }
760 993
761 ret = find_parent_nodes(trans, fs_info, bytenr, seq, *leafs, tmp); 994 ret = find_parent_nodes(trans, fs_info, bytenr, delayed_ref_seq,
995 time_seq, *leafs, tmp, extent_item_pos);
762 ulist_free(tmp); 996 ulist_free(tmp);
763 997
764 if (ret < 0 && ret != -ENOENT) { 998 if (ret < 0 && ret != -ENOENT) {
765 ulist_free(*leafs); 999 free_leaf_list(*leafs);
766 return ret; 1000 return ret;
767 } 1001 }
768 1002
@@ -784,10 +1018,12 @@ static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,
784 */ 1018 */
785int btrfs_find_all_roots(struct btrfs_trans_handle *trans, 1019int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
786 struct btrfs_fs_info *fs_info, u64 bytenr, 1020 struct btrfs_fs_info *fs_info, u64 bytenr,
787 u64 num_bytes, u64 seq, struct ulist **roots) 1021 u64 delayed_ref_seq, u64 time_seq,
1022 struct ulist **roots)
788{ 1023{
789 struct ulist *tmp; 1024 struct ulist *tmp;
790 struct ulist_node *node = NULL; 1025 struct ulist_node *node = NULL;
1026 struct ulist_iterator uiter;
791 int ret; 1027 int ret;
792 1028
793 tmp = ulist_alloc(GFP_NOFS); 1029 tmp = ulist_alloc(GFP_NOFS);
@@ -799,15 +1035,16 @@ int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
799 return -ENOMEM; 1035 return -ENOMEM;
800 } 1036 }
801 1037
1038 ULIST_ITER_INIT(&uiter);
802 while (1) { 1039 while (1) {
803 ret = find_parent_nodes(trans, fs_info, bytenr, seq, 1040 ret = find_parent_nodes(trans, fs_info, bytenr, delayed_ref_seq,
804 tmp, *roots); 1041 time_seq, tmp, *roots, NULL);
805 if (ret < 0 && ret != -ENOENT) { 1042 if (ret < 0 && ret != -ENOENT) {
806 ulist_free(tmp); 1043 ulist_free(tmp);
807 ulist_free(*roots); 1044 ulist_free(*roots);
808 return ret; 1045 return ret;
809 } 1046 }
810 node = ulist_next(tmp, node); 1047 node = ulist_next(tmp, &uiter);
811 if (!node) 1048 if (!node)
812 break; 1049 break;
813 bytenr = node->val; 1050 bytenr = node->val;
@@ -1093,67 +1330,25 @@ int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
1093 return 0; 1330 return 0;
1094} 1331}
1095 1332
1096static int iterate_leaf_refs(struct btrfs_fs_info *fs_info, u64 logical, 1333static int iterate_leaf_refs(struct extent_inode_elem *inode_list,
1097 u64 orig_extent_item_objectid, 1334 u64 root, u64 extent_item_objectid,
1098 u64 extent_item_pos, u64 root,
1099 iterate_extent_inodes_t *iterate, void *ctx) 1335 iterate_extent_inodes_t *iterate, void *ctx)
1100{ 1336{
1101 u64 disk_byte; 1337 struct extent_inode_elem *eie;
1102 struct btrfs_key key;
1103 struct btrfs_file_extent_item *fi;
1104 struct extent_buffer *eb;
1105 int slot;
1106 int nritems;
1107 int ret = 0; 1338 int ret = 0;
1108 int extent_type;
1109 u64 data_offset;
1110 u64 data_len;
1111
1112 eb = read_tree_block(fs_info->tree_root, logical,
1113 fs_info->tree_root->leafsize, 0);
1114 if (!eb)
1115 return -EIO;
1116
1117 /*
1118 * from the shared data ref, we only have the leaf but we need
1119 * the key. thus, we must look into all items and see that we
1120 * find one (some) with a reference to our extent item.
1121 */
1122 nritems = btrfs_header_nritems(eb);
1123 for (slot = 0; slot < nritems; ++slot) {
1124 btrfs_item_key_to_cpu(eb, &key, slot);
1125 if (key.type != BTRFS_EXTENT_DATA_KEY)
1126 continue;
1127 fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item);
1128 extent_type = btrfs_file_extent_type(eb, fi);
1129 if (extent_type == BTRFS_FILE_EXTENT_INLINE)
1130 continue;
1131 /* don't skip BTRFS_FILE_EXTENT_PREALLOC, we can handle that */
1132 disk_byte = btrfs_file_extent_disk_bytenr(eb, fi);
1133 if (disk_byte != orig_extent_item_objectid)
1134 continue;
1135
1136 data_offset = btrfs_file_extent_offset(eb, fi);
1137 data_len = btrfs_file_extent_num_bytes(eb, fi);
1138
1139 if (extent_item_pos < data_offset ||
1140 extent_item_pos >= data_offset + data_len)
1141 continue;
1142 1339
1340 for (eie = inode_list; eie; eie = eie->next) {
1143 pr_debug("ref for %llu resolved, key (%llu EXTEND_DATA %llu), " 1341 pr_debug("ref for %llu resolved, key (%llu EXTEND_DATA %llu), "
1144 "root %llu\n", orig_extent_item_objectid, 1342 "root %llu\n", extent_item_objectid,
1145 key.objectid, key.offset, root); 1343 eie->inum, eie->offset, root);
1146 ret = iterate(key.objectid, 1344 ret = iterate(eie->inum, eie->offset, root, ctx);
1147 key.offset + (extent_item_pos - data_offset),
1148 root, ctx);
1149 if (ret) { 1345 if (ret) {
1150 pr_debug("stopping iteration because ret=%d\n", ret); 1346 pr_debug("stopping iteration for %llu due to ret=%d\n",
1347 extent_item_objectid, ret);
1151 break; 1348 break;
1152 } 1349 }
1153 } 1350 }
1154 1351
1155 free_extent_buffer(eb);
1156
1157 return ret; 1352 return ret;
1158} 1353}
1159 1354
@@ -1175,7 +1370,10 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
1175 struct ulist *roots = NULL; 1370 struct ulist *roots = NULL;
1176 struct ulist_node *ref_node = NULL; 1371 struct ulist_node *ref_node = NULL;
1177 struct ulist_node *root_node = NULL; 1372 struct ulist_node *root_node = NULL;
1178 struct seq_list seq_elem; 1373 struct seq_list seq_elem = {};
1374 struct seq_list tree_mod_seq_elem = {};
1375 struct ulist_iterator ref_uiter;
1376 struct ulist_iterator root_uiter;
1179 struct btrfs_delayed_ref_root *delayed_refs = NULL; 1377 struct btrfs_delayed_ref_root *delayed_refs = NULL;
1180 1378
1181 pr_debug("resolving all inodes for extent %llu\n", 1379 pr_debug("resolving all inodes for extent %llu\n",
@@ -1192,34 +1390,41 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
1192 spin_lock(&delayed_refs->lock); 1390 spin_lock(&delayed_refs->lock);
1193 btrfs_get_delayed_seq(delayed_refs, &seq_elem); 1391 btrfs_get_delayed_seq(delayed_refs, &seq_elem);
1194 spin_unlock(&delayed_refs->lock); 1392 spin_unlock(&delayed_refs->lock);
1393 btrfs_get_tree_mod_seq(fs_info, &tree_mod_seq_elem);
1195 } 1394 }
1196 1395
1197 ret = btrfs_find_all_leafs(trans, fs_info, extent_item_objectid, 1396 ret = btrfs_find_all_leafs(trans, fs_info, extent_item_objectid,
1198 extent_item_pos, seq_elem.seq, 1397 seq_elem.seq, tree_mod_seq_elem.seq, &refs,
1199 &refs); 1398 &extent_item_pos);
1200
1201 if (ret) 1399 if (ret)
1202 goto out; 1400 goto out;
1203 1401
1204 while (!ret && (ref_node = ulist_next(refs, ref_node))) { 1402 ULIST_ITER_INIT(&ref_uiter);
1205 ret = btrfs_find_all_roots(trans, fs_info, ref_node->val, -1, 1403 while (!ret && (ref_node = ulist_next(refs, &ref_uiter))) {
1206 seq_elem.seq, &roots); 1404 ret = btrfs_find_all_roots(trans, fs_info, ref_node->val,
1405 seq_elem.seq,
1406 tree_mod_seq_elem.seq, &roots);
1207 if (ret) 1407 if (ret)
1208 break; 1408 break;
1209 while (!ret && (root_node = ulist_next(roots, root_node))) { 1409 ULIST_ITER_INIT(&root_uiter);
1210 pr_debug("root %llu references leaf %llu\n", 1410 while (!ret && (root_node = ulist_next(roots, &root_uiter))) {
1211 root_node->val, ref_node->val); 1411 pr_debug("root %llu references leaf %llu, data list "
1212 ret = iterate_leaf_refs(fs_info, ref_node->val, 1412 "%#lx\n", root_node->val, ref_node->val,
1213 extent_item_objectid, 1413 ref_node->aux);
1214 extent_item_pos, root_node->val, 1414 ret = iterate_leaf_refs(
1215 iterate, ctx); 1415 (struct extent_inode_elem *)ref_node->aux,
1416 root_node->val, extent_item_objectid,
1417 iterate, ctx);
1216 } 1418 }
1419 ulist_free(roots);
1420 roots = NULL;
1217 } 1421 }
1218 1422
1219 ulist_free(refs); 1423 free_leaf_list(refs);
1220 ulist_free(roots); 1424 ulist_free(roots);
1221out: 1425out:
1222 if (!search_commit_root) { 1426 if (!search_commit_root) {
1427 btrfs_put_tree_mod_seq(fs_info, &tree_mod_seq_elem);
1223 btrfs_put_delayed_seq(delayed_refs, &seq_elem); 1428 btrfs_put_delayed_seq(delayed_refs, &seq_elem);
1224 btrfs_end_transaction(trans, fs_info->extent_root); 1429 btrfs_end_transaction(trans, fs_info->extent_root);
1225 } 1430 }
diff --git a/fs/btrfs/backref.h b/fs/btrfs/backref.h
index 57ea2e959e4d..c18d8ac7b795 100644
--- a/fs/btrfs/backref.h
+++ b/fs/btrfs/backref.h
@@ -58,7 +58,8 @@ int paths_from_inode(u64 inum, struct inode_fs_paths *ipath);
58 58
59int btrfs_find_all_roots(struct btrfs_trans_handle *trans, 59int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
60 struct btrfs_fs_info *fs_info, u64 bytenr, 60 struct btrfs_fs_info *fs_info, u64 bytenr,
61 u64 num_bytes, u64 seq, struct ulist **roots); 61 u64 delayed_ref_seq, u64 time_seq,
62 struct ulist **roots);
62 63
63struct btrfs_data_container *init_data_container(u32 total_bytes); 64struct btrfs_data_container *init_data_container(u32 total_bytes);
64struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root, 65struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index 9b9b15fd5204..e616f8872e69 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -24,6 +24,20 @@
24#include "ordered-data.h" 24#include "ordered-data.h"
25#include "delayed-inode.h" 25#include "delayed-inode.h"
26 26
27/*
28 * ordered_data_close is set by truncate when a file that used
29 * to have good data has been truncated to zero. When it is set
30 * the btrfs file release call will add this inode to the
31 * ordered operations list so that we make sure to flush out any
32 * new data the application may have written before commit.
33 */
34#define BTRFS_INODE_ORDERED_DATA_CLOSE 0
35#define BTRFS_INODE_ORPHAN_META_RESERVED 1
36#define BTRFS_INODE_DUMMY 2
37#define BTRFS_INODE_IN_DEFRAG 3
38#define BTRFS_INODE_DELALLOC_META_RESERVED 4
39#define BTRFS_INODE_HAS_ORPHAN_ITEM 5
40
27/* in memory btrfs inode */ 41/* in memory btrfs inode */
28struct btrfs_inode { 42struct btrfs_inode {
29 /* which subvolume this inode belongs to */ 43 /* which subvolume this inode belongs to */
@@ -57,9 +71,6 @@ struct btrfs_inode {
57 /* used to order data wrt metadata */ 71 /* used to order data wrt metadata */
58 struct btrfs_ordered_inode_tree ordered_tree; 72 struct btrfs_ordered_inode_tree ordered_tree;
59 73
60 /* for keeping track of orphaned inodes */
61 struct list_head i_orphan;
62
63 /* list of all the delalloc inodes in the FS. There are times we need 74 /* list of all the delalloc inodes in the FS. There are times we need
64 * to write all the delalloc pages to disk, and this list is used 75 * to write all the delalloc pages to disk, and this list is used
65 * to walk them all. 76 * to walk them all.
@@ -78,14 +89,13 @@ struct btrfs_inode {
78 /* the space_info for where this inode's data allocations are done */ 89 /* the space_info for where this inode's data allocations are done */
79 struct btrfs_space_info *space_info; 90 struct btrfs_space_info *space_info;
80 91
92 unsigned long runtime_flags;
93
81 /* full 64 bit generation number, struct vfs_inode doesn't have a big 94 /* full 64 bit generation number, struct vfs_inode doesn't have a big
82 * enough field for this. 95 * enough field for this.
83 */ 96 */
84 u64 generation; 97 u64 generation;
85 98
86 /* sequence number for NFS changes */
87 u64 sequence;
88
89 /* 99 /*
90 * transid of the trans_handle that last modified this inode 100 * transid of the trans_handle that last modified this inode
91 */ 101 */
@@ -145,22 +155,9 @@ struct btrfs_inode {
145 unsigned reserved_extents; 155 unsigned reserved_extents;
146 156
147 /* 157 /*
148 * ordered_data_close is set by truncate when a file that used
149 * to have good data has been truncated to zero. When it is set
150 * the btrfs file release call will add this inode to the
151 * ordered operations list so that we make sure to flush out any
152 * new data the application may have written before commit.
153 */
154 unsigned ordered_data_close:1;
155 unsigned orphan_meta_reserved:1;
156 unsigned dummy_inode:1;
157 unsigned in_defrag:1;
158 unsigned delalloc_meta_reserved:1;
159
160 /*
161 * always compress this one file 158 * always compress this one file
162 */ 159 */
163 unsigned force_compress:4; 160 unsigned force_compress;
164 161
165 struct btrfs_delayed_node *delayed_node; 162 struct btrfs_delayed_node *delayed_node;
166 163
@@ -202,4 +199,17 @@ static inline bool btrfs_is_free_space_inode(struct btrfs_root *root,
202 return false; 199 return false;
203} 200}
204 201
202static inline int btrfs_inode_in_log(struct inode *inode, u64 generation)
203{
204 struct btrfs_root *root = BTRFS_I(inode)->root;
205 int ret = 0;
206
207 mutex_lock(&root->log_mutex);
208 if (BTRFS_I(inode)->logged_trans == generation &&
209 BTRFS_I(inode)->last_sub_trans <= root->last_log_commit)
210 ret = 1;
211 mutex_unlock(&root->log_mutex);
212 return ret;
213}
214
205#endif 215#endif
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index c053e90f2006..9cebb1fd6a3c 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -103,8 +103,6 @@
103#define BTRFSIC_BLOCK_STACK_FRAME_MAGIC_NUMBER 20111300 103#define BTRFSIC_BLOCK_STACK_FRAME_MAGIC_NUMBER 20111300
104#define BTRFSIC_TREE_DUMP_MAX_INDENT_LEVEL (200 - 6) /* in characters, 104#define BTRFSIC_TREE_DUMP_MAX_INDENT_LEVEL (200 - 6) /* in characters,
105 * excluding " [...]" */ 105 * excluding " [...]" */
106#define BTRFSIC_BLOCK_SIZE PAGE_SIZE
107
108#define BTRFSIC_GENERATION_UNKNOWN ((u64)-1) 106#define BTRFSIC_GENERATION_UNKNOWN ((u64)-1)
109 107
110/* 108/*
@@ -210,8 +208,9 @@ struct btrfsic_block_data_ctx {
210 u64 dev_bytenr; /* physical bytenr on device */ 208 u64 dev_bytenr; /* physical bytenr on device */
211 u32 len; 209 u32 len;
212 struct btrfsic_dev_state *dev; 210 struct btrfsic_dev_state *dev;
213 char *data; 211 char **datav;
214 struct buffer_head *bh; /* do not use if set to NULL */ 212 struct page **pagev;
213 void *mem_to_free;
215}; 214};
216 215
217/* This structure is used to implement recursion without occupying 216/* This structure is used to implement recursion without occupying
@@ -243,6 +242,8 @@ struct btrfsic_state {
243 struct btrfs_root *root; 242 struct btrfs_root *root;
244 u64 max_superblock_generation; 243 u64 max_superblock_generation;
245 struct btrfsic_block *latest_superblock; 244 struct btrfsic_block *latest_superblock;
245 u32 metablock_size;
246 u32 datablock_size;
246}; 247};
247 248
248static void btrfsic_block_init(struct btrfsic_block *b); 249static void btrfsic_block_init(struct btrfsic_block *b);
@@ -290,8 +291,10 @@ static int btrfsic_process_superblock(struct btrfsic_state *state,
290static int btrfsic_process_metablock(struct btrfsic_state *state, 291static int btrfsic_process_metablock(struct btrfsic_state *state,
291 struct btrfsic_block *block, 292 struct btrfsic_block *block,
292 struct btrfsic_block_data_ctx *block_ctx, 293 struct btrfsic_block_data_ctx *block_ctx,
293 struct btrfs_header *hdr,
294 int limit_nesting, int force_iodone_flag); 294 int limit_nesting, int force_iodone_flag);
295static void btrfsic_read_from_block_data(
296 struct btrfsic_block_data_ctx *block_ctx,
297 void *dst, u32 offset, size_t len);
295static int btrfsic_create_link_to_next_block( 298static int btrfsic_create_link_to_next_block(
296 struct btrfsic_state *state, 299 struct btrfsic_state *state,
297 struct btrfsic_block *block, 300 struct btrfsic_block *block,
@@ -318,12 +321,13 @@ static void btrfsic_release_block_ctx(struct btrfsic_block_data_ctx *block_ctx);
318static int btrfsic_read_block(struct btrfsic_state *state, 321static int btrfsic_read_block(struct btrfsic_state *state,
319 struct btrfsic_block_data_ctx *block_ctx); 322 struct btrfsic_block_data_ctx *block_ctx);
320static void btrfsic_dump_database(struct btrfsic_state *state); 323static void btrfsic_dump_database(struct btrfsic_state *state);
324static void btrfsic_complete_bio_end_io(struct bio *bio, int err);
321static int btrfsic_test_for_metadata(struct btrfsic_state *state, 325static int btrfsic_test_for_metadata(struct btrfsic_state *state,
322 const u8 *data, unsigned int size); 326 char **datav, unsigned int num_pages);
323static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state, 327static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
324 u64 dev_bytenr, u8 *mapped_data, 328 u64 dev_bytenr, char **mapped_datav,
325 unsigned int len, struct bio *bio, 329 unsigned int num_pages,
326 int *bio_is_patched, 330 struct bio *bio, int *bio_is_patched,
327 struct buffer_head *bh, 331 struct buffer_head *bh,
328 int submit_bio_bh_rw); 332 int submit_bio_bh_rw);
329static int btrfsic_process_written_superblock( 333static int btrfsic_process_written_superblock(
@@ -375,7 +379,7 @@ static struct btrfsic_dev_state *btrfsic_dev_state_lookup(
375static void btrfsic_cmp_log_and_dev_bytenr(struct btrfsic_state *state, 379static void btrfsic_cmp_log_and_dev_bytenr(struct btrfsic_state *state,
376 u64 bytenr, 380 u64 bytenr,
377 struct btrfsic_dev_state *dev_state, 381 struct btrfsic_dev_state *dev_state,
378 u64 dev_bytenr, char *data); 382 u64 dev_bytenr);
379 383
380static struct mutex btrfsic_mutex; 384static struct mutex btrfsic_mutex;
381static int btrfsic_is_initialized; 385static int btrfsic_is_initialized;
@@ -651,7 +655,7 @@ static int btrfsic_process_superblock(struct btrfsic_state *state,
651 int pass; 655 int pass;
652 656
653 BUG_ON(NULL == state); 657 BUG_ON(NULL == state);
654 selected_super = kmalloc(sizeof(*selected_super), GFP_NOFS); 658 selected_super = kzalloc(sizeof(*selected_super), GFP_NOFS);
655 if (NULL == selected_super) { 659 if (NULL == selected_super) {
656 printk(KERN_INFO "btrfsic: error, kmalloc failed!\n"); 660 printk(KERN_INFO "btrfsic: error, kmalloc failed!\n");
657 return -1; 661 return -1;
@@ -718,7 +722,7 @@ static int btrfsic_process_superblock(struct btrfsic_state *state,
718 722
719 num_copies = 723 num_copies =
720 btrfs_num_copies(&state->root->fs_info->mapping_tree, 724 btrfs_num_copies(&state->root->fs_info->mapping_tree,
721 next_bytenr, PAGE_SIZE); 725 next_bytenr, state->metablock_size);
722 if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES) 726 if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES)
723 printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n", 727 printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n",
724 (unsigned long long)next_bytenr, num_copies); 728 (unsigned long long)next_bytenr, num_copies);
@@ -727,9 +731,9 @@ static int btrfsic_process_superblock(struct btrfsic_state *state,
727 struct btrfsic_block *next_block; 731 struct btrfsic_block *next_block;
728 struct btrfsic_block_data_ctx tmp_next_block_ctx; 732 struct btrfsic_block_data_ctx tmp_next_block_ctx;
729 struct btrfsic_block_link *l; 733 struct btrfsic_block_link *l;
730 struct btrfs_header *hdr;
731 734
732 ret = btrfsic_map_block(state, next_bytenr, PAGE_SIZE, 735 ret = btrfsic_map_block(state, next_bytenr,
736 state->metablock_size,
733 &tmp_next_block_ctx, 737 &tmp_next_block_ctx,
734 mirror_num); 738 mirror_num);
735 if (ret) { 739 if (ret) {
@@ -758,7 +762,7 @@ static int btrfsic_process_superblock(struct btrfsic_state *state,
758 BUG_ON(NULL == l); 762 BUG_ON(NULL == l);
759 763
760 ret = btrfsic_read_block(state, &tmp_next_block_ctx); 764 ret = btrfsic_read_block(state, &tmp_next_block_ctx);
761 if (ret < (int)BTRFSIC_BLOCK_SIZE) { 765 if (ret < (int)PAGE_CACHE_SIZE) {
762 printk(KERN_INFO 766 printk(KERN_INFO
763 "btrfsic: read @logical %llu failed!\n", 767 "btrfsic: read @logical %llu failed!\n",
764 (unsigned long long) 768 (unsigned long long)
@@ -768,11 +772,9 @@ static int btrfsic_process_superblock(struct btrfsic_state *state,
768 return -1; 772 return -1;
769 } 773 }
770 774
771 hdr = (struct btrfs_header *)tmp_next_block_ctx.data;
772 ret = btrfsic_process_metablock(state, 775 ret = btrfsic_process_metablock(state,
773 next_block, 776 next_block,
774 &tmp_next_block_ctx, 777 &tmp_next_block_ctx,
775 hdr,
776 BTRFS_MAX_LEVEL + 3, 1); 778 BTRFS_MAX_LEVEL + 3, 1);
777 btrfsic_release_block_ctx(&tmp_next_block_ctx); 779 btrfsic_release_block_ctx(&tmp_next_block_ctx);
778 } 780 }
@@ -799,7 +801,10 @@ static int btrfsic_process_superblock_dev_mirror(
799 801
800 /* super block bytenr is always the unmapped device bytenr */ 802 /* super block bytenr is always the unmapped device bytenr */
801 dev_bytenr = btrfs_sb_offset(superblock_mirror_num); 803 dev_bytenr = btrfs_sb_offset(superblock_mirror_num);
802 bh = __bread(superblock_bdev, dev_bytenr / 4096, 4096); 804 if (dev_bytenr + BTRFS_SUPER_INFO_SIZE > device->total_bytes)
805 return -1;
806 bh = __bread(superblock_bdev, dev_bytenr / 4096,
807 BTRFS_SUPER_INFO_SIZE);
803 if (NULL == bh) 808 if (NULL == bh)
804 return -1; 809 return -1;
805 super_tmp = (struct btrfs_super_block *) 810 super_tmp = (struct btrfs_super_block *)
@@ -808,7 +813,10 @@ static int btrfsic_process_superblock_dev_mirror(
808 if (btrfs_super_bytenr(super_tmp) != dev_bytenr || 813 if (btrfs_super_bytenr(super_tmp) != dev_bytenr ||
809 strncmp((char *)(&(super_tmp->magic)), BTRFS_MAGIC, 814 strncmp((char *)(&(super_tmp->magic)), BTRFS_MAGIC,
810 sizeof(super_tmp->magic)) || 815 sizeof(super_tmp->magic)) ||
811 memcmp(device->uuid, super_tmp->dev_item.uuid, BTRFS_UUID_SIZE)) { 816 memcmp(device->uuid, super_tmp->dev_item.uuid, BTRFS_UUID_SIZE) ||
817 btrfs_super_nodesize(super_tmp) != state->metablock_size ||
818 btrfs_super_leafsize(super_tmp) != state->metablock_size ||
819 btrfs_super_sectorsize(super_tmp) != state->datablock_size) {
812 brelse(bh); 820 brelse(bh);
813 return 0; 821 return 0;
814 } 822 }
@@ -893,7 +901,7 @@ static int btrfsic_process_superblock_dev_mirror(
893 901
894 num_copies = 902 num_copies =
895 btrfs_num_copies(&state->root->fs_info->mapping_tree, 903 btrfs_num_copies(&state->root->fs_info->mapping_tree,
896 next_bytenr, PAGE_SIZE); 904 next_bytenr, state->metablock_size);
897 if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES) 905 if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES)
898 printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n", 906 printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n",
899 (unsigned long long)next_bytenr, num_copies); 907 (unsigned long long)next_bytenr, num_copies);
@@ -902,7 +910,8 @@ static int btrfsic_process_superblock_dev_mirror(
902 struct btrfsic_block_data_ctx tmp_next_block_ctx; 910 struct btrfsic_block_data_ctx tmp_next_block_ctx;
903 struct btrfsic_block_link *l; 911 struct btrfsic_block_link *l;
904 912
905 if (btrfsic_map_block(state, next_bytenr, PAGE_SIZE, 913 if (btrfsic_map_block(state, next_bytenr,
914 state->metablock_size,
906 &tmp_next_block_ctx, 915 &tmp_next_block_ctx,
907 mirror_num)) { 916 mirror_num)) {
908 printk(KERN_INFO "btrfsic: btrfsic_map_block(" 917 printk(KERN_INFO "btrfsic: btrfsic_map_block("
@@ -966,13 +975,15 @@ static int btrfsic_process_metablock(
966 struct btrfsic_state *state, 975 struct btrfsic_state *state,
967 struct btrfsic_block *const first_block, 976 struct btrfsic_block *const first_block,
968 struct btrfsic_block_data_ctx *const first_block_ctx, 977 struct btrfsic_block_data_ctx *const first_block_ctx,
969 struct btrfs_header *const first_hdr,
970 int first_limit_nesting, int force_iodone_flag) 978 int first_limit_nesting, int force_iodone_flag)
971{ 979{
972 struct btrfsic_stack_frame initial_stack_frame = { 0 }; 980 struct btrfsic_stack_frame initial_stack_frame = { 0 };
973 struct btrfsic_stack_frame *sf; 981 struct btrfsic_stack_frame *sf;
974 struct btrfsic_stack_frame *next_stack; 982 struct btrfsic_stack_frame *next_stack;
983 struct btrfs_header *const first_hdr =
984 (struct btrfs_header *)first_block_ctx->datav[0];
975 985
986 BUG_ON(!first_hdr);
976 sf = &initial_stack_frame; 987 sf = &initial_stack_frame;
977 sf->error = 0; 988 sf->error = 0;
978 sf->i = -1; 989 sf->i = -1;
@@ -1012,21 +1023,47 @@ continue_with_current_leaf_stack_frame:
1012 } 1023 }
1013 1024
1014 if (sf->i < sf->nr) { 1025 if (sf->i < sf->nr) {
1015 struct btrfs_item *disk_item = leafhdr->items + sf->i; 1026 struct btrfs_item disk_item;
1016 struct btrfs_disk_key *disk_key = &disk_item->key; 1027 u32 disk_item_offset =
1028 (uintptr_t)(leafhdr->items + sf->i) -
1029 (uintptr_t)leafhdr;
1030 struct btrfs_disk_key *disk_key;
1017 u8 type; 1031 u8 type;
1018 const u32 item_offset = le32_to_cpu(disk_item->offset); 1032 u32 item_offset;
1019 1033
1034 if (disk_item_offset + sizeof(struct btrfs_item) >
1035 sf->block_ctx->len) {
1036leaf_item_out_of_bounce_error:
1037 printk(KERN_INFO
1038 "btrfsic: leaf item out of bounce at logical %llu, dev %s\n",
1039 sf->block_ctx->start,
1040 sf->block_ctx->dev->name);
1041 goto one_stack_frame_backwards;
1042 }
1043 btrfsic_read_from_block_data(sf->block_ctx,
1044 &disk_item,
1045 disk_item_offset,
1046 sizeof(struct btrfs_item));
1047 item_offset = le32_to_cpu(disk_item.offset);
1048 disk_key = &disk_item.key;
1020 type = disk_key->type; 1049 type = disk_key->type;
1021 1050
1022 if (BTRFS_ROOT_ITEM_KEY == type) { 1051 if (BTRFS_ROOT_ITEM_KEY == type) {
1023 const struct btrfs_root_item *const root_item = 1052 struct btrfs_root_item root_item;
1024 (struct btrfs_root_item *) 1053 u32 root_item_offset;
1025 (sf->block_ctx->data + 1054 u64 next_bytenr;
1026 offsetof(struct btrfs_leaf, items) + 1055
1027 item_offset); 1056 root_item_offset = item_offset +
1028 const u64 next_bytenr = 1057 offsetof(struct btrfs_leaf, items);
1029 le64_to_cpu(root_item->bytenr); 1058 if (root_item_offset +
1059 sizeof(struct btrfs_root_item) >
1060 sf->block_ctx->len)
1061 goto leaf_item_out_of_bounce_error;
1062 btrfsic_read_from_block_data(
1063 sf->block_ctx, &root_item,
1064 root_item_offset,
1065 sizeof(struct btrfs_root_item));
1066 next_bytenr = le64_to_cpu(root_item.bytenr);
1030 1067
1031 sf->error = 1068 sf->error =
1032 btrfsic_create_link_to_next_block( 1069 btrfsic_create_link_to_next_block(
@@ -1041,7 +1078,7 @@ continue_with_current_leaf_stack_frame:
1041 &sf->num_copies, 1078 &sf->num_copies,
1042 &sf->mirror_num, 1079 &sf->mirror_num,
1043 disk_key, 1080 disk_key,
1044 le64_to_cpu(root_item-> 1081 le64_to_cpu(root_item.
1045 generation)); 1082 generation));
1046 if (sf->error) 1083 if (sf->error)
1047 goto one_stack_frame_backwards; 1084 goto one_stack_frame_backwards;
@@ -1049,7 +1086,7 @@ continue_with_current_leaf_stack_frame:
1049 if (NULL != sf->next_block) { 1086 if (NULL != sf->next_block) {
1050 struct btrfs_header *const next_hdr = 1087 struct btrfs_header *const next_hdr =
1051 (struct btrfs_header *) 1088 (struct btrfs_header *)
1052 sf->next_block_ctx.data; 1089 sf->next_block_ctx.datav[0];
1053 1090
1054 next_stack = 1091 next_stack =
1055 btrfsic_stack_frame_alloc(); 1092 btrfsic_stack_frame_alloc();
@@ -1111,10 +1148,24 @@ continue_with_current_node_stack_frame:
1111 } 1148 }
1112 1149
1113 if (sf->i < sf->nr) { 1150 if (sf->i < sf->nr) {
1114 struct btrfs_key_ptr *disk_key_ptr = 1151 struct btrfs_key_ptr key_ptr;
1115 nodehdr->ptrs + sf->i; 1152 u32 key_ptr_offset;
1116 const u64 next_bytenr = 1153 u64 next_bytenr;
1117 le64_to_cpu(disk_key_ptr->blockptr); 1154
1155 key_ptr_offset = (uintptr_t)(nodehdr->ptrs + sf->i) -
1156 (uintptr_t)nodehdr;
1157 if (key_ptr_offset + sizeof(struct btrfs_key_ptr) >
1158 sf->block_ctx->len) {
1159 printk(KERN_INFO
1160 "btrfsic: node item out of bounce at logical %llu, dev %s\n",
1161 sf->block_ctx->start,
1162 sf->block_ctx->dev->name);
1163 goto one_stack_frame_backwards;
1164 }
1165 btrfsic_read_from_block_data(
1166 sf->block_ctx, &key_ptr, key_ptr_offset,
1167 sizeof(struct btrfs_key_ptr));
1168 next_bytenr = le64_to_cpu(key_ptr.blockptr);
1118 1169
1119 sf->error = btrfsic_create_link_to_next_block( 1170 sf->error = btrfsic_create_link_to_next_block(
1120 state, 1171 state,
@@ -1127,15 +1178,15 @@ continue_with_current_node_stack_frame:
1127 force_iodone_flag, 1178 force_iodone_flag,
1128 &sf->num_copies, 1179 &sf->num_copies,
1129 &sf->mirror_num, 1180 &sf->mirror_num,
1130 &disk_key_ptr->key, 1181 &key_ptr.key,
1131 le64_to_cpu(disk_key_ptr->generation)); 1182 le64_to_cpu(key_ptr.generation));
1132 if (sf->error) 1183 if (sf->error)
1133 goto one_stack_frame_backwards; 1184 goto one_stack_frame_backwards;
1134 1185
1135 if (NULL != sf->next_block) { 1186 if (NULL != sf->next_block) {
1136 struct btrfs_header *const next_hdr = 1187 struct btrfs_header *const next_hdr =
1137 (struct btrfs_header *) 1188 (struct btrfs_header *)
1138 sf->next_block_ctx.data; 1189 sf->next_block_ctx.datav[0];
1139 1190
1140 next_stack = btrfsic_stack_frame_alloc(); 1191 next_stack = btrfsic_stack_frame_alloc();
1141 if (NULL == next_stack) 1192 if (NULL == next_stack)
@@ -1181,6 +1232,35 @@ one_stack_frame_backwards:
1181 return sf->error; 1232 return sf->error;
1182} 1233}
1183 1234
1235static void btrfsic_read_from_block_data(
1236 struct btrfsic_block_data_ctx *block_ctx,
1237 void *dstv, u32 offset, size_t len)
1238{
1239 size_t cur;
1240 size_t offset_in_page;
1241 char *kaddr;
1242 char *dst = (char *)dstv;
1243 size_t start_offset = block_ctx->start & ((u64)PAGE_CACHE_SIZE - 1);
1244 unsigned long i = (start_offset + offset) >> PAGE_CACHE_SHIFT;
1245
1246 WARN_ON(offset + len > block_ctx->len);
1247 offset_in_page = (start_offset + offset) &
1248 ((unsigned long)PAGE_CACHE_SIZE - 1);
1249
1250 while (len > 0) {
1251 cur = min(len, ((size_t)PAGE_CACHE_SIZE - offset_in_page));
1252 BUG_ON(i >= (block_ctx->len + PAGE_CACHE_SIZE - 1) >>
1253 PAGE_CACHE_SHIFT);
1254 kaddr = block_ctx->datav[i];
1255 memcpy(dst, kaddr + offset_in_page, cur);
1256
1257 dst += cur;
1258 len -= cur;
1259 offset_in_page = 0;
1260 i++;
1261 }
1262}
1263
1184static int btrfsic_create_link_to_next_block( 1264static int btrfsic_create_link_to_next_block(
1185 struct btrfsic_state *state, 1265 struct btrfsic_state *state,
1186 struct btrfsic_block *block, 1266 struct btrfsic_block *block,
@@ -1204,7 +1284,7 @@ static int btrfsic_create_link_to_next_block(
1204 if (0 == *num_copiesp) { 1284 if (0 == *num_copiesp) {
1205 *num_copiesp = 1285 *num_copiesp =
1206 btrfs_num_copies(&state->root->fs_info->mapping_tree, 1286 btrfs_num_copies(&state->root->fs_info->mapping_tree,
1207 next_bytenr, PAGE_SIZE); 1287 next_bytenr, state->metablock_size);
1208 if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES) 1288 if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES)
1209 printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n", 1289 printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n",
1210 (unsigned long long)next_bytenr, *num_copiesp); 1290 (unsigned long long)next_bytenr, *num_copiesp);
@@ -1219,7 +1299,7 @@ static int btrfsic_create_link_to_next_block(
1219 "btrfsic_create_link_to_next_block(mirror_num=%d)\n", 1299 "btrfsic_create_link_to_next_block(mirror_num=%d)\n",
1220 *mirror_nump); 1300 *mirror_nump);
1221 ret = btrfsic_map_block(state, next_bytenr, 1301 ret = btrfsic_map_block(state, next_bytenr,
1222 BTRFSIC_BLOCK_SIZE, 1302 state->metablock_size,
1223 next_block_ctx, *mirror_nump); 1303 next_block_ctx, *mirror_nump);
1224 if (ret) { 1304 if (ret) {
1225 printk(KERN_INFO 1305 printk(KERN_INFO
@@ -1314,7 +1394,7 @@ static int btrfsic_create_link_to_next_block(
1314 1394
1315 if (limit_nesting > 0 && did_alloc_block_link) { 1395 if (limit_nesting > 0 && did_alloc_block_link) {
1316 ret = btrfsic_read_block(state, next_block_ctx); 1396 ret = btrfsic_read_block(state, next_block_ctx);
1317 if (ret < (int)BTRFSIC_BLOCK_SIZE) { 1397 if (ret < (int)next_block_ctx->len) {
1318 printk(KERN_INFO 1398 printk(KERN_INFO
1319 "btrfsic: read block @logical %llu failed!\n", 1399 "btrfsic: read block @logical %llu failed!\n",
1320 (unsigned long long)next_bytenr); 1400 (unsigned long long)next_bytenr);
@@ -1339,43 +1419,74 @@ static int btrfsic_handle_extent_data(
1339 u32 item_offset, int force_iodone_flag) 1419 u32 item_offset, int force_iodone_flag)
1340{ 1420{
1341 int ret; 1421 int ret;
1342 struct btrfs_file_extent_item *file_extent_item = 1422 struct btrfs_file_extent_item file_extent_item;
1343 (struct btrfs_file_extent_item *)(block_ctx->data + 1423 u64 file_extent_item_offset;
1344 offsetof(struct btrfs_leaf, 1424 u64 next_bytenr;
1345 items) + item_offset); 1425 u64 num_bytes;
1346 u64 next_bytenr = 1426 u64 generation;
1347 le64_to_cpu(file_extent_item->disk_bytenr) +
1348 le64_to_cpu(file_extent_item->offset);
1349 u64 num_bytes = le64_to_cpu(file_extent_item->num_bytes);
1350 u64 generation = le64_to_cpu(file_extent_item->generation);
1351 struct btrfsic_block_link *l; 1427 struct btrfsic_block_link *l;
1352 1428
1429 file_extent_item_offset = offsetof(struct btrfs_leaf, items) +
1430 item_offset;
1431 if (file_extent_item_offset +
1432 offsetof(struct btrfs_file_extent_item, disk_num_bytes) >
1433 block_ctx->len) {
1434 printk(KERN_INFO
1435 "btrfsic: file item out of bounce at logical %llu, dev %s\n",
1436 block_ctx->start, block_ctx->dev->name);
1437 return -1;
1438 }
1439
1440 btrfsic_read_from_block_data(block_ctx, &file_extent_item,
1441 file_extent_item_offset,
1442 offsetof(struct btrfs_file_extent_item, disk_num_bytes));
1443 if (BTRFS_FILE_EXTENT_REG != file_extent_item.type ||
1444 ((u64)0) == le64_to_cpu(file_extent_item.disk_bytenr)) {
1445 if (state->print_mask & BTRFSIC_PRINT_MASK_VERY_VERBOSE)
1446 printk(KERN_INFO "extent_data: type %u, disk_bytenr = %llu\n",
1447 file_extent_item.type,
1448 (unsigned long long)
1449 le64_to_cpu(file_extent_item.disk_bytenr));
1450 return 0;
1451 }
1452
1453 if (file_extent_item_offset + sizeof(struct btrfs_file_extent_item) >
1454 block_ctx->len) {
1455 printk(KERN_INFO
1456 "btrfsic: file item out of bounce at logical %llu, dev %s\n",
1457 block_ctx->start, block_ctx->dev->name);
1458 return -1;
1459 }
1460 btrfsic_read_from_block_data(block_ctx, &file_extent_item,
1461 file_extent_item_offset,
1462 sizeof(struct btrfs_file_extent_item));
1463 next_bytenr = le64_to_cpu(file_extent_item.disk_bytenr) +
1464 le64_to_cpu(file_extent_item.offset);
1465 generation = le64_to_cpu(file_extent_item.generation);
1466 num_bytes = le64_to_cpu(file_extent_item.num_bytes);
1467 generation = le64_to_cpu(file_extent_item.generation);
1468
1353 if (state->print_mask & BTRFSIC_PRINT_MASK_VERY_VERBOSE) 1469 if (state->print_mask & BTRFSIC_PRINT_MASK_VERY_VERBOSE)
1354 printk(KERN_INFO "extent_data: type %u, disk_bytenr = %llu," 1470 printk(KERN_INFO "extent_data: type %u, disk_bytenr = %llu,"
1355 " offset = %llu, num_bytes = %llu\n", 1471 " offset = %llu, num_bytes = %llu\n",
1356 file_extent_item->type, 1472 file_extent_item.type,
1357 (unsigned long long) 1473 (unsigned long long)
1358 le64_to_cpu(file_extent_item->disk_bytenr), 1474 le64_to_cpu(file_extent_item.disk_bytenr),
1359 (unsigned long long) 1475 (unsigned long long)le64_to_cpu(file_extent_item.offset),
1360 le64_to_cpu(file_extent_item->offset), 1476 (unsigned long long)num_bytes);
1361 (unsigned long long)
1362 le64_to_cpu(file_extent_item->num_bytes));
1363 if (BTRFS_FILE_EXTENT_REG != file_extent_item->type ||
1364 ((u64)0) == le64_to_cpu(file_extent_item->disk_bytenr))
1365 return 0;
1366 while (num_bytes > 0) { 1477 while (num_bytes > 0) {
1367 u32 chunk_len; 1478 u32 chunk_len;
1368 int num_copies; 1479 int num_copies;
1369 int mirror_num; 1480 int mirror_num;
1370 1481
1371 if (num_bytes > BTRFSIC_BLOCK_SIZE) 1482 if (num_bytes > state->datablock_size)
1372 chunk_len = BTRFSIC_BLOCK_SIZE; 1483 chunk_len = state->datablock_size;
1373 else 1484 else
1374 chunk_len = num_bytes; 1485 chunk_len = num_bytes;
1375 1486
1376 num_copies = 1487 num_copies =
1377 btrfs_num_copies(&state->root->fs_info->mapping_tree, 1488 btrfs_num_copies(&state->root->fs_info->mapping_tree,
1378 next_bytenr, PAGE_SIZE); 1489 next_bytenr, state->datablock_size);
1379 if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES) 1490 if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES)
1380 printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n", 1491 printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n",
1381 (unsigned long long)next_bytenr, num_copies); 1492 (unsigned long long)next_bytenr, num_copies);
@@ -1475,8 +1586,9 @@ static int btrfsic_map_block(struct btrfsic_state *state, u64 bytenr, u32 len,
1475 block_ctx_out->dev_bytenr = multi->stripes[0].physical; 1586 block_ctx_out->dev_bytenr = multi->stripes[0].physical;
1476 block_ctx_out->start = bytenr; 1587 block_ctx_out->start = bytenr;
1477 block_ctx_out->len = len; 1588 block_ctx_out->len = len;
1478 block_ctx_out->data = NULL; 1589 block_ctx_out->datav = NULL;
1479 block_ctx_out->bh = NULL; 1590 block_ctx_out->pagev = NULL;
1591 block_ctx_out->mem_to_free = NULL;
1480 1592
1481 if (0 == ret) 1593 if (0 == ret)
1482 kfree(multi); 1594 kfree(multi);
@@ -1496,8 +1608,9 @@ static int btrfsic_map_superblock(struct btrfsic_state *state, u64 bytenr,
1496 block_ctx_out->dev_bytenr = bytenr; 1608 block_ctx_out->dev_bytenr = bytenr;
1497 block_ctx_out->start = bytenr; 1609 block_ctx_out->start = bytenr;
1498 block_ctx_out->len = len; 1610 block_ctx_out->len = len;
1499 block_ctx_out->data = NULL; 1611 block_ctx_out->datav = NULL;
1500 block_ctx_out->bh = NULL; 1612 block_ctx_out->pagev = NULL;
1613 block_ctx_out->mem_to_free = NULL;
1501 if (NULL != block_ctx_out->dev) { 1614 if (NULL != block_ctx_out->dev) {
1502 return 0; 1615 return 0;
1503 } else { 1616 } else {
@@ -1508,38 +1621,127 @@ static int btrfsic_map_superblock(struct btrfsic_state *state, u64 bytenr,
1508 1621
1509static void btrfsic_release_block_ctx(struct btrfsic_block_data_ctx *block_ctx) 1622static void btrfsic_release_block_ctx(struct btrfsic_block_data_ctx *block_ctx)
1510{ 1623{
1511 if (NULL != block_ctx->bh) { 1624 if (block_ctx->mem_to_free) {
1512 brelse(block_ctx->bh); 1625 unsigned int num_pages;
1513 block_ctx->bh = NULL; 1626
1627 BUG_ON(!block_ctx->datav);
1628 BUG_ON(!block_ctx->pagev);
1629 num_pages = (block_ctx->len + (u64)PAGE_CACHE_SIZE - 1) >>
1630 PAGE_CACHE_SHIFT;
1631 while (num_pages > 0) {
1632 num_pages--;
1633 if (block_ctx->datav[num_pages]) {
1634 kunmap(block_ctx->pagev[num_pages]);
1635 block_ctx->datav[num_pages] = NULL;
1636 }
1637 if (block_ctx->pagev[num_pages]) {
1638 __free_page(block_ctx->pagev[num_pages]);
1639 block_ctx->pagev[num_pages] = NULL;
1640 }
1641 }
1642
1643 kfree(block_ctx->mem_to_free);
1644 block_ctx->mem_to_free = NULL;
1645 block_ctx->pagev = NULL;
1646 block_ctx->datav = NULL;
1514 } 1647 }
1515} 1648}
1516 1649
1517static int btrfsic_read_block(struct btrfsic_state *state, 1650static int btrfsic_read_block(struct btrfsic_state *state,
1518 struct btrfsic_block_data_ctx *block_ctx) 1651 struct btrfsic_block_data_ctx *block_ctx)
1519{ 1652{
1520 block_ctx->bh = NULL; 1653 unsigned int num_pages;
1521 if (block_ctx->dev_bytenr & 4095) { 1654 unsigned int i;
1655 u64 dev_bytenr;
1656 int ret;
1657
1658 BUG_ON(block_ctx->datav);
1659 BUG_ON(block_ctx->pagev);
1660 BUG_ON(block_ctx->mem_to_free);
1661 if (block_ctx->dev_bytenr & ((u64)PAGE_CACHE_SIZE - 1)) {
1522 printk(KERN_INFO 1662 printk(KERN_INFO
1523 "btrfsic: read_block() with unaligned bytenr %llu\n", 1663 "btrfsic: read_block() with unaligned bytenr %llu\n",
1524 (unsigned long long)block_ctx->dev_bytenr); 1664 (unsigned long long)block_ctx->dev_bytenr);
1525 return -1; 1665 return -1;
1526 } 1666 }
1527 if (block_ctx->len > 4096) { 1667
1528 printk(KERN_INFO 1668 num_pages = (block_ctx->len + (u64)PAGE_CACHE_SIZE - 1) >>
1529 "btrfsic: read_block() with too huge size %d\n", 1669 PAGE_CACHE_SHIFT;
1530 block_ctx->len); 1670 block_ctx->mem_to_free = kzalloc((sizeof(*block_ctx->datav) +
1671 sizeof(*block_ctx->pagev)) *
1672 num_pages, GFP_NOFS);
1673 if (!block_ctx->mem_to_free)
1531 return -1; 1674 return -1;
1675 block_ctx->datav = block_ctx->mem_to_free;
1676 block_ctx->pagev = (struct page **)(block_ctx->datav + num_pages);
1677 for (i = 0; i < num_pages; i++) {
1678 block_ctx->pagev[i] = alloc_page(GFP_NOFS);
1679 if (!block_ctx->pagev[i])
1680 return -1;
1532 } 1681 }
1533 1682
1534 block_ctx->bh = __bread(block_ctx->dev->bdev, 1683 dev_bytenr = block_ctx->dev_bytenr;
1535 block_ctx->dev_bytenr >> 12, 4096); 1684 for (i = 0; i < num_pages;) {
1536 if (NULL == block_ctx->bh) 1685 struct bio *bio;
1537 return -1; 1686 unsigned int j;
1538 block_ctx->data = block_ctx->bh->b_data; 1687 DECLARE_COMPLETION_ONSTACK(complete);
1688
1689 bio = bio_alloc(GFP_NOFS, num_pages - i);
1690 if (!bio) {
1691 printk(KERN_INFO
1692 "btrfsic: bio_alloc() for %u pages failed!\n",
1693 num_pages - i);
1694 return -1;
1695 }
1696 bio->bi_bdev = block_ctx->dev->bdev;
1697 bio->bi_sector = dev_bytenr >> 9;
1698 bio->bi_end_io = btrfsic_complete_bio_end_io;
1699 bio->bi_private = &complete;
1700
1701 for (j = i; j < num_pages; j++) {
1702 ret = bio_add_page(bio, block_ctx->pagev[j],
1703 PAGE_CACHE_SIZE, 0);
1704 if (PAGE_CACHE_SIZE != ret)
1705 break;
1706 }
1707 if (j == i) {
1708 printk(KERN_INFO
1709 "btrfsic: error, failed to add a single page!\n");
1710 return -1;
1711 }
1712 submit_bio(READ, bio);
1713
1714 /* this will also unplug the queue */
1715 wait_for_completion(&complete);
1716
1717 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) {
1718 printk(KERN_INFO
1719 "btrfsic: read error at logical %llu dev %s!\n",
1720 block_ctx->start, block_ctx->dev->name);
1721 bio_put(bio);
1722 return -1;
1723 }
1724 bio_put(bio);
1725 dev_bytenr += (j - i) * PAGE_CACHE_SIZE;
1726 i = j;
1727 }
1728 for (i = 0; i < num_pages; i++) {
1729 block_ctx->datav[i] = kmap(block_ctx->pagev[i]);
1730 if (!block_ctx->datav[i]) {
1731 printk(KERN_INFO "btrfsic: kmap() failed (dev %s)!\n",
1732 block_ctx->dev->name);
1733 return -1;
1734 }
1735 }
1539 1736
1540 return block_ctx->len; 1737 return block_ctx->len;
1541} 1738}
1542 1739
1740static void btrfsic_complete_bio_end_io(struct bio *bio, int err)
1741{
1742 complete((struct completion *)bio->bi_private);
1743}
1744
1543static void btrfsic_dump_database(struct btrfsic_state *state) 1745static void btrfsic_dump_database(struct btrfsic_state *state)
1544{ 1746{
1545 struct list_head *elem_all; 1747 struct list_head *elem_all;
@@ -1617,32 +1819,39 @@ static void btrfsic_dump_database(struct btrfsic_state *state)
1617 * (note that this test fails for the super block) 1819 * (note that this test fails for the super block)
1618 */ 1820 */
1619static int btrfsic_test_for_metadata(struct btrfsic_state *state, 1821static int btrfsic_test_for_metadata(struct btrfsic_state *state,
1620 const u8 *data, unsigned int size) 1822 char **datav, unsigned int num_pages)
1621{ 1823{
1622 struct btrfs_header *h; 1824 struct btrfs_header *h;
1623 u8 csum[BTRFS_CSUM_SIZE]; 1825 u8 csum[BTRFS_CSUM_SIZE];
1624 u32 crc = ~(u32)0; 1826 u32 crc = ~(u32)0;
1625 int fail = 0; 1827 unsigned int i;
1626 int crc_fail = 0;
1627 1828
1628 h = (struct btrfs_header *)data; 1829 if (num_pages * PAGE_CACHE_SIZE < state->metablock_size)
1830 return 1; /* not metadata */
1831 num_pages = state->metablock_size >> PAGE_CACHE_SHIFT;
1832 h = (struct btrfs_header *)datav[0];
1629 1833
1630 if (memcmp(h->fsid, state->root->fs_info->fsid, BTRFS_UUID_SIZE)) 1834 if (memcmp(h->fsid, state->root->fs_info->fsid, BTRFS_UUID_SIZE))
1631 fail++; 1835 return 1;
1836
1837 for (i = 0; i < num_pages; i++) {
1838 u8 *data = i ? datav[i] : (datav[i] + BTRFS_CSUM_SIZE);
1839 size_t sublen = i ? PAGE_CACHE_SIZE :
1840 (PAGE_CACHE_SIZE - BTRFS_CSUM_SIZE);
1632 1841
1633 crc = crc32c(crc, data + BTRFS_CSUM_SIZE, PAGE_SIZE - BTRFS_CSUM_SIZE); 1842 crc = crc32c(crc, data, sublen);
1843 }
1634 btrfs_csum_final(crc, csum); 1844 btrfs_csum_final(crc, csum);
1635 if (memcmp(csum, h->csum, state->csum_size)) 1845 if (memcmp(csum, h->csum, state->csum_size))
1636 crc_fail++; 1846 return 1;
1637 1847
1638 return fail || crc_fail; 1848 return 0; /* is metadata */
1639} 1849}
1640 1850
1641static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state, 1851static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1642 u64 dev_bytenr, 1852 u64 dev_bytenr, char **mapped_datav,
1643 u8 *mapped_data, unsigned int len, 1853 unsigned int num_pages,
1644 struct bio *bio, 1854 struct bio *bio, int *bio_is_patched,
1645 int *bio_is_patched,
1646 struct buffer_head *bh, 1855 struct buffer_head *bh,
1647 int submit_bio_bh_rw) 1856 int submit_bio_bh_rw)
1648{ 1857{
@@ -1652,12 +1861,19 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1652 int ret; 1861 int ret;
1653 struct btrfsic_state *state = dev_state->state; 1862 struct btrfsic_state *state = dev_state->state;
1654 struct block_device *bdev = dev_state->bdev; 1863 struct block_device *bdev = dev_state->bdev;
1864 unsigned int processed_len;
1655 1865
1656 WARN_ON(len > PAGE_SIZE);
1657 is_metadata = (0 == btrfsic_test_for_metadata(state, mapped_data, len));
1658 if (NULL != bio_is_patched) 1866 if (NULL != bio_is_patched)
1659 *bio_is_patched = 0; 1867 *bio_is_patched = 0;
1660 1868
1869again:
1870 if (num_pages == 0)
1871 return;
1872
1873 processed_len = 0;
1874 is_metadata = (0 == btrfsic_test_for_metadata(state, mapped_datav,
1875 num_pages));
1876
1661 block = btrfsic_block_hashtable_lookup(bdev, dev_bytenr, 1877 block = btrfsic_block_hashtable_lookup(bdev, dev_bytenr,
1662 &state->block_hashtable); 1878 &state->block_hashtable);
1663 if (NULL != block) { 1879 if (NULL != block) {
@@ -1667,8 +1883,16 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1667 1883
1668 if (block->is_superblock) { 1884 if (block->is_superblock) {
1669 bytenr = le64_to_cpu(((struct btrfs_super_block *) 1885 bytenr = le64_to_cpu(((struct btrfs_super_block *)
1670 mapped_data)->bytenr); 1886 mapped_datav[0])->bytenr);
1887 if (num_pages * PAGE_CACHE_SIZE <
1888 BTRFS_SUPER_INFO_SIZE) {
1889 printk(KERN_INFO
1890 "btrfsic: cannot work with too short bios!\n");
1891 return;
1892 }
1671 is_metadata = 1; 1893 is_metadata = 1;
1894 BUG_ON(BTRFS_SUPER_INFO_SIZE & (PAGE_CACHE_SIZE - 1));
1895 processed_len = BTRFS_SUPER_INFO_SIZE;
1672 if (state->print_mask & 1896 if (state->print_mask &
1673 BTRFSIC_PRINT_MASK_TREE_BEFORE_SB_WRITE) { 1897 BTRFSIC_PRINT_MASK_TREE_BEFORE_SB_WRITE) {
1674 printk(KERN_INFO 1898 printk(KERN_INFO
@@ -1678,12 +1902,18 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1678 } 1902 }
1679 if (is_metadata) { 1903 if (is_metadata) {
1680 if (!block->is_superblock) { 1904 if (!block->is_superblock) {
1905 if (num_pages * PAGE_CACHE_SIZE <
1906 state->metablock_size) {
1907 printk(KERN_INFO
1908 "btrfsic: cannot work with too short bios!\n");
1909 return;
1910 }
1911 processed_len = state->metablock_size;
1681 bytenr = le64_to_cpu(((struct btrfs_header *) 1912 bytenr = le64_to_cpu(((struct btrfs_header *)
1682 mapped_data)->bytenr); 1913 mapped_datav[0])->bytenr);
1683 btrfsic_cmp_log_and_dev_bytenr(state, bytenr, 1914 btrfsic_cmp_log_and_dev_bytenr(state, bytenr,
1684 dev_state, 1915 dev_state,
1685 dev_bytenr, 1916 dev_bytenr);
1686 mapped_data);
1687 } 1917 }
1688 if (block->logical_bytenr != bytenr) { 1918 if (block->logical_bytenr != bytenr) {
1689 printk(KERN_INFO 1919 printk(KERN_INFO
@@ -1710,6 +1940,13 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1710 block->mirror_num, 1940 block->mirror_num,
1711 btrfsic_get_block_type(state, block)); 1941 btrfsic_get_block_type(state, block));
1712 } else { 1942 } else {
1943 if (num_pages * PAGE_CACHE_SIZE <
1944 state->datablock_size) {
1945 printk(KERN_INFO
1946 "btrfsic: cannot work with too short bios!\n");
1947 return;
1948 }
1949 processed_len = state->datablock_size;
1713 bytenr = block->logical_bytenr; 1950 bytenr = block->logical_bytenr;
1714 if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE) 1951 if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE)
1715 printk(KERN_INFO 1952 printk(KERN_INFO
@@ -1747,7 +1984,7 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1747 le64_to_cpu(block->disk_key.offset), 1984 le64_to_cpu(block->disk_key.offset),
1748 (unsigned long long) 1985 (unsigned long long)
1749 le64_to_cpu(((struct btrfs_header *) 1986 le64_to_cpu(((struct btrfs_header *)
1750 mapped_data)->generation), 1987 mapped_datav[0])->generation),
1751 (unsigned long long) 1988 (unsigned long long)
1752 state->max_superblock_generation); 1989 state->max_superblock_generation);
1753 btrfsic_dump_tree(state); 1990 btrfsic_dump_tree(state);
@@ -1765,10 +2002,10 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1765 (unsigned long long)block->generation, 2002 (unsigned long long)block->generation,
1766 (unsigned long long) 2003 (unsigned long long)
1767 le64_to_cpu(((struct btrfs_header *) 2004 le64_to_cpu(((struct btrfs_header *)
1768 mapped_data)->generation)); 2005 mapped_datav[0])->generation));
1769 /* it would not be safe to go on */ 2006 /* it would not be safe to go on */
1770 btrfsic_dump_tree(state); 2007 btrfsic_dump_tree(state);
1771 return; 2008 goto continue_loop;
1772 } 2009 }
1773 2010
1774 /* 2011 /*
@@ -1796,18 +2033,19 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1796 } 2033 }
1797 2034
1798 if (block->is_superblock) 2035 if (block->is_superblock)
1799 ret = btrfsic_map_superblock(state, bytenr, len, 2036 ret = btrfsic_map_superblock(state, bytenr,
2037 processed_len,
1800 bdev, &block_ctx); 2038 bdev, &block_ctx);
1801 else 2039 else
1802 ret = btrfsic_map_block(state, bytenr, len, 2040 ret = btrfsic_map_block(state, bytenr, processed_len,
1803 &block_ctx, 0); 2041 &block_ctx, 0);
1804 if (ret) { 2042 if (ret) {
1805 printk(KERN_INFO 2043 printk(KERN_INFO
1806 "btrfsic: btrfsic_map_block(root @%llu)" 2044 "btrfsic: btrfsic_map_block(root @%llu)"
1807 " failed!\n", (unsigned long long)bytenr); 2045 " failed!\n", (unsigned long long)bytenr);
1808 return; 2046 goto continue_loop;
1809 } 2047 }
1810 block_ctx.data = mapped_data; 2048 block_ctx.datav = mapped_datav;
1811 /* the following is required in case of writes to mirrors, 2049 /* the following is required in case of writes to mirrors,
1812 * use the same that was used for the lookup */ 2050 * use the same that was used for the lookup */
1813 block_ctx.dev = dev_state; 2051 block_ctx.dev = dev_state;
@@ -1863,11 +2101,13 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1863 block->logical_bytenr = bytenr; 2101 block->logical_bytenr = bytenr;
1864 block->is_metadata = 1; 2102 block->is_metadata = 1;
1865 if (block->is_superblock) { 2103 if (block->is_superblock) {
2104 BUG_ON(PAGE_CACHE_SIZE !=
2105 BTRFS_SUPER_INFO_SIZE);
1866 ret = btrfsic_process_written_superblock( 2106 ret = btrfsic_process_written_superblock(
1867 state, 2107 state,
1868 block, 2108 block,
1869 (struct btrfs_super_block *) 2109 (struct btrfs_super_block *)
1870 mapped_data); 2110 mapped_datav[0]);
1871 if (state->print_mask & 2111 if (state->print_mask &
1872 BTRFSIC_PRINT_MASK_TREE_AFTER_SB_WRITE) { 2112 BTRFSIC_PRINT_MASK_TREE_AFTER_SB_WRITE) {
1873 printk(KERN_INFO 2113 printk(KERN_INFO
@@ -1880,8 +2120,6 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1880 state, 2120 state,
1881 block, 2121 block,
1882 &block_ctx, 2122 &block_ctx,
1883 (struct btrfs_header *)
1884 block_ctx.data,
1885 0, 0); 2123 0, 0);
1886 } 2124 }
1887 if (ret) 2125 if (ret)
@@ -1912,26 +2150,30 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1912 u64 bytenr; 2150 u64 bytenr;
1913 2151
1914 if (!is_metadata) { 2152 if (!is_metadata) {
2153 processed_len = state->datablock_size;
1915 if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE) 2154 if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE)
1916 printk(KERN_INFO "Written block (%s/%llu/?)" 2155 printk(KERN_INFO "Written block (%s/%llu/?)"
1917 " !found in hash table, D.\n", 2156 " !found in hash table, D.\n",
1918 dev_state->name, 2157 dev_state->name,
1919 (unsigned long long)dev_bytenr); 2158 (unsigned long long)dev_bytenr);
1920 if (!state->include_extent_data) 2159 if (!state->include_extent_data) {
1921 return; /* ignore that written D block */ 2160 /* ignore that written D block */
2161 goto continue_loop;
2162 }
1922 2163
1923 /* this is getting ugly for the 2164 /* this is getting ugly for the
1924 * include_extent_data case... */ 2165 * include_extent_data case... */
1925 bytenr = 0; /* unknown */ 2166 bytenr = 0; /* unknown */
1926 block_ctx.start = bytenr; 2167 block_ctx.start = bytenr;
1927 block_ctx.len = len; 2168 block_ctx.len = processed_len;
1928 block_ctx.bh = NULL; 2169 block_ctx.mem_to_free = NULL;
2170 block_ctx.pagev = NULL;
1929 } else { 2171 } else {
2172 processed_len = state->metablock_size;
1930 bytenr = le64_to_cpu(((struct btrfs_header *) 2173 bytenr = le64_to_cpu(((struct btrfs_header *)
1931 mapped_data)->bytenr); 2174 mapped_datav[0])->bytenr);
1932 btrfsic_cmp_log_and_dev_bytenr(state, bytenr, dev_state, 2175 btrfsic_cmp_log_and_dev_bytenr(state, bytenr, dev_state,
1933 dev_bytenr, 2176 dev_bytenr);
1934 mapped_data);
1935 if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE) 2177 if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE)
1936 printk(KERN_INFO 2178 printk(KERN_INFO
1937 "Written block @%llu (%s/%llu/?)" 2179 "Written block @%llu (%s/%llu/?)"
@@ -1940,17 +2182,17 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1940 dev_state->name, 2182 dev_state->name,
1941 (unsigned long long)dev_bytenr); 2183 (unsigned long long)dev_bytenr);
1942 2184
1943 ret = btrfsic_map_block(state, bytenr, len, &block_ctx, 2185 ret = btrfsic_map_block(state, bytenr, processed_len,
1944 0); 2186 &block_ctx, 0);
1945 if (ret) { 2187 if (ret) {
1946 printk(KERN_INFO 2188 printk(KERN_INFO
1947 "btrfsic: btrfsic_map_block(root @%llu)" 2189 "btrfsic: btrfsic_map_block(root @%llu)"
1948 " failed!\n", 2190 " failed!\n",
1949 (unsigned long long)dev_bytenr); 2191 (unsigned long long)dev_bytenr);
1950 return; 2192 goto continue_loop;
1951 } 2193 }
1952 } 2194 }
1953 block_ctx.data = mapped_data; 2195 block_ctx.datav = mapped_datav;
1954 /* the following is required in case of writes to mirrors, 2196 /* the following is required in case of writes to mirrors,
1955 * use the same that was used for the lookup */ 2197 * use the same that was used for the lookup */
1956 block_ctx.dev = dev_state; 2198 block_ctx.dev = dev_state;
@@ -1960,7 +2202,7 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
1960 if (NULL == block) { 2202 if (NULL == block) {
1961 printk(KERN_INFO "btrfsic: error, kmalloc failed!\n"); 2203 printk(KERN_INFO "btrfsic: error, kmalloc failed!\n");
1962 btrfsic_release_block_ctx(&block_ctx); 2204 btrfsic_release_block_ctx(&block_ctx);
1963 return; 2205 goto continue_loop;
1964 } 2206 }
1965 block->dev_state = dev_state; 2207 block->dev_state = dev_state;
1966 block->dev_bytenr = dev_bytenr; 2208 block->dev_bytenr = dev_bytenr;
@@ -2020,9 +2262,7 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
2020 2262
2021 if (is_metadata) { 2263 if (is_metadata) {
2022 ret = btrfsic_process_metablock(state, block, 2264 ret = btrfsic_process_metablock(state, block,
2023 &block_ctx, 2265 &block_ctx, 0, 0);
2024 (struct btrfs_header *)
2025 block_ctx.data, 0, 0);
2026 if (ret) 2266 if (ret)
2027 printk(KERN_INFO 2267 printk(KERN_INFO
2028 "btrfsic: process_metablock(root @%llu)" 2268 "btrfsic: process_metablock(root @%llu)"
@@ -2031,6 +2271,13 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
2031 } 2271 }
2032 btrfsic_release_block_ctx(&block_ctx); 2272 btrfsic_release_block_ctx(&block_ctx);
2033 } 2273 }
2274
2275continue_loop:
2276 BUG_ON(!processed_len);
2277 dev_bytenr += processed_len;
2278 mapped_datav += processed_len >> PAGE_CACHE_SHIFT;
2279 num_pages -= processed_len >> PAGE_CACHE_SHIFT;
2280 goto again;
2034} 2281}
2035 2282
2036static void btrfsic_bio_end_io(struct bio *bp, int bio_error_status) 2283static void btrfsic_bio_end_io(struct bio *bp, int bio_error_status)
@@ -2213,7 +2460,7 @@ static int btrfsic_process_written_superblock(
2213 2460
2214 num_copies = 2461 num_copies =
2215 btrfs_num_copies(&state->root->fs_info->mapping_tree, 2462 btrfs_num_copies(&state->root->fs_info->mapping_tree,
2216 next_bytenr, PAGE_SIZE); 2463 next_bytenr, BTRFS_SUPER_INFO_SIZE);
2217 if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES) 2464 if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES)
2218 printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n", 2465 printk(KERN_INFO "num_copies(log_bytenr=%llu) = %d\n",
2219 (unsigned long long)next_bytenr, num_copies); 2466 (unsigned long long)next_bytenr, num_copies);
@@ -2224,7 +2471,8 @@ static int btrfsic_process_written_superblock(
2224 printk(KERN_INFO 2471 printk(KERN_INFO
2225 "btrfsic_process_written_superblock(" 2472 "btrfsic_process_written_superblock("
2226 "mirror_num=%d)\n", mirror_num); 2473 "mirror_num=%d)\n", mirror_num);
2227 ret = btrfsic_map_block(state, next_bytenr, PAGE_SIZE, 2474 ret = btrfsic_map_block(state, next_bytenr,
2475 BTRFS_SUPER_INFO_SIZE,
2228 &tmp_next_block_ctx, 2476 &tmp_next_block_ctx,
2229 mirror_num); 2477 mirror_num);
2230 if (ret) { 2478 if (ret) {
@@ -2689,7 +2937,7 @@ static struct btrfsic_block *btrfsic_block_lookup_or_add(
2689static void btrfsic_cmp_log_and_dev_bytenr(struct btrfsic_state *state, 2937static void btrfsic_cmp_log_and_dev_bytenr(struct btrfsic_state *state,
2690 u64 bytenr, 2938 u64 bytenr,
2691 struct btrfsic_dev_state *dev_state, 2939 struct btrfsic_dev_state *dev_state,
2692 u64 dev_bytenr, char *data) 2940 u64 dev_bytenr)
2693{ 2941{
2694 int num_copies; 2942 int num_copies;
2695 int mirror_num; 2943 int mirror_num;
@@ -2698,10 +2946,10 @@ static void btrfsic_cmp_log_and_dev_bytenr(struct btrfsic_state *state,
2698 int match = 0; 2946 int match = 0;
2699 2947
2700 num_copies = btrfs_num_copies(&state->root->fs_info->mapping_tree, 2948 num_copies = btrfs_num_copies(&state->root->fs_info->mapping_tree,
2701 bytenr, PAGE_SIZE); 2949 bytenr, state->metablock_size);
2702 2950
2703 for (mirror_num = 1; mirror_num <= num_copies; mirror_num++) { 2951 for (mirror_num = 1; mirror_num <= num_copies; mirror_num++) {
2704 ret = btrfsic_map_block(state, bytenr, PAGE_SIZE, 2952 ret = btrfsic_map_block(state, bytenr, state->metablock_size,
2705 &block_ctx, mirror_num); 2953 &block_ctx, mirror_num);
2706 if (ret) { 2954 if (ret) {
2707 printk(KERN_INFO "btrfsic:" 2955 printk(KERN_INFO "btrfsic:"
@@ -2727,7 +2975,8 @@ static void btrfsic_cmp_log_and_dev_bytenr(struct btrfsic_state *state,
2727 (unsigned long long)bytenr, dev_state->name, 2975 (unsigned long long)bytenr, dev_state->name,
2728 (unsigned long long)dev_bytenr); 2976 (unsigned long long)dev_bytenr);
2729 for (mirror_num = 1; mirror_num <= num_copies; mirror_num++) { 2977 for (mirror_num = 1; mirror_num <= num_copies; mirror_num++) {
2730 ret = btrfsic_map_block(state, bytenr, PAGE_SIZE, 2978 ret = btrfsic_map_block(state, bytenr,
2979 state->metablock_size,
2731 &block_ctx, mirror_num); 2980 &block_ctx, mirror_num);
2732 if (ret) 2981 if (ret)
2733 continue; 2982 continue;
@@ -2781,13 +3030,13 @@ int btrfsic_submit_bh(int rw, struct buffer_head *bh)
2781 (unsigned long)bh->b_size, bh->b_data, 3030 (unsigned long)bh->b_size, bh->b_data,
2782 bh->b_bdev); 3031 bh->b_bdev);
2783 btrfsic_process_written_block(dev_state, dev_bytenr, 3032 btrfsic_process_written_block(dev_state, dev_bytenr,
2784 bh->b_data, bh->b_size, NULL, 3033 &bh->b_data, 1, NULL,
2785 NULL, bh, rw); 3034 NULL, bh, rw);
2786 } else if (NULL != dev_state && (rw & REQ_FLUSH)) { 3035 } else if (NULL != dev_state && (rw & REQ_FLUSH)) {
2787 if (dev_state->state->print_mask & 3036 if (dev_state->state->print_mask &
2788 BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH) 3037 BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH)
2789 printk(KERN_INFO 3038 printk(KERN_INFO
2790 "submit_bh(rw=0x%x) FLUSH, bdev=%p)\n", 3039 "submit_bh(rw=0x%x FLUSH, bdev=%p)\n",
2791 rw, bh->b_bdev); 3040 rw, bh->b_bdev);
2792 if (!dev_state->dummy_block_for_bio_bh_flush.is_iodone) { 3041 if (!dev_state->dummy_block_for_bio_bh_flush.is_iodone) {
2793 if ((dev_state->state->print_mask & 3042 if ((dev_state->state->print_mask &
@@ -2836,6 +3085,7 @@ void btrfsic_submit_bio(int rw, struct bio *bio)
2836 unsigned int i; 3085 unsigned int i;
2837 u64 dev_bytenr; 3086 u64 dev_bytenr;
2838 int bio_is_patched; 3087 int bio_is_patched;
3088 char **mapped_datav;
2839 3089
2840 dev_bytenr = 512 * bio->bi_sector; 3090 dev_bytenr = 512 * bio->bi_sector;
2841 bio_is_patched = 0; 3091 bio_is_patched = 0;
@@ -2848,35 +3098,46 @@ void btrfsic_submit_bio(int rw, struct bio *bio)
2848 (unsigned long long)dev_bytenr, 3098 (unsigned long long)dev_bytenr,
2849 bio->bi_bdev); 3099 bio->bi_bdev);
2850 3100
3101 mapped_datav = kmalloc(sizeof(*mapped_datav) * bio->bi_vcnt,
3102 GFP_NOFS);
3103 if (!mapped_datav)
3104 goto leave;
2851 for (i = 0; i < bio->bi_vcnt; i++) { 3105 for (i = 0; i < bio->bi_vcnt; i++) {
2852 u8 *mapped_data; 3106 BUG_ON(bio->bi_io_vec[i].bv_len != PAGE_CACHE_SIZE);
2853 3107 mapped_datav[i] = kmap(bio->bi_io_vec[i].bv_page);
2854 mapped_data = kmap(bio->bi_io_vec[i].bv_page); 3108 if (!mapped_datav[i]) {
3109 while (i > 0) {
3110 i--;
3111 kunmap(bio->bi_io_vec[i].bv_page);
3112 }
3113 kfree(mapped_datav);
3114 goto leave;
3115 }
2855 if ((BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH | 3116 if ((BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH |
2856 BTRFSIC_PRINT_MASK_VERBOSE) == 3117 BTRFSIC_PRINT_MASK_VERBOSE) ==
2857 (dev_state->state->print_mask & 3118 (dev_state->state->print_mask &
2858 (BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH | 3119 (BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH |
2859 BTRFSIC_PRINT_MASK_VERBOSE))) 3120 BTRFSIC_PRINT_MASK_VERBOSE)))
2860 printk(KERN_INFO 3121 printk(KERN_INFO
2861 "#%u: page=%p, mapped=%p, len=%u," 3122 "#%u: page=%p, len=%u, offset=%u\n",
2862 " offset=%u\n",
2863 i, bio->bi_io_vec[i].bv_page, 3123 i, bio->bi_io_vec[i].bv_page,
2864 mapped_data,
2865 bio->bi_io_vec[i].bv_len, 3124 bio->bi_io_vec[i].bv_len,
2866 bio->bi_io_vec[i].bv_offset); 3125 bio->bi_io_vec[i].bv_offset);
2867 btrfsic_process_written_block(dev_state, dev_bytenr, 3126 }
2868 mapped_data, 3127 btrfsic_process_written_block(dev_state, dev_bytenr,
2869 bio->bi_io_vec[i].bv_len, 3128 mapped_datav, bio->bi_vcnt,
2870 bio, &bio_is_patched, 3129 bio, &bio_is_patched,
2871 NULL, rw); 3130 NULL, rw);
3131 while (i > 0) {
3132 i--;
2872 kunmap(bio->bi_io_vec[i].bv_page); 3133 kunmap(bio->bi_io_vec[i].bv_page);
2873 dev_bytenr += bio->bi_io_vec[i].bv_len;
2874 } 3134 }
3135 kfree(mapped_datav);
2875 } else if (NULL != dev_state && (rw & REQ_FLUSH)) { 3136 } else if (NULL != dev_state && (rw & REQ_FLUSH)) {
2876 if (dev_state->state->print_mask & 3137 if (dev_state->state->print_mask &
2877 BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH) 3138 BTRFSIC_PRINT_MASK_SUBMIT_BIO_BH)
2878 printk(KERN_INFO 3139 printk(KERN_INFO
2879 "submit_bio(rw=0x%x) FLUSH, bdev=%p)\n", 3140 "submit_bio(rw=0x%x FLUSH, bdev=%p)\n",
2880 rw, bio->bi_bdev); 3141 rw, bio->bi_bdev);
2881 if (!dev_state->dummy_block_for_bio_bh_flush.is_iodone) { 3142 if (!dev_state->dummy_block_for_bio_bh_flush.is_iodone) {
2882 if ((dev_state->state->print_mask & 3143 if ((dev_state->state->print_mask &
@@ -2903,6 +3164,7 @@ void btrfsic_submit_bio(int rw, struct bio *bio)
2903 bio->bi_end_io = btrfsic_bio_end_io; 3164 bio->bi_end_io = btrfsic_bio_end_io;
2904 } 3165 }
2905 } 3166 }
3167leave:
2906 mutex_unlock(&btrfsic_mutex); 3168 mutex_unlock(&btrfsic_mutex);
2907 3169
2908 submit_bio(rw, bio); 3170 submit_bio(rw, bio);
@@ -2917,6 +3179,30 @@ int btrfsic_mount(struct btrfs_root *root,
2917 struct list_head *dev_head = &fs_devices->devices; 3179 struct list_head *dev_head = &fs_devices->devices;
2918 struct btrfs_device *device; 3180 struct btrfs_device *device;
2919 3181
3182 if (root->nodesize != root->leafsize) {
3183 printk(KERN_INFO
3184 "btrfsic: cannot handle nodesize %d != leafsize %d!\n",
3185 root->nodesize, root->leafsize);
3186 return -1;
3187 }
3188 if (root->nodesize & ((u64)PAGE_CACHE_SIZE - 1)) {
3189 printk(KERN_INFO
3190 "btrfsic: cannot handle nodesize %d not being a multiple of PAGE_CACHE_SIZE %ld!\n",
3191 root->nodesize, (unsigned long)PAGE_CACHE_SIZE);
3192 return -1;
3193 }
3194 if (root->leafsize & ((u64)PAGE_CACHE_SIZE - 1)) {
3195 printk(KERN_INFO
3196 "btrfsic: cannot handle leafsize %d not being a multiple of PAGE_CACHE_SIZE %ld!\n",
3197 root->leafsize, (unsigned long)PAGE_CACHE_SIZE);
3198 return -1;
3199 }
3200 if (root->sectorsize & ((u64)PAGE_CACHE_SIZE - 1)) {
3201 printk(KERN_INFO
3202 "btrfsic: cannot handle sectorsize %d not being a multiple of PAGE_CACHE_SIZE %ld!\n",
3203 root->sectorsize, (unsigned long)PAGE_CACHE_SIZE);
3204 return -1;
3205 }
2920 state = kzalloc(sizeof(*state), GFP_NOFS); 3206 state = kzalloc(sizeof(*state), GFP_NOFS);
2921 if (NULL == state) { 3207 if (NULL == state) {
2922 printk(KERN_INFO "btrfs check-integrity: kmalloc() failed!\n"); 3208 printk(KERN_INFO "btrfs check-integrity: kmalloc() failed!\n");
@@ -2933,6 +3219,8 @@ int btrfsic_mount(struct btrfs_root *root,
2933 state->print_mask = print_mask; 3219 state->print_mask = print_mask;
2934 state->include_extent_data = including_extent_data; 3220 state->include_extent_data = including_extent_data;
2935 state->csum_size = 0; 3221 state->csum_size = 0;
3222 state->metablock_size = root->nodesize;
3223 state->datablock_size = root->sectorsize;
2936 INIT_LIST_HEAD(&state->all_blocks_list); 3224 INIT_LIST_HEAD(&state->all_blocks_list);
2937 btrfsic_block_hashtable_init(&state->block_hashtable); 3225 btrfsic_block_hashtable_init(&state->block_hashtable);
2938 btrfsic_block_link_hashtable_init(&state->block_link_hashtable); 3226 btrfsic_block_link_hashtable_init(&state->block_link_hashtable);
@@ -3049,7 +3337,7 @@ void btrfsic_unmount(struct btrfs_root *root,
3049 btrfsic_block_link_free(l); 3337 btrfsic_block_link_free(l);
3050 } 3338 }
3051 3339
3052 if (b_all->is_iodone) 3340 if (b_all->is_iodone || b_all->never_written)
3053 btrfsic_block_free(b_all); 3341 btrfsic_block_free(b_all);
3054 else 3342 else
3055 printk(KERN_INFO "btrfs: attempt to free %c-block" 3343 printk(KERN_INFO "btrfs: attempt to free %c-block"
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 4106264fbc65..d7a96cfdc50a 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -18,6 +18,7 @@
18 18
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/rbtree.h>
21#include "ctree.h" 22#include "ctree.h"
22#include "disk-io.h" 23#include "disk-io.h"
23#include "transaction.h" 24#include "transaction.h"
@@ -37,7 +38,16 @@ static int balance_node_right(struct btrfs_trans_handle *trans,
37 struct extent_buffer *dst_buf, 38 struct extent_buffer *dst_buf,
38 struct extent_buffer *src_buf); 39 struct extent_buffer *src_buf);
39static void del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root, 40static void del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root,
40 struct btrfs_path *path, int level, int slot); 41 struct btrfs_path *path, int level, int slot,
42 int tree_mod_log);
43static void tree_mod_log_free_eb(struct btrfs_fs_info *fs_info,
44 struct extent_buffer *eb);
45struct extent_buffer *read_old_tree_block(struct btrfs_root *root, u64 bytenr,
46 u32 blocksize, u64 parent_transid,
47 u64 time_seq);
48struct extent_buffer *btrfs_find_old_tree_block(struct btrfs_root *root,
49 u64 bytenr, u32 blocksize,
50 u64 time_seq);
41 51
42struct btrfs_path *btrfs_alloc_path(void) 52struct btrfs_path *btrfs_alloc_path(void)
43{ 53{
@@ -255,7 +265,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
255 265
256 cow = btrfs_alloc_free_block(trans, root, buf->len, 0, 266 cow = btrfs_alloc_free_block(trans, root, buf->len, 0,
257 new_root_objectid, &disk_key, level, 267 new_root_objectid, &disk_key, level,
258 buf->start, 0, 1); 268 buf->start, 0);
259 if (IS_ERR(cow)) 269 if (IS_ERR(cow))
260 return PTR_ERR(cow); 270 return PTR_ERR(cow);
261 271
@@ -288,6 +298,434 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
288 return 0; 298 return 0;
289} 299}
290 300
301enum mod_log_op {
302 MOD_LOG_KEY_REPLACE,
303 MOD_LOG_KEY_ADD,
304 MOD_LOG_KEY_REMOVE,
305 MOD_LOG_KEY_REMOVE_WHILE_FREEING,
306 MOD_LOG_KEY_REMOVE_WHILE_MOVING,
307 MOD_LOG_MOVE_KEYS,
308 MOD_LOG_ROOT_REPLACE,
309};
310
311struct tree_mod_move {
312 int dst_slot;
313 int nr_items;
314};
315
316struct tree_mod_root {
317 u64 logical;
318 u8 level;
319};
320
321struct tree_mod_elem {
322 struct rb_node node;
323 u64 index; /* shifted logical */
324 struct seq_list elem;
325 enum mod_log_op op;
326
327 /* this is used for MOD_LOG_KEY_* and MOD_LOG_MOVE_KEYS operations */
328 int slot;
329
330 /* this is used for MOD_LOG_KEY* and MOD_LOG_ROOT_REPLACE */
331 u64 generation;
332
333 /* those are used for op == MOD_LOG_KEY_{REPLACE,REMOVE} */
334 struct btrfs_disk_key key;
335 u64 blockptr;
336
337 /* this is used for op == MOD_LOG_MOVE_KEYS */
338 struct tree_mod_move move;
339
340 /* this is used for op == MOD_LOG_ROOT_REPLACE */
341 struct tree_mod_root old_root;
342};
343
344static inline void
345__get_tree_mod_seq(struct btrfs_fs_info *fs_info, struct seq_list *elem)
346{
347 elem->seq = atomic_inc_return(&fs_info->tree_mod_seq);
348 list_add_tail(&elem->list, &fs_info->tree_mod_seq_list);
349}
350
351void btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
352 struct seq_list *elem)
353{
354 elem->flags = 1;
355 spin_lock(&fs_info->tree_mod_seq_lock);
356 __get_tree_mod_seq(fs_info, elem);
357 spin_unlock(&fs_info->tree_mod_seq_lock);
358}
359
360void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
361 struct seq_list *elem)
362{
363 struct rb_root *tm_root;
364 struct rb_node *node;
365 struct rb_node *next;
366 struct seq_list *cur_elem;
367 struct tree_mod_elem *tm;
368 u64 min_seq = (u64)-1;
369 u64 seq_putting = elem->seq;
370
371 if (!seq_putting)
372 return;
373
374 BUG_ON(!(elem->flags & 1));
375 spin_lock(&fs_info->tree_mod_seq_lock);
376 list_del(&elem->list);
377
378 list_for_each_entry(cur_elem, &fs_info->tree_mod_seq_list, list) {
379 if ((cur_elem->flags & 1) && cur_elem->seq < min_seq) {
380 if (seq_putting > cur_elem->seq) {
381 /*
382 * blocker with lower sequence number exists, we
383 * cannot remove anything from the log
384 */
385 goto out;
386 }
387 min_seq = cur_elem->seq;
388 }
389 }
390
391 /*
392 * anything that's lower than the lowest existing (read: blocked)
393 * sequence number can be removed from the tree.
394 */
395 write_lock(&fs_info->tree_mod_log_lock);
396 tm_root = &fs_info->tree_mod_log;
397 for (node = rb_first(tm_root); node; node = next) {
398 next = rb_next(node);
399 tm = container_of(node, struct tree_mod_elem, node);
400 if (tm->elem.seq > min_seq)
401 continue;
402 rb_erase(node, tm_root);
403 list_del(&tm->elem.list);
404 kfree(tm);
405 }
406 write_unlock(&fs_info->tree_mod_log_lock);
407out:
408 spin_unlock(&fs_info->tree_mod_seq_lock);
409}
410
411/*
412 * key order of the log:
413 * index -> sequence
414 *
415 * the index is the shifted logical of the *new* root node for root replace
416 * operations, or the shifted logical of the affected block for all other
417 * operations.
418 */
419static noinline int
420__tree_mod_log_insert(struct btrfs_fs_info *fs_info, struct tree_mod_elem *tm)
421{
422 struct rb_root *tm_root;
423 struct rb_node **new;
424 struct rb_node *parent = NULL;
425 struct tree_mod_elem *cur;
426 int ret = 0;
427
428 BUG_ON(!tm || !tm->elem.seq);
429
430 write_lock(&fs_info->tree_mod_log_lock);
431 tm_root = &fs_info->tree_mod_log;
432 new = &tm_root->rb_node;
433 while (*new) {
434 cur = container_of(*new, struct tree_mod_elem, node);
435 parent = *new;
436 if (cur->index < tm->index)
437 new = &((*new)->rb_left);
438 else if (cur->index > tm->index)
439 new = &((*new)->rb_right);
440 else if (cur->elem.seq < tm->elem.seq)
441 new = &((*new)->rb_left);
442 else if (cur->elem.seq > tm->elem.seq)
443 new = &((*new)->rb_right);
444 else {
445 kfree(tm);
446 ret = -EEXIST;
447 goto unlock;
448 }
449 }
450
451 rb_link_node(&tm->node, parent, new);
452 rb_insert_color(&tm->node, tm_root);
453unlock:
454 write_unlock(&fs_info->tree_mod_log_lock);
455 return ret;
456}
457
458static inline int tree_mod_dont_log(struct btrfs_fs_info *fs_info,
459 struct extent_buffer *eb) {
460 smp_mb();
461 if (list_empty(&(fs_info)->tree_mod_seq_list))
462 return 1;
463 if (!eb)
464 return 0;
465 if (btrfs_header_level(eb) == 0)
466 return 1;
467 return 0;
468}
469
470static inline int tree_mod_alloc(struct btrfs_fs_info *fs_info, gfp_t flags,
471 struct tree_mod_elem **tm_ret)
472{
473 struct tree_mod_elem *tm;
474 int seq;
475
476 if (tree_mod_dont_log(fs_info, NULL))
477 return 0;
478
479 tm = *tm_ret = kzalloc(sizeof(*tm), flags);
480 if (!tm)
481 return -ENOMEM;
482
483 tm->elem.flags = 0;
484 spin_lock(&fs_info->tree_mod_seq_lock);
485 if (list_empty(&fs_info->tree_mod_seq_list)) {
486 /*
487 * someone emptied the list while we were waiting for the lock.
488 * we must not add to the list, because no blocker exists. items
489 * are removed from the list only when the existing blocker is
490 * removed from the list.
491 */
492 kfree(tm);
493 seq = 0;
494 } else {
495 __get_tree_mod_seq(fs_info, &tm->elem);
496 seq = tm->elem.seq;
497 }
498 spin_unlock(&fs_info->tree_mod_seq_lock);
499
500 return seq;
501}
502
503static noinline int
504tree_mod_log_insert_key_mask(struct btrfs_fs_info *fs_info,
505 struct extent_buffer *eb, int slot,
506 enum mod_log_op op, gfp_t flags)
507{
508 struct tree_mod_elem *tm;
509 int ret;
510
511 ret = tree_mod_alloc(fs_info, flags, &tm);
512 if (ret <= 0)
513 return ret;
514
515 tm->index = eb->start >> PAGE_CACHE_SHIFT;
516 if (op != MOD_LOG_KEY_ADD) {
517 btrfs_node_key(eb, &tm->key, slot);
518 tm->blockptr = btrfs_node_blockptr(eb, slot);
519 }
520 tm->op = op;
521 tm->slot = slot;
522 tm->generation = btrfs_node_ptr_generation(eb, slot);
523
524 return __tree_mod_log_insert(fs_info, tm);
525}
526
527static noinline int
528tree_mod_log_insert_key(struct btrfs_fs_info *fs_info, struct extent_buffer *eb,
529 int slot, enum mod_log_op op)
530{
531 return tree_mod_log_insert_key_mask(fs_info, eb, slot, op, GFP_NOFS);
532}
533
534static noinline int
535tree_mod_log_insert_move(struct btrfs_fs_info *fs_info,
536 struct extent_buffer *eb, int dst_slot, int src_slot,
537 int nr_items, gfp_t flags)
538{
539 struct tree_mod_elem *tm;
540 int ret;
541 int i;
542
543 if (tree_mod_dont_log(fs_info, eb))
544 return 0;
545
546 for (i = 0; i + dst_slot < src_slot && i < nr_items; i++) {
547 ret = tree_mod_log_insert_key(fs_info, eb, i + dst_slot,
548 MOD_LOG_KEY_REMOVE_WHILE_MOVING);
549 BUG_ON(ret < 0);
550 }
551
552 ret = tree_mod_alloc(fs_info, flags, &tm);
553 if (ret <= 0)
554 return ret;
555
556 tm->index = eb->start >> PAGE_CACHE_SHIFT;
557 tm->slot = src_slot;
558 tm->move.dst_slot = dst_slot;
559 tm->move.nr_items = nr_items;
560 tm->op = MOD_LOG_MOVE_KEYS;
561
562 return __tree_mod_log_insert(fs_info, tm);
563}
564
565static noinline int
566tree_mod_log_insert_root(struct btrfs_fs_info *fs_info,
567 struct extent_buffer *old_root,
568 struct extent_buffer *new_root, gfp_t flags)
569{
570 struct tree_mod_elem *tm;
571 int ret;
572
573 ret = tree_mod_alloc(fs_info, flags, &tm);
574 if (ret <= 0)
575 return ret;
576
577 tm->index = new_root->start >> PAGE_CACHE_SHIFT;
578 tm->old_root.logical = old_root->start;
579 tm->old_root.level = btrfs_header_level(old_root);
580 tm->generation = btrfs_header_generation(old_root);
581 tm->op = MOD_LOG_ROOT_REPLACE;
582
583 return __tree_mod_log_insert(fs_info, tm);
584}
585
586static struct tree_mod_elem *
587__tree_mod_log_search(struct btrfs_fs_info *fs_info, u64 start, u64 min_seq,
588 int smallest)
589{
590 struct rb_root *tm_root;
591 struct rb_node *node;
592 struct tree_mod_elem *cur = NULL;
593 struct tree_mod_elem *found = NULL;
594 u64 index = start >> PAGE_CACHE_SHIFT;
595
596 read_lock(&fs_info->tree_mod_log_lock);
597 tm_root = &fs_info->tree_mod_log;
598 node = tm_root->rb_node;
599 while (node) {
600 cur = container_of(node, struct tree_mod_elem, node);
601 if (cur->index < index) {
602 node = node->rb_left;
603 } else if (cur->index > index) {
604 node = node->rb_right;
605 } else if (cur->elem.seq < min_seq) {
606 node = node->rb_left;
607 } else if (!smallest) {
608 /* we want the node with the highest seq */
609 if (found)
610 BUG_ON(found->elem.seq > cur->elem.seq);
611 found = cur;
612 node = node->rb_left;
613 } else if (cur->elem.seq > min_seq) {
614 /* we want the node with the smallest seq */
615 if (found)
616 BUG_ON(found->elem.seq < cur->elem.seq);
617 found = cur;
618 node = node->rb_right;
619 } else {
620 found = cur;
621 break;
622 }
623 }
624 read_unlock(&fs_info->tree_mod_log_lock);
625
626 return found;
627}
628
629/*
630 * this returns the element from the log with the smallest time sequence
631 * value that's in the log (the oldest log item). any element with a time
632 * sequence lower than min_seq will be ignored.
633 */
634static struct tree_mod_elem *
635tree_mod_log_search_oldest(struct btrfs_fs_info *fs_info, u64 start,
636 u64 min_seq)
637{
638 return __tree_mod_log_search(fs_info, start, min_seq, 1);
639}
640
641/*
642 * this returns the element from the log with the largest time sequence
643 * value that's in the log (the most recent log item). any element with
644 * a time sequence lower than min_seq will be ignored.
645 */
646static struct tree_mod_elem *
647tree_mod_log_search(struct btrfs_fs_info *fs_info, u64 start, u64 min_seq)
648{
649 return __tree_mod_log_search(fs_info, start, min_seq, 0);
650}
651
652static inline void
653tree_mod_log_eb_copy(struct btrfs_fs_info *fs_info, struct extent_buffer *dst,
654 struct extent_buffer *src, unsigned long dst_offset,
655 unsigned long src_offset, int nr_items)
656{
657 int ret;
658 int i;
659
660 if (tree_mod_dont_log(fs_info, NULL))
661 return;
662
663 if (btrfs_header_level(dst) == 0 && btrfs_header_level(src) == 0)
664 return;
665
666 /* speed this up by single seq for all operations? */
667 for (i = 0; i < nr_items; i++) {
668 ret = tree_mod_log_insert_key(fs_info, src, i + src_offset,
669 MOD_LOG_KEY_REMOVE);
670 BUG_ON(ret < 0);
671 ret = tree_mod_log_insert_key(fs_info, dst, i + dst_offset,
672 MOD_LOG_KEY_ADD);
673 BUG_ON(ret < 0);
674 }
675}
676
677static inline void
678tree_mod_log_eb_move(struct btrfs_fs_info *fs_info, struct extent_buffer *dst,
679 int dst_offset, int src_offset, int nr_items)
680{
681 int ret;
682 ret = tree_mod_log_insert_move(fs_info, dst, dst_offset, src_offset,
683 nr_items, GFP_NOFS);
684 BUG_ON(ret < 0);
685}
686
687static inline void
688tree_mod_log_set_node_key(struct btrfs_fs_info *fs_info,
689 struct extent_buffer *eb,
690 struct btrfs_disk_key *disk_key, int slot, int atomic)
691{
692 int ret;
693
694 ret = tree_mod_log_insert_key_mask(fs_info, eb, slot,
695 MOD_LOG_KEY_REPLACE,
696 atomic ? GFP_ATOMIC : GFP_NOFS);
697 BUG_ON(ret < 0);
698}
699
700static void tree_mod_log_free_eb(struct btrfs_fs_info *fs_info,
701 struct extent_buffer *eb)
702{
703 int i;
704 int ret;
705 u32 nritems;
706
707 if (tree_mod_dont_log(fs_info, eb))
708 return;
709
710 nritems = btrfs_header_nritems(eb);
711 for (i = nritems - 1; i >= 0; i--) {
712 ret = tree_mod_log_insert_key(fs_info, eb, i,
713 MOD_LOG_KEY_REMOVE_WHILE_FREEING);
714 BUG_ON(ret < 0);
715 }
716}
717
718static inline void
719tree_mod_log_set_root_pointer(struct btrfs_root *root,
720 struct extent_buffer *new_root_node)
721{
722 int ret;
723 tree_mod_log_free_eb(root->fs_info, root->node);
724 ret = tree_mod_log_insert_root(root->fs_info, root->node,
725 new_root_node, GFP_NOFS);
726 BUG_ON(ret < 0);
727}
728
291/* 729/*
292 * check if the tree block can be shared by multiple trees 730 * check if the tree block can be shared by multiple trees
293 */ 731 */
@@ -409,6 +847,12 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
409 ret = btrfs_dec_ref(trans, root, buf, 1, 1); 847 ret = btrfs_dec_ref(trans, root, buf, 1, 1);
410 BUG_ON(ret); /* -ENOMEM */ 848 BUG_ON(ret); /* -ENOMEM */
411 } 849 }
850 /*
851 * don't log freeing in case we're freeing the root node, this
852 * is done by tree_mod_log_set_root_pointer later
853 */
854 if (buf != root->node && btrfs_header_level(buf) != 0)
855 tree_mod_log_free_eb(root->fs_info, buf);
412 clean_tree_block(trans, root, buf); 856 clean_tree_block(trans, root, buf);
413 *last_ref = 1; 857 *last_ref = 1;
414 } 858 }
@@ -467,7 +911,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
467 911
468 cow = btrfs_alloc_free_block(trans, root, buf->len, parent_start, 912 cow = btrfs_alloc_free_block(trans, root, buf->len, parent_start,
469 root->root_key.objectid, &disk_key, 913 root->root_key.objectid, &disk_key,
470 level, search_start, empty_size, 1); 914 level, search_start, empty_size);
471 if (IS_ERR(cow)) 915 if (IS_ERR(cow))
472 return PTR_ERR(cow); 916 return PTR_ERR(cow);
473 917
@@ -506,10 +950,11 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
506 parent_start = 0; 950 parent_start = 0;
507 951
508 extent_buffer_get(cow); 952 extent_buffer_get(cow);
953 tree_mod_log_set_root_pointer(root, cow);
509 rcu_assign_pointer(root->node, cow); 954 rcu_assign_pointer(root->node, cow);
510 955
511 btrfs_free_tree_block(trans, root, buf, parent_start, 956 btrfs_free_tree_block(trans, root, buf, parent_start,
512 last_ref, 1); 957 last_ref);
513 free_extent_buffer(buf); 958 free_extent_buffer(buf);
514 add_root_to_dirty_list(root); 959 add_root_to_dirty_list(root);
515 } else { 960 } else {
@@ -519,13 +964,15 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
519 parent_start = 0; 964 parent_start = 0;
520 965
521 WARN_ON(trans->transid != btrfs_header_generation(parent)); 966 WARN_ON(trans->transid != btrfs_header_generation(parent));
967 tree_mod_log_insert_key(root->fs_info, parent, parent_slot,
968 MOD_LOG_KEY_REPLACE);
522 btrfs_set_node_blockptr(parent, parent_slot, 969 btrfs_set_node_blockptr(parent, parent_slot,
523 cow->start); 970 cow->start);
524 btrfs_set_node_ptr_generation(parent, parent_slot, 971 btrfs_set_node_ptr_generation(parent, parent_slot,
525 trans->transid); 972 trans->transid);
526 btrfs_mark_buffer_dirty(parent); 973 btrfs_mark_buffer_dirty(parent);
527 btrfs_free_tree_block(trans, root, buf, parent_start, 974 btrfs_free_tree_block(trans, root, buf, parent_start,
528 last_ref, 1); 975 last_ref);
529 } 976 }
530 if (unlock_orig) 977 if (unlock_orig)
531 btrfs_tree_unlock(buf); 978 btrfs_tree_unlock(buf);
@@ -535,6 +982,210 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
535 return 0; 982 return 0;
536} 983}
537 984
985/*
986 * returns the logical address of the oldest predecessor of the given root.
987 * entries older than time_seq are ignored.
988 */
989static struct tree_mod_elem *
990__tree_mod_log_oldest_root(struct btrfs_fs_info *fs_info,
991 struct btrfs_root *root, u64 time_seq)
992{
993 struct tree_mod_elem *tm;
994 struct tree_mod_elem *found = NULL;
995 u64 root_logical = root->node->start;
996 int looped = 0;
997
998 if (!time_seq)
999 return 0;
1000
1001 /*
1002 * the very last operation that's logged for a root is the replacement
1003 * operation (if it is replaced at all). this has the index of the *new*
1004 * root, making it the very first operation that's logged for this root.
1005 */
1006 while (1) {
1007 tm = tree_mod_log_search_oldest(fs_info, root_logical,
1008 time_seq);
1009 if (!looped && !tm)
1010 return 0;
1011 /*
1012 * we must have key remove operations in the log before the
1013 * replace operation.
1014 */
1015 BUG_ON(!tm);
1016
1017 if (tm->op != MOD_LOG_ROOT_REPLACE)
1018 break;
1019
1020 found = tm;
1021 root_logical = tm->old_root.logical;
1022 BUG_ON(root_logical == root->node->start);
1023 looped = 1;
1024 }
1025
1026 return found;
1027}
1028
1029/*
1030 * tm is a pointer to the first operation to rewind within eb. then, all
1031 * previous operations will be rewinded (until we reach something older than
1032 * time_seq).
1033 */
1034static void
1035__tree_mod_log_rewind(struct extent_buffer *eb, u64 time_seq,
1036 struct tree_mod_elem *first_tm)
1037{
1038 u32 n;
1039 struct rb_node *next;
1040 struct tree_mod_elem *tm = first_tm;
1041 unsigned long o_dst;
1042 unsigned long o_src;
1043 unsigned long p_size = sizeof(struct btrfs_key_ptr);
1044
1045 n = btrfs_header_nritems(eb);
1046 while (tm && tm->elem.seq >= time_seq) {
1047 /*
1048 * all the operations are recorded with the operator used for
1049 * the modification. as we're going backwards, we do the
1050 * opposite of each operation here.
1051 */
1052 switch (tm->op) {
1053 case MOD_LOG_KEY_REMOVE_WHILE_FREEING:
1054 BUG_ON(tm->slot < n);
1055 case MOD_LOG_KEY_REMOVE_WHILE_MOVING:
1056 case MOD_LOG_KEY_REMOVE:
1057 btrfs_set_node_key(eb, &tm->key, tm->slot);
1058 btrfs_set_node_blockptr(eb, tm->slot, tm->blockptr);
1059 btrfs_set_node_ptr_generation(eb, tm->slot,
1060 tm->generation);
1061 n++;
1062 break;
1063 case MOD_LOG_KEY_REPLACE:
1064 BUG_ON(tm->slot >= n);
1065 btrfs_set_node_key(eb, &tm->key, tm->slot);
1066 btrfs_set_node_blockptr(eb, tm->slot, tm->blockptr);
1067 btrfs_set_node_ptr_generation(eb, tm->slot,
1068 tm->generation);
1069 break;
1070 case MOD_LOG_KEY_ADD:
1071 if (tm->slot != n - 1) {
1072 o_dst = btrfs_node_key_ptr_offset(tm->slot);
1073 o_src = btrfs_node_key_ptr_offset(tm->slot + 1);
1074 memmove_extent_buffer(eb, o_dst, o_src, p_size);
1075 }
1076 n--;
1077 break;
1078 case MOD_LOG_MOVE_KEYS:
1079 o_dst = btrfs_node_key_ptr_offset(tm->slot);
1080 o_src = btrfs_node_key_ptr_offset(tm->move.dst_slot);
1081 memmove_extent_buffer(eb, o_dst, o_src,
1082 tm->move.nr_items * p_size);
1083 break;
1084 case MOD_LOG_ROOT_REPLACE:
1085 /*
1086 * this operation is special. for roots, this must be
1087 * handled explicitly before rewinding.
1088 * for non-roots, this operation may exist if the node
1089 * was a root: root A -> child B; then A gets empty and
1090 * B is promoted to the new root. in the mod log, we'll
1091 * have a root-replace operation for B, a tree block
1092 * that is no root. we simply ignore that operation.
1093 */
1094 break;
1095 }
1096 next = rb_next(&tm->node);
1097 if (!next)
1098 break;
1099 tm = container_of(next, struct tree_mod_elem, node);
1100 if (tm->index != first_tm->index)
1101 break;
1102 }
1103 btrfs_set_header_nritems(eb, n);
1104}
1105
1106static struct extent_buffer *
1107tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct extent_buffer *eb,
1108 u64 time_seq)
1109{
1110 struct extent_buffer *eb_rewin;
1111 struct tree_mod_elem *tm;
1112
1113 if (!time_seq)
1114 return eb;
1115
1116 if (btrfs_header_level(eb) == 0)
1117 return eb;
1118
1119 tm = tree_mod_log_search(fs_info, eb->start, time_seq);
1120 if (!tm)
1121 return eb;
1122
1123 if (tm->op == MOD_LOG_KEY_REMOVE_WHILE_FREEING) {
1124 BUG_ON(tm->slot != 0);
1125 eb_rewin = alloc_dummy_extent_buffer(eb->start,
1126 fs_info->tree_root->nodesize);
1127 BUG_ON(!eb_rewin);
1128 btrfs_set_header_bytenr(eb_rewin, eb->start);
1129 btrfs_set_header_backref_rev(eb_rewin,
1130 btrfs_header_backref_rev(eb));
1131 btrfs_set_header_owner(eb_rewin, btrfs_header_owner(eb));
1132 btrfs_set_header_level(eb_rewin, btrfs_header_level(eb));
1133 } else {
1134 eb_rewin = btrfs_clone_extent_buffer(eb);
1135 BUG_ON(!eb_rewin);
1136 }
1137
1138 extent_buffer_get(eb_rewin);
1139 free_extent_buffer(eb);
1140
1141 __tree_mod_log_rewind(eb_rewin, time_seq, tm);
1142
1143 return eb_rewin;
1144}
1145
1146static inline struct extent_buffer *
1147get_old_root(struct btrfs_root *root, u64 time_seq)
1148{
1149 struct tree_mod_elem *tm;
1150 struct extent_buffer *eb;
1151 struct tree_mod_root *old_root;
1152 u64 old_generation;
1153
1154 tm = __tree_mod_log_oldest_root(root->fs_info, root, time_seq);
1155 if (!tm)
1156 return root->node;
1157
1158 old_root = &tm->old_root;
1159 old_generation = tm->generation;
1160
1161 tm = tree_mod_log_search(root->fs_info, old_root->logical, time_seq);
1162 /*
1163 * there was an item in the log when __tree_mod_log_oldest_root
1164 * returned. this one must not go away, because the time_seq passed to
1165 * us must be blocking its removal.
1166 */
1167 BUG_ON(!tm);
1168
1169 if (old_root->logical == root->node->start) {
1170 /* there are logged operations for the current root */
1171 eb = btrfs_clone_extent_buffer(root->node);
1172 } else {
1173 /* there's a root replace operation for the current root */
1174 eb = alloc_dummy_extent_buffer(tm->index << PAGE_CACHE_SHIFT,
1175 root->nodesize);
1176 btrfs_set_header_bytenr(eb, eb->start);
1177 btrfs_set_header_backref_rev(eb, BTRFS_MIXED_BACKREF_REV);
1178 btrfs_set_header_owner(eb, root->root_key.objectid);
1179 }
1180 if (!eb)
1181 return NULL;
1182 btrfs_set_header_level(eb, old_root->level);
1183 btrfs_set_header_generation(eb, old_generation);
1184 __tree_mod_log_rewind(eb, time_seq, tm);
1185
1186 return eb;
1187}
1188
538static inline int should_cow_block(struct btrfs_trans_handle *trans, 1189static inline int should_cow_block(struct btrfs_trans_handle *trans,
539 struct btrfs_root *root, 1190 struct btrfs_root *root,
540 struct extent_buffer *buf) 1191 struct extent_buffer *buf)
@@ -739,7 +1390,11 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
739 if (!cur) 1390 if (!cur)
740 return -EIO; 1391 return -EIO;
741 } else if (!uptodate) { 1392 } else if (!uptodate) {
742 btrfs_read_buffer(cur, gen); 1393 err = btrfs_read_buffer(cur, gen);
1394 if (err) {
1395 free_extent_buffer(cur);
1396 return err;
1397 }
743 } 1398 }
744 } 1399 }
745 if (search_start == 0) 1400 if (search_start == 0)
@@ -854,20 +1509,18 @@ static noinline int generic_bin_search(struct extent_buffer *eb,
854static int bin_search(struct extent_buffer *eb, struct btrfs_key *key, 1509static int bin_search(struct extent_buffer *eb, struct btrfs_key *key,
855 int level, int *slot) 1510 int level, int *slot)
856{ 1511{
857 if (level == 0) { 1512 if (level == 0)
858 return generic_bin_search(eb, 1513 return generic_bin_search(eb,
859 offsetof(struct btrfs_leaf, items), 1514 offsetof(struct btrfs_leaf, items),
860 sizeof(struct btrfs_item), 1515 sizeof(struct btrfs_item),
861 key, btrfs_header_nritems(eb), 1516 key, btrfs_header_nritems(eb),
862 slot); 1517 slot);
863 } else { 1518 else
864 return generic_bin_search(eb, 1519 return generic_bin_search(eb,
865 offsetof(struct btrfs_node, ptrs), 1520 offsetof(struct btrfs_node, ptrs),
866 sizeof(struct btrfs_key_ptr), 1521 sizeof(struct btrfs_key_ptr),
867 key, btrfs_header_nritems(eb), 1522 key, btrfs_header_nritems(eb),
868 slot); 1523 slot);
869 }
870 return -1;
871} 1524}
872 1525
873int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, 1526int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key,
@@ -974,6 +1627,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
974 goto enospc; 1627 goto enospc;
975 } 1628 }
976 1629
1630 tree_mod_log_set_root_pointer(root, child);
977 rcu_assign_pointer(root->node, child); 1631 rcu_assign_pointer(root->node, child);
978 1632
979 add_root_to_dirty_list(root); 1633 add_root_to_dirty_list(root);
@@ -987,7 +1641,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
987 free_extent_buffer(mid); 1641 free_extent_buffer(mid);
988 1642
989 root_sub_used(root, mid->len); 1643 root_sub_used(root, mid->len);
990 btrfs_free_tree_block(trans, root, mid, 0, 1, 0); 1644 btrfs_free_tree_block(trans, root, mid, 0, 1);
991 /* once for the root ptr */ 1645 /* once for the root ptr */
992 free_extent_buffer_stale(mid); 1646 free_extent_buffer_stale(mid);
993 return 0; 1647 return 0;
@@ -1040,14 +1694,16 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
1040 if (btrfs_header_nritems(right) == 0) { 1694 if (btrfs_header_nritems(right) == 0) {
1041 clean_tree_block(trans, root, right); 1695 clean_tree_block(trans, root, right);
1042 btrfs_tree_unlock(right); 1696 btrfs_tree_unlock(right);
1043 del_ptr(trans, root, path, level + 1, pslot + 1); 1697 del_ptr(trans, root, path, level + 1, pslot + 1, 1);
1044 root_sub_used(root, right->len); 1698 root_sub_used(root, right->len);
1045 btrfs_free_tree_block(trans, root, right, 0, 1, 0); 1699 btrfs_free_tree_block(trans, root, right, 0, 1);
1046 free_extent_buffer_stale(right); 1700 free_extent_buffer_stale(right);
1047 right = NULL; 1701 right = NULL;
1048 } else { 1702 } else {
1049 struct btrfs_disk_key right_key; 1703 struct btrfs_disk_key right_key;
1050 btrfs_node_key(right, &right_key, 0); 1704 btrfs_node_key(right, &right_key, 0);
1705 tree_mod_log_set_node_key(root->fs_info, parent,
1706 &right_key, pslot + 1, 0);
1051 btrfs_set_node_key(parent, &right_key, pslot + 1); 1707 btrfs_set_node_key(parent, &right_key, pslot + 1);
1052 btrfs_mark_buffer_dirty(parent); 1708 btrfs_mark_buffer_dirty(parent);
1053 } 1709 }
@@ -1082,15 +1738,17 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
1082 if (btrfs_header_nritems(mid) == 0) { 1738 if (btrfs_header_nritems(mid) == 0) {
1083 clean_tree_block(trans, root, mid); 1739 clean_tree_block(trans, root, mid);
1084 btrfs_tree_unlock(mid); 1740 btrfs_tree_unlock(mid);
1085 del_ptr(trans, root, path, level + 1, pslot); 1741 del_ptr(trans, root, path, level + 1, pslot, 1);
1086 root_sub_used(root, mid->len); 1742 root_sub_used(root, mid->len);
1087 btrfs_free_tree_block(trans, root, mid, 0, 1, 0); 1743 btrfs_free_tree_block(trans, root, mid, 0, 1);
1088 free_extent_buffer_stale(mid); 1744 free_extent_buffer_stale(mid);
1089 mid = NULL; 1745 mid = NULL;
1090 } else { 1746 } else {
1091 /* update the parent key to reflect our changes */ 1747 /* update the parent key to reflect our changes */
1092 struct btrfs_disk_key mid_key; 1748 struct btrfs_disk_key mid_key;
1093 btrfs_node_key(mid, &mid_key, 0); 1749 btrfs_node_key(mid, &mid_key, 0);
1750 tree_mod_log_set_node_key(root->fs_info, parent, &mid_key,
1751 pslot, 0);
1094 btrfs_set_node_key(parent, &mid_key, pslot); 1752 btrfs_set_node_key(parent, &mid_key, pslot);
1095 btrfs_mark_buffer_dirty(parent); 1753 btrfs_mark_buffer_dirty(parent);
1096 } 1754 }
@@ -1188,6 +1846,8 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans,
1188 struct btrfs_disk_key disk_key; 1846 struct btrfs_disk_key disk_key;
1189 orig_slot += left_nr; 1847 orig_slot += left_nr;
1190 btrfs_node_key(mid, &disk_key, 0); 1848 btrfs_node_key(mid, &disk_key, 0);
1849 tree_mod_log_set_node_key(root->fs_info, parent,
1850 &disk_key, pslot, 0);
1191 btrfs_set_node_key(parent, &disk_key, pslot); 1851 btrfs_set_node_key(parent, &disk_key, pslot);
1192 btrfs_mark_buffer_dirty(parent); 1852 btrfs_mark_buffer_dirty(parent);
1193 if (btrfs_header_nritems(left) > orig_slot) { 1853 if (btrfs_header_nritems(left) > orig_slot) {
@@ -1239,6 +1899,8 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans,
1239 struct btrfs_disk_key disk_key; 1899 struct btrfs_disk_key disk_key;
1240 1900
1241 btrfs_node_key(right, &disk_key, 0); 1901 btrfs_node_key(right, &disk_key, 0);
1902 tree_mod_log_set_node_key(root->fs_info, parent,
1903 &disk_key, pslot + 1, 0);
1242 btrfs_set_node_key(parent, &disk_key, pslot + 1); 1904 btrfs_set_node_key(parent, &disk_key, pslot + 1);
1243 btrfs_mark_buffer_dirty(parent); 1905 btrfs_mark_buffer_dirty(parent);
1244 1906
@@ -1496,7 +2158,7 @@ static int
1496read_block_for_search(struct btrfs_trans_handle *trans, 2158read_block_for_search(struct btrfs_trans_handle *trans,
1497 struct btrfs_root *root, struct btrfs_path *p, 2159 struct btrfs_root *root, struct btrfs_path *p,
1498 struct extent_buffer **eb_ret, int level, int slot, 2160 struct extent_buffer **eb_ret, int level, int slot,
1499 struct btrfs_key *key) 2161 struct btrfs_key *key, u64 time_seq)
1500{ 2162{
1501 u64 blocknr; 2163 u64 blocknr;
1502 u64 gen; 2164 u64 gen;
@@ -1850,7 +2512,7 @@ cow_done:
1850 } 2512 }
1851 2513
1852 err = read_block_for_search(trans, root, p, 2514 err = read_block_for_search(trans, root, p,
1853 &b, level, slot, key); 2515 &b, level, slot, key, 0);
1854 if (err == -EAGAIN) 2516 if (err == -EAGAIN)
1855 goto again; 2517 goto again;
1856 if (err) { 2518 if (err) {
@@ -1922,6 +2584,115 @@ done:
1922} 2584}
1923 2585
1924/* 2586/*
2587 * Like btrfs_search_slot, this looks for a key in the given tree. It uses the
2588 * current state of the tree together with the operations recorded in the tree
2589 * modification log to search for the key in a previous version of this tree, as
2590 * denoted by the time_seq parameter.
2591 *
2592 * Naturally, there is no support for insert, delete or cow operations.
2593 *
2594 * The resulting path and return value will be set up as if we called
2595 * btrfs_search_slot at that point in time with ins_len and cow both set to 0.
2596 */
2597int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key,
2598 struct btrfs_path *p, u64 time_seq)
2599{
2600 struct extent_buffer *b;
2601 int slot;
2602 int ret;
2603 int err;
2604 int level;
2605 int lowest_unlock = 1;
2606 u8 lowest_level = 0;
2607
2608 lowest_level = p->lowest_level;
2609 WARN_ON(p->nodes[0] != NULL);
2610
2611 if (p->search_commit_root) {
2612 BUG_ON(time_seq);
2613 return btrfs_search_slot(NULL, root, key, p, 0, 0);
2614 }
2615
2616again:
2617 b = get_old_root(root, time_seq);
2618 extent_buffer_get(b);
2619 level = btrfs_header_level(b);
2620 btrfs_tree_read_lock(b);
2621 p->locks[level] = BTRFS_READ_LOCK;
2622
2623 while (b) {
2624 level = btrfs_header_level(b);
2625 p->nodes[level] = b;
2626 btrfs_clear_path_blocking(p, NULL, 0);
2627
2628 /*
2629 * we have a lock on b and as long as we aren't changing
2630 * the tree, there is no way to for the items in b to change.
2631 * It is safe to drop the lock on our parent before we
2632 * go through the expensive btree search on b.
2633 */
2634 btrfs_unlock_up_safe(p, level + 1);
2635
2636 ret = bin_search(b, key, level, &slot);
2637
2638 if (level != 0) {
2639 int dec = 0;
2640 if (ret && slot > 0) {
2641 dec = 1;
2642 slot -= 1;
2643 }
2644 p->slots[level] = slot;
2645 unlock_up(p, level, lowest_unlock, 0, NULL);
2646
2647 if (level == lowest_level) {
2648 if (dec)
2649 p->slots[level]++;
2650 goto done;
2651 }
2652
2653 err = read_block_for_search(NULL, root, p, &b, level,
2654 slot, key, time_seq);
2655 if (err == -EAGAIN)
2656 goto again;
2657 if (err) {
2658 ret = err;
2659 goto done;
2660 }
2661
2662 level = btrfs_header_level(b);
2663 err = btrfs_try_tree_read_lock(b);
2664 if (!err) {
2665 btrfs_set_path_blocking(p);
2666 btrfs_tree_read_lock(b);
2667 btrfs_clear_path_blocking(p, b,
2668 BTRFS_READ_LOCK);
2669 }
2670 p->locks[level] = BTRFS_READ_LOCK;
2671 p->nodes[level] = b;
2672 b = tree_mod_log_rewind(root->fs_info, b, time_seq);
2673 if (b != p->nodes[level]) {
2674 btrfs_tree_unlock_rw(p->nodes[level],
2675 p->locks[level]);
2676 p->locks[level] = 0;
2677 p->nodes[level] = b;
2678 }
2679 } else {
2680 p->slots[level] = slot;
2681 unlock_up(p, level, lowest_unlock, 0, NULL);
2682 goto done;
2683 }
2684 }
2685 ret = 1;
2686done:
2687 if (!p->leave_spinning)
2688 btrfs_set_path_blocking(p);
2689 if (ret < 0)
2690 btrfs_release_path(p);
2691
2692 return ret;
2693}
2694
2695/*
1925 * adjust the pointers going up the tree, starting at level 2696 * adjust the pointers going up the tree, starting at level
1926 * making sure the right key of each node is points to 'key'. 2697 * making sure the right key of each node is points to 'key'.
1927 * This is used after shifting pointers to the left, so it stops 2698 * This is used after shifting pointers to the left, so it stops
@@ -1941,6 +2712,7 @@ static void fixup_low_keys(struct btrfs_trans_handle *trans,
1941 if (!path->nodes[i]) 2712 if (!path->nodes[i])
1942 break; 2713 break;
1943 t = path->nodes[i]; 2714 t = path->nodes[i];
2715 tree_mod_log_set_node_key(root->fs_info, t, key, tslot, 1);
1944 btrfs_set_node_key(t, key, tslot); 2716 btrfs_set_node_key(t, key, tslot);
1945 btrfs_mark_buffer_dirty(path->nodes[i]); 2717 btrfs_mark_buffer_dirty(path->nodes[i]);
1946 if (tslot != 0) 2718 if (tslot != 0)
@@ -2023,12 +2795,16 @@ static int push_node_left(struct btrfs_trans_handle *trans,
2023 } else 2795 } else
2024 push_items = min(src_nritems - 8, push_items); 2796 push_items = min(src_nritems - 8, push_items);
2025 2797
2798 tree_mod_log_eb_copy(root->fs_info, dst, src, dst_nritems, 0,
2799 push_items);
2026 copy_extent_buffer(dst, src, 2800 copy_extent_buffer(dst, src,
2027 btrfs_node_key_ptr_offset(dst_nritems), 2801 btrfs_node_key_ptr_offset(dst_nritems),
2028 btrfs_node_key_ptr_offset(0), 2802 btrfs_node_key_ptr_offset(0),
2029 push_items * sizeof(struct btrfs_key_ptr)); 2803 push_items * sizeof(struct btrfs_key_ptr));
2030 2804
2031 if (push_items < src_nritems) { 2805 if (push_items < src_nritems) {
2806 tree_mod_log_eb_move(root->fs_info, src, 0, push_items,
2807 src_nritems - push_items);
2032 memmove_extent_buffer(src, btrfs_node_key_ptr_offset(0), 2808 memmove_extent_buffer(src, btrfs_node_key_ptr_offset(0),
2033 btrfs_node_key_ptr_offset(push_items), 2809 btrfs_node_key_ptr_offset(push_items),
2034 (src_nritems - push_items) * 2810 (src_nritems - push_items) *
@@ -2082,11 +2858,14 @@ static int balance_node_right(struct btrfs_trans_handle *trans,
2082 if (max_push < push_items) 2858 if (max_push < push_items)
2083 push_items = max_push; 2859 push_items = max_push;
2084 2860
2861 tree_mod_log_eb_move(root->fs_info, dst, push_items, 0, dst_nritems);
2085 memmove_extent_buffer(dst, btrfs_node_key_ptr_offset(push_items), 2862 memmove_extent_buffer(dst, btrfs_node_key_ptr_offset(push_items),
2086 btrfs_node_key_ptr_offset(0), 2863 btrfs_node_key_ptr_offset(0),
2087 (dst_nritems) * 2864 (dst_nritems) *
2088 sizeof(struct btrfs_key_ptr)); 2865 sizeof(struct btrfs_key_ptr));
2089 2866
2867 tree_mod_log_eb_copy(root->fs_info, dst, src, 0,
2868 src_nritems - push_items, push_items);
2090 copy_extent_buffer(dst, src, 2869 copy_extent_buffer(dst, src,
2091 btrfs_node_key_ptr_offset(0), 2870 btrfs_node_key_ptr_offset(0),
2092 btrfs_node_key_ptr_offset(src_nritems - push_items), 2871 btrfs_node_key_ptr_offset(src_nritems - push_items),
@@ -2129,7 +2908,7 @@ static noinline int insert_new_root(struct btrfs_trans_handle *trans,
2129 2908
2130 c = btrfs_alloc_free_block(trans, root, root->nodesize, 0, 2909 c = btrfs_alloc_free_block(trans, root, root->nodesize, 0,
2131 root->root_key.objectid, &lower_key, 2910 root->root_key.objectid, &lower_key,
2132 level, root->node->start, 0, 0); 2911 level, root->node->start, 0);
2133 if (IS_ERR(c)) 2912 if (IS_ERR(c))
2134 return PTR_ERR(c); 2913 return PTR_ERR(c);
2135 2914
@@ -2161,6 +2940,7 @@ static noinline int insert_new_root(struct btrfs_trans_handle *trans,
2161 btrfs_mark_buffer_dirty(c); 2940 btrfs_mark_buffer_dirty(c);
2162 2941
2163 old = root->node; 2942 old = root->node;
2943 tree_mod_log_set_root_pointer(root, c);
2164 rcu_assign_pointer(root->node, c); 2944 rcu_assign_pointer(root->node, c);
2165 2945
2166 /* the super has an extra ref to root->node */ 2946 /* the super has an extra ref to root->node */
@@ -2184,10 +2964,11 @@ static noinline int insert_new_root(struct btrfs_trans_handle *trans,
2184static void insert_ptr(struct btrfs_trans_handle *trans, 2964static void insert_ptr(struct btrfs_trans_handle *trans,
2185 struct btrfs_root *root, struct btrfs_path *path, 2965 struct btrfs_root *root, struct btrfs_path *path,
2186 struct btrfs_disk_key *key, u64 bytenr, 2966 struct btrfs_disk_key *key, u64 bytenr,
2187 int slot, int level) 2967 int slot, int level, int tree_mod_log)
2188{ 2968{
2189 struct extent_buffer *lower; 2969 struct extent_buffer *lower;
2190 int nritems; 2970 int nritems;
2971 int ret;
2191 2972
2192 BUG_ON(!path->nodes[level]); 2973 BUG_ON(!path->nodes[level]);
2193 btrfs_assert_tree_locked(path->nodes[level]); 2974 btrfs_assert_tree_locked(path->nodes[level]);
@@ -2196,11 +2977,19 @@ static void insert_ptr(struct btrfs_trans_handle *trans,
2196 BUG_ON(slot > nritems); 2977 BUG_ON(slot > nritems);
2197 BUG_ON(nritems == BTRFS_NODEPTRS_PER_BLOCK(root)); 2978 BUG_ON(nritems == BTRFS_NODEPTRS_PER_BLOCK(root));
2198 if (slot != nritems) { 2979 if (slot != nritems) {
2980 if (tree_mod_log && level)
2981 tree_mod_log_eb_move(root->fs_info, lower, slot + 1,
2982 slot, nritems - slot);
2199 memmove_extent_buffer(lower, 2983 memmove_extent_buffer(lower,
2200 btrfs_node_key_ptr_offset(slot + 1), 2984 btrfs_node_key_ptr_offset(slot + 1),
2201 btrfs_node_key_ptr_offset(slot), 2985 btrfs_node_key_ptr_offset(slot),
2202 (nritems - slot) * sizeof(struct btrfs_key_ptr)); 2986 (nritems - slot) * sizeof(struct btrfs_key_ptr));
2203 } 2987 }
2988 if (tree_mod_log && level) {
2989 ret = tree_mod_log_insert_key(root->fs_info, lower, slot,
2990 MOD_LOG_KEY_ADD);
2991 BUG_ON(ret < 0);
2992 }
2204 btrfs_set_node_key(lower, key, slot); 2993 btrfs_set_node_key(lower, key, slot);
2205 btrfs_set_node_blockptr(lower, slot, bytenr); 2994 btrfs_set_node_blockptr(lower, slot, bytenr);
2206 WARN_ON(trans->transid == 0); 2995 WARN_ON(trans->transid == 0);
@@ -2252,7 +3041,7 @@ static noinline int split_node(struct btrfs_trans_handle *trans,
2252 3041
2253 split = btrfs_alloc_free_block(trans, root, root->nodesize, 0, 3042 split = btrfs_alloc_free_block(trans, root, root->nodesize, 0,
2254 root->root_key.objectid, 3043 root->root_key.objectid,
2255 &disk_key, level, c->start, 0, 0); 3044 &disk_key, level, c->start, 0);
2256 if (IS_ERR(split)) 3045 if (IS_ERR(split))
2257 return PTR_ERR(split); 3046 return PTR_ERR(split);
2258 3047
@@ -2271,7 +3060,7 @@ static noinline int split_node(struct btrfs_trans_handle *trans,
2271 (unsigned long)btrfs_header_chunk_tree_uuid(split), 3060 (unsigned long)btrfs_header_chunk_tree_uuid(split),
2272 BTRFS_UUID_SIZE); 3061 BTRFS_UUID_SIZE);
2273 3062
2274 3063 tree_mod_log_eb_copy(root->fs_info, split, c, 0, mid, c_nritems - mid);
2275 copy_extent_buffer(split, c, 3064 copy_extent_buffer(split, c,
2276 btrfs_node_key_ptr_offset(0), 3065 btrfs_node_key_ptr_offset(0),
2277 btrfs_node_key_ptr_offset(mid), 3066 btrfs_node_key_ptr_offset(mid),
@@ -2284,7 +3073,7 @@ static noinline int split_node(struct btrfs_trans_handle *trans,
2284 btrfs_mark_buffer_dirty(split); 3073 btrfs_mark_buffer_dirty(split);
2285 3074
2286 insert_ptr(trans, root, path, &disk_key, split->start, 3075 insert_ptr(trans, root, path, &disk_key, split->start,
2287 path->slots[level + 1] + 1, level + 1); 3076 path->slots[level + 1] + 1, level + 1, 1);
2288 3077
2289 if (path->slots[level] >= mid) { 3078 if (path->slots[level] >= mid) {
2290 path->slots[level] -= mid; 3079 path->slots[level] -= mid;
@@ -2821,7 +3610,7 @@ static noinline void copy_for_split(struct btrfs_trans_handle *trans,
2821 btrfs_set_header_nritems(l, mid); 3610 btrfs_set_header_nritems(l, mid);
2822 btrfs_item_key(right, &disk_key, 0); 3611 btrfs_item_key(right, &disk_key, 0);
2823 insert_ptr(trans, root, path, &disk_key, right->start, 3612 insert_ptr(trans, root, path, &disk_key, right->start,
2824 path->slots[1] + 1, 1); 3613 path->slots[1] + 1, 1, 0);
2825 3614
2826 btrfs_mark_buffer_dirty(right); 3615 btrfs_mark_buffer_dirty(right);
2827 btrfs_mark_buffer_dirty(l); 3616 btrfs_mark_buffer_dirty(l);
@@ -3004,7 +3793,7 @@ again:
3004 3793
3005 right = btrfs_alloc_free_block(trans, root, root->leafsize, 0, 3794 right = btrfs_alloc_free_block(trans, root, root->leafsize, 0,
3006 root->root_key.objectid, 3795 root->root_key.objectid,
3007 &disk_key, 0, l->start, 0, 0); 3796 &disk_key, 0, l->start, 0);
3008 if (IS_ERR(right)) 3797 if (IS_ERR(right))
3009 return PTR_ERR(right); 3798 return PTR_ERR(right);
3010 3799
@@ -3028,7 +3817,7 @@ again:
3028 if (mid <= slot) { 3817 if (mid <= slot) {
3029 btrfs_set_header_nritems(right, 0); 3818 btrfs_set_header_nritems(right, 0);
3030 insert_ptr(trans, root, path, &disk_key, right->start, 3819 insert_ptr(trans, root, path, &disk_key, right->start,
3031 path->slots[1] + 1, 1); 3820 path->slots[1] + 1, 1, 0);
3032 btrfs_tree_unlock(path->nodes[0]); 3821 btrfs_tree_unlock(path->nodes[0]);
3033 free_extent_buffer(path->nodes[0]); 3822 free_extent_buffer(path->nodes[0]);
3034 path->nodes[0] = right; 3823 path->nodes[0] = right;
@@ -3037,7 +3826,7 @@ again:
3037 } else { 3826 } else {
3038 btrfs_set_header_nritems(right, 0); 3827 btrfs_set_header_nritems(right, 0);
3039 insert_ptr(trans, root, path, &disk_key, right->start, 3828 insert_ptr(trans, root, path, &disk_key, right->start,
3040 path->slots[1], 1); 3829 path->slots[1], 1, 0);
3041 btrfs_tree_unlock(path->nodes[0]); 3830 btrfs_tree_unlock(path->nodes[0]);
3042 free_extent_buffer(path->nodes[0]); 3831 free_extent_buffer(path->nodes[0]);
3043 path->nodes[0] = right; 3832 path->nodes[0] = right;
@@ -3749,19 +4538,29 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
3749 * empty a node. 4538 * empty a node.
3750 */ 4539 */
3751static void del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root, 4540static void del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root,
3752 struct btrfs_path *path, int level, int slot) 4541 struct btrfs_path *path, int level, int slot,
4542 int tree_mod_log)
3753{ 4543{
3754 struct extent_buffer *parent = path->nodes[level]; 4544 struct extent_buffer *parent = path->nodes[level];
3755 u32 nritems; 4545 u32 nritems;
4546 int ret;
3756 4547
3757 nritems = btrfs_header_nritems(parent); 4548 nritems = btrfs_header_nritems(parent);
3758 if (slot != nritems - 1) { 4549 if (slot != nritems - 1) {
4550 if (tree_mod_log && level)
4551 tree_mod_log_eb_move(root->fs_info, parent, slot,
4552 slot + 1, nritems - slot - 1);
3759 memmove_extent_buffer(parent, 4553 memmove_extent_buffer(parent,
3760 btrfs_node_key_ptr_offset(slot), 4554 btrfs_node_key_ptr_offset(slot),
3761 btrfs_node_key_ptr_offset(slot + 1), 4555 btrfs_node_key_ptr_offset(slot + 1),
3762 sizeof(struct btrfs_key_ptr) * 4556 sizeof(struct btrfs_key_ptr) *
3763 (nritems - slot - 1)); 4557 (nritems - slot - 1));
4558 } else if (tree_mod_log && level) {
4559 ret = tree_mod_log_insert_key(root->fs_info, parent, slot,
4560 MOD_LOG_KEY_REMOVE);
4561 BUG_ON(ret < 0);
3764 } 4562 }
4563
3765 nritems--; 4564 nritems--;
3766 btrfs_set_header_nritems(parent, nritems); 4565 btrfs_set_header_nritems(parent, nritems);
3767 if (nritems == 0 && parent == root->node) { 4566 if (nritems == 0 && parent == root->node) {
@@ -3793,7 +4592,7 @@ static noinline void btrfs_del_leaf(struct btrfs_trans_handle *trans,
3793 struct extent_buffer *leaf) 4592 struct extent_buffer *leaf)
3794{ 4593{
3795 WARN_ON(btrfs_header_generation(leaf) != trans->transid); 4594 WARN_ON(btrfs_header_generation(leaf) != trans->transid);
3796 del_ptr(trans, root, path, 1, path->slots[1]); 4595 del_ptr(trans, root, path, 1, path->slots[1], 1);
3797 4596
3798 /* 4597 /*
3799 * btrfs_free_extent is expensive, we want to make sure we 4598 * btrfs_free_extent is expensive, we want to make sure we
@@ -3804,7 +4603,7 @@ static noinline void btrfs_del_leaf(struct btrfs_trans_handle *trans,
3804 root_sub_used(root, leaf->len); 4603 root_sub_used(root, leaf->len);
3805 4604
3806 extent_buffer_get(leaf); 4605 extent_buffer_get(leaf);
3807 btrfs_free_tree_block(trans, root, leaf, 0, 1, 0); 4606 btrfs_free_tree_block(trans, root, leaf, 0, 1);
3808 free_extent_buffer_stale(leaf); 4607 free_extent_buffer_stale(leaf);
3809} 4608}
3810/* 4609/*
@@ -4271,7 +5070,7 @@ again:
4271 next = c; 5070 next = c;
4272 next_rw_lock = path->locks[level]; 5071 next_rw_lock = path->locks[level];
4273 ret = read_block_for_search(NULL, root, path, &next, level, 5072 ret = read_block_for_search(NULL, root, path, &next, level,
4274 slot, &key); 5073 slot, &key, 0);
4275 if (ret == -EAGAIN) 5074 if (ret == -EAGAIN)
4276 goto again; 5075 goto again;
4277 5076
@@ -4308,7 +5107,7 @@ again:
4308 break; 5107 break;
4309 5108
4310 ret = read_block_for_search(NULL, root, path, &next, level, 5109 ret = read_block_for_search(NULL, root, path, &next, level,
4311 0, &key); 5110 0, &key, 0);
4312 if (ret == -EAGAIN) 5111 if (ret == -EAGAIN)
4313 goto again; 5112 goto again;
4314 5113
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 8fd72331d600..0236d03c6732 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -173,6 +173,9 @@ static int btrfs_csum_sizes[] = { 4, 0 };
173#define BTRFS_FT_XATTR 8 173#define BTRFS_FT_XATTR 8
174#define BTRFS_FT_MAX 9 174#define BTRFS_FT_MAX 9
175 175
176/* ioprio of readahead is set to idle */
177#define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0))
178
176/* 179/*
177 * The key defines the order in the tree, and so it also defines (optimal) 180 * The key defines the order in the tree, and so it also defines (optimal)
178 * block layout. 181 * block layout.
@@ -823,6 +826,14 @@ struct btrfs_csum_item {
823 u8 csum; 826 u8 csum;
824} __attribute__ ((__packed__)); 827} __attribute__ ((__packed__));
825 828
829struct btrfs_dev_stats_item {
830 /*
831 * grow this item struct at the end for future enhancements and keep
832 * the existing values unchanged
833 */
834 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
835} __attribute__ ((__packed__));
836
826/* different types of block groups (and chunks) */ 837/* different types of block groups (and chunks) */
827#define BTRFS_BLOCK_GROUP_DATA (1ULL << 0) 838#define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
828#define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1) 839#define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
@@ -1129,6 +1140,15 @@ struct btrfs_fs_info {
1129 spinlock_t delayed_iput_lock; 1140 spinlock_t delayed_iput_lock;
1130 struct list_head delayed_iputs; 1141 struct list_head delayed_iputs;
1131 1142
1143 /* this protects tree_mod_seq_list */
1144 spinlock_t tree_mod_seq_lock;
1145 atomic_t tree_mod_seq;
1146 struct list_head tree_mod_seq_list;
1147
1148 /* this protects tree_mod_log */
1149 rwlock_t tree_mod_log_lock;
1150 struct rb_root tree_mod_log;
1151
1132 atomic_t nr_async_submits; 1152 atomic_t nr_async_submits;
1133 atomic_t async_submit_draining; 1153 atomic_t async_submit_draining;
1134 atomic_t nr_async_bios; 1154 atomic_t nr_async_bios;
@@ -1375,7 +1395,7 @@ struct btrfs_root {
1375 struct list_head root_list; 1395 struct list_head root_list;
1376 1396
1377 spinlock_t orphan_lock; 1397 spinlock_t orphan_lock;
1378 struct list_head orphan_list; 1398 atomic_t orphan_inodes;
1379 struct btrfs_block_rsv *orphan_block_rsv; 1399 struct btrfs_block_rsv *orphan_block_rsv;
1380 int orphan_item_inserted; 1400 int orphan_item_inserted;
1381 int orphan_cleanup_state; 1401 int orphan_cleanup_state;
@@ -1508,6 +1528,12 @@ struct btrfs_ioctl_defrag_range_args {
1508#define BTRFS_BALANCE_ITEM_KEY 248 1528#define BTRFS_BALANCE_ITEM_KEY 248
1509 1529
1510/* 1530/*
1531 * Persistantly stores the io stats in the device tree.
1532 * One key for all stats, (0, BTRFS_DEV_STATS_KEY, devid).
1533 */
1534#define BTRFS_DEV_STATS_KEY 249
1535
1536/*
1511 * string items are for debugging. They just store a short string of 1537 * string items are for debugging. They just store a short string of
1512 * data in the FS 1538 * data in the FS
1513 */ 1539 */
@@ -2415,6 +2441,30 @@ static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
2415 return btrfs_item_size(eb, e) - offset; 2441 return btrfs_item_size(eb, e) - offset;
2416} 2442}
2417 2443
2444/* btrfs_dev_stats_item */
2445static inline u64 btrfs_dev_stats_value(struct extent_buffer *eb,
2446 struct btrfs_dev_stats_item *ptr,
2447 int index)
2448{
2449 u64 val;
2450
2451 read_extent_buffer(eb, &val,
2452 offsetof(struct btrfs_dev_stats_item, values) +
2453 ((unsigned long)ptr) + (index * sizeof(u64)),
2454 sizeof(val));
2455 return val;
2456}
2457
2458static inline void btrfs_set_dev_stats_value(struct extent_buffer *eb,
2459 struct btrfs_dev_stats_item *ptr,
2460 int index, u64 val)
2461{
2462 write_extent_buffer(eb, &val,
2463 offsetof(struct btrfs_dev_stats_item, values) +
2464 ((unsigned long)ptr) + (index * sizeof(u64)),
2465 sizeof(val));
2466}
2467
2418static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) 2468static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb)
2419{ 2469{
2420 return sb->s_fs_info; 2470 return sb->s_fs_info;
@@ -2496,11 +2546,11 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
2496 struct btrfs_root *root, u32 blocksize, 2546 struct btrfs_root *root, u32 blocksize,
2497 u64 parent, u64 root_objectid, 2547 u64 parent, u64 root_objectid,
2498 struct btrfs_disk_key *key, int level, 2548 struct btrfs_disk_key *key, int level,
2499 u64 hint, u64 empty_size, int for_cow); 2549 u64 hint, u64 empty_size);
2500void btrfs_free_tree_block(struct btrfs_trans_handle *trans, 2550void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
2501 struct btrfs_root *root, 2551 struct btrfs_root *root,
2502 struct extent_buffer *buf, 2552 struct extent_buffer *buf,
2503 u64 parent, int last_ref, int for_cow); 2553 u64 parent, int last_ref);
2504struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans, 2554struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans,
2505 struct btrfs_root *root, 2555 struct btrfs_root *root,
2506 u64 bytenr, u32 blocksize, 2556 u64 bytenr, u32 blocksize,
@@ -2659,6 +2709,8 @@ int btrfs_duplicate_item(struct btrfs_trans_handle *trans,
2659int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root 2709int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
2660 *root, struct btrfs_key *key, struct btrfs_path *p, int 2710 *root, struct btrfs_key *key, struct btrfs_path *p, int
2661 ins_len, int cow); 2711 ins_len, int cow);
2712int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key,
2713 struct btrfs_path *p, u64 time_seq);
2662int btrfs_realloc_node(struct btrfs_trans_handle *trans, 2714int btrfs_realloc_node(struct btrfs_trans_handle *trans,
2663 struct btrfs_root *root, struct extent_buffer *parent, 2715 struct btrfs_root *root, struct extent_buffer *parent,
2664 int start_slot, int cache_only, u64 *last_ret, 2716 int start_slot, int cache_only, u64 *last_ret,
@@ -2922,7 +2974,6 @@ int btrfs_readpage(struct file *file, struct page *page);
2922void btrfs_evict_inode(struct inode *inode); 2974void btrfs_evict_inode(struct inode *inode);
2923int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc); 2975int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc);
2924int btrfs_dirty_inode(struct inode *inode); 2976int btrfs_dirty_inode(struct inode *inode);
2925int btrfs_update_time(struct file *file);
2926struct inode *btrfs_alloc_inode(struct super_block *sb); 2977struct inode *btrfs_alloc_inode(struct super_block *sb);
2927void btrfs_destroy_inode(struct inode *inode); 2978void btrfs_destroy_inode(struct inode *inode);
2928int btrfs_drop_inode(struct inode *inode); 2979int btrfs_drop_inode(struct inode *inode);
@@ -3098,4 +3149,23 @@ void btrfs_reada_detach(void *handle);
3098int btree_readahead_hook(struct btrfs_root *root, struct extent_buffer *eb, 3149int btree_readahead_hook(struct btrfs_root *root, struct extent_buffer *eb,
3099 u64 start, int err); 3150 u64 start, int err);
3100 3151
3152/* delayed seq elem */
3153struct seq_list {
3154 struct list_head list;
3155 u64 seq;
3156 u32 flags;
3157};
3158
3159void btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
3160 struct seq_list *elem);
3161void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
3162 struct seq_list *elem);
3163
3164static inline int is_fstree(u64 rootid)
3165{
3166 if (rootid == BTRFS_FS_TREE_OBJECTID ||
3167 (s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID)
3168 return 1;
3169 return 0;
3170}
3101#endif 3171#endif
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 03e3748d84d0..c18d0442ae6d 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -669,8 +669,8 @@ static int btrfs_delayed_inode_reserve_metadata(
669 return ret; 669 return ret;
670 } else if (src_rsv == &root->fs_info->delalloc_block_rsv) { 670 } else if (src_rsv == &root->fs_info->delalloc_block_rsv) {
671 spin_lock(&BTRFS_I(inode)->lock); 671 spin_lock(&BTRFS_I(inode)->lock);
672 if (BTRFS_I(inode)->delalloc_meta_reserved) { 672 if (test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
673 BTRFS_I(inode)->delalloc_meta_reserved = 0; 673 &BTRFS_I(inode)->runtime_flags)) {
674 spin_unlock(&BTRFS_I(inode)->lock); 674 spin_unlock(&BTRFS_I(inode)->lock);
675 release = true; 675 release = true;
676 goto migrate; 676 goto migrate;
@@ -1706,7 +1706,7 @@ static void fill_stack_inode_item(struct btrfs_trans_handle *trans,
1706 btrfs_set_stack_inode_nbytes(inode_item, inode_get_bytes(inode)); 1706 btrfs_set_stack_inode_nbytes(inode_item, inode_get_bytes(inode));
1707 btrfs_set_stack_inode_generation(inode_item, 1707 btrfs_set_stack_inode_generation(inode_item,
1708 BTRFS_I(inode)->generation); 1708 BTRFS_I(inode)->generation);
1709 btrfs_set_stack_inode_sequence(inode_item, BTRFS_I(inode)->sequence); 1709 btrfs_set_stack_inode_sequence(inode_item, inode->i_version);
1710 btrfs_set_stack_inode_transid(inode_item, trans->transid); 1710 btrfs_set_stack_inode_transid(inode_item, trans->transid);
1711 btrfs_set_stack_inode_rdev(inode_item, inode->i_rdev); 1711 btrfs_set_stack_inode_rdev(inode_item, inode->i_rdev);
1712 btrfs_set_stack_inode_flags(inode_item, BTRFS_I(inode)->flags); 1712 btrfs_set_stack_inode_flags(inode_item, BTRFS_I(inode)->flags);
@@ -1754,7 +1754,7 @@ int btrfs_fill_inode(struct inode *inode, u32 *rdev)
1754 set_nlink(inode, btrfs_stack_inode_nlink(inode_item)); 1754 set_nlink(inode, btrfs_stack_inode_nlink(inode_item));
1755 inode_set_bytes(inode, btrfs_stack_inode_nbytes(inode_item)); 1755 inode_set_bytes(inode, btrfs_stack_inode_nbytes(inode_item));
1756 BTRFS_I(inode)->generation = btrfs_stack_inode_generation(inode_item); 1756 BTRFS_I(inode)->generation = btrfs_stack_inode_generation(inode_item);
1757 BTRFS_I(inode)->sequence = btrfs_stack_inode_sequence(inode_item); 1757 inode->i_version = btrfs_stack_inode_sequence(inode_item);
1758 inode->i_rdev = 0; 1758 inode->i_rdev = 0;
1759 *rdev = btrfs_stack_inode_rdev(inode_item); 1759 *rdev = btrfs_stack_inode_rdev(inode_item);
1760 BTRFS_I(inode)->flags = btrfs_stack_inode_flags(inode_item); 1760 BTRFS_I(inode)->flags = btrfs_stack_inode_flags(inode_item);
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index 69f22e3ab3bc..13ae7b04790e 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -525,7 +525,7 @@ static noinline void add_delayed_tree_ref(struct btrfs_fs_info *fs_info,
525 ref->is_head = 0; 525 ref->is_head = 0;
526 ref->in_tree = 1; 526 ref->in_tree = 1;
527 527
528 if (need_ref_seq(for_cow, ref_root)) 528 if (is_fstree(ref_root))
529 seq = inc_delayed_seq(delayed_refs); 529 seq = inc_delayed_seq(delayed_refs);
530 ref->seq = seq; 530 ref->seq = seq;
531 531
@@ -584,7 +584,7 @@ static noinline void add_delayed_data_ref(struct btrfs_fs_info *fs_info,
584 ref->is_head = 0; 584 ref->is_head = 0;
585 ref->in_tree = 1; 585 ref->in_tree = 1;
586 586
587 if (need_ref_seq(for_cow, ref_root)) 587 if (is_fstree(ref_root))
588 seq = inc_delayed_seq(delayed_refs); 588 seq = inc_delayed_seq(delayed_refs);
589 ref->seq = seq; 589 ref->seq = seq;
590 590
@@ -658,10 +658,11 @@ int btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info,
658 add_delayed_tree_ref(fs_info, trans, &ref->node, bytenr, 658 add_delayed_tree_ref(fs_info, trans, &ref->node, bytenr,
659 num_bytes, parent, ref_root, level, action, 659 num_bytes, parent, ref_root, level, action,
660 for_cow); 660 for_cow);
661 if (!need_ref_seq(for_cow, ref_root) && 661 if (!is_fstree(ref_root) &&
662 waitqueue_active(&delayed_refs->seq_wait)) 662 waitqueue_active(&delayed_refs->seq_wait))
663 wake_up(&delayed_refs->seq_wait); 663 wake_up(&delayed_refs->seq_wait);
664 spin_unlock(&delayed_refs->lock); 664 spin_unlock(&delayed_refs->lock);
665
665 return 0; 666 return 0;
666} 667}
667 668
@@ -706,10 +707,11 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
706 add_delayed_data_ref(fs_info, trans, &ref->node, bytenr, 707 add_delayed_data_ref(fs_info, trans, &ref->node, bytenr,
707 num_bytes, parent, ref_root, owner, offset, 708 num_bytes, parent, ref_root, owner, offset,
708 action, for_cow); 709 action, for_cow);
709 if (!need_ref_seq(for_cow, ref_root) && 710 if (!is_fstree(ref_root) &&
710 waitqueue_active(&delayed_refs->seq_wait)) 711 waitqueue_active(&delayed_refs->seq_wait))
711 wake_up(&delayed_refs->seq_wait); 712 wake_up(&delayed_refs->seq_wait);
712 spin_unlock(&delayed_refs->lock); 713 spin_unlock(&delayed_refs->lock);
714
713 return 0; 715 return 0;
714} 716}
715 717
diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
index d8f244d94925..413927fb9957 100644
--- a/fs/btrfs/delayed-ref.h
+++ b/fs/btrfs/delayed-ref.h
@@ -195,11 +195,6 @@ int btrfs_delayed_ref_lock(struct btrfs_trans_handle *trans,
195int btrfs_find_ref_cluster(struct btrfs_trans_handle *trans, 195int btrfs_find_ref_cluster(struct btrfs_trans_handle *trans,
196 struct list_head *cluster, u64 search_start); 196 struct list_head *cluster, u64 search_start);
197 197
198struct seq_list {
199 struct list_head list;
200 u64 seq;
201};
202
203static inline u64 inc_delayed_seq(struct btrfs_delayed_ref_root *delayed_refs) 198static inline u64 inc_delayed_seq(struct btrfs_delayed_ref_root *delayed_refs)
204{ 199{
205 assert_spin_locked(&delayed_refs->lock); 200 assert_spin_locked(&delayed_refs->lock);
@@ -230,25 +225,6 @@ int btrfs_check_delayed_seq(struct btrfs_delayed_ref_root *delayed_refs,
230 u64 seq); 225 u64 seq);
231 226
232/* 227/*
233 * delayed refs with a ref_seq > 0 must be held back during backref walking.
234 * this only applies to items in one of the fs-trees. for_cow items never need
235 * to be held back, so they won't get a ref_seq number.
236 */
237static inline int need_ref_seq(int for_cow, u64 rootid)
238{
239 if (for_cow)
240 return 0;
241
242 if (rootid == BTRFS_FS_TREE_OBJECTID)
243 return 1;
244
245 if ((s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID)
246 return 1;
247
248 return 0;
249}
250
251/*
252 * a node might live in a head or a regular ref, this lets you 228 * a node might live in a head or a regular ref, this lets you
253 * test for the proper type to use. 229 * test for the proper type to use.
254 */ 230 */
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index e1fe74a2ce16..7ae51decf6d3 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1153,7 +1153,6 @@ static void __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
1153 root->orphan_block_rsv = NULL; 1153 root->orphan_block_rsv = NULL;
1154 1154
1155 INIT_LIST_HEAD(&root->dirty_list); 1155 INIT_LIST_HEAD(&root->dirty_list);
1156 INIT_LIST_HEAD(&root->orphan_list);
1157 INIT_LIST_HEAD(&root->root_list); 1156 INIT_LIST_HEAD(&root->root_list);
1158 spin_lock_init(&root->orphan_lock); 1157 spin_lock_init(&root->orphan_lock);
1159 spin_lock_init(&root->inode_lock); 1158 spin_lock_init(&root->inode_lock);
@@ -1166,6 +1165,7 @@ static void __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
1166 atomic_set(&root->log_commit[0], 0); 1165 atomic_set(&root->log_commit[0], 0);
1167 atomic_set(&root->log_commit[1], 0); 1166 atomic_set(&root->log_commit[1], 0);
1168 atomic_set(&root->log_writers, 0); 1167 atomic_set(&root->log_writers, 0);
1168 atomic_set(&root->orphan_inodes, 0);
1169 root->log_batch = 0; 1169 root->log_batch = 0;
1170 root->log_transid = 0; 1170 root->log_transid = 0;
1171 root->last_log_commit = 0; 1171 root->last_log_commit = 0;
@@ -1252,7 +1252,7 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1252 1252
1253 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 0, 1253 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 0,
1254 BTRFS_TREE_LOG_OBJECTID, NULL, 1254 BTRFS_TREE_LOG_OBJECTID, NULL,
1255 0, 0, 0, 0); 1255 0, 0, 0);
1256 if (IS_ERR(leaf)) { 1256 if (IS_ERR(leaf)) {
1257 kfree(root); 1257 kfree(root);
1258 return ERR_CAST(leaf); 1258 return ERR_CAST(leaf);
@@ -1914,11 +1914,14 @@ int open_ctree(struct super_block *sb,
1914 spin_lock_init(&fs_info->delayed_iput_lock); 1914 spin_lock_init(&fs_info->delayed_iput_lock);
1915 spin_lock_init(&fs_info->defrag_inodes_lock); 1915 spin_lock_init(&fs_info->defrag_inodes_lock);
1916 spin_lock_init(&fs_info->free_chunk_lock); 1916 spin_lock_init(&fs_info->free_chunk_lock);
1917 spin_lock_init(&fs_info->tree_mod_seq_lock);
1918 rwlock_init(&fs_info->tree_mod_log_lock);
1917 mutex_init(&fs_info->reloc_mutex); 1919 mutex_init(&fs_info->reloc_mutex);
1918 1920
1919 init_completion(&fs_info->kobj_unregister); 1921 init_completion(&fs_info->kobj_unregister);
1920 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots); 1922 INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots);
1921 INIT_LIST_HEAD(&fs_info->space_info); 1923 INIT_LIST_HEAD(&fs_info->space_info);
1924 INIT_LIST_HEAD(&fs_info->tree_mod_seq_list);
1922 btrfs_mapping_init(&fs_info->mapping_tree); 1925 btrfs_mapping_init(&fs_info->mapping_tree);
1923 btrfs_init_block_rsv(&fs_info->global_block_rsv); 1926 btrfs_init_block_rsv(&fs_info->global_block_rsv);
1924 btrfs_init_block_rsv(&fs_info->delalloc_block_rsv); 1927 btrfs_init_block_rsv(&fs_info->delalloc_block_rsv);
@@ -1931,12 +1934,14 @@ int open_ctree(struct super_block *sb,
1931 atomic_set(&fs_info->async_submit_draining, 0); 1934 atomic_set(&fs_info->async_submit_draining, 0);
1932 atomic_set(&fs_info->nr_async_bios, 0); 1935 atomic_set(&fs_info->nr_async_bios, 0);
1933 atomic_set(&fs_info->defrag_running, 0); 1936 atomic_set(&fs_info->defrag_running, 0);
1937 atomic_set(&fs_info->tree_mod_seq, 0);
1934 fs_info->sb = sb; 1938 fs_info->sb = sb;
1935 fs_info->max_inline = 8192 * 1024; 1939 fs_info->max_inline = 8192 * 1024;
1936 fs_info->metadata_ratio = 0; 1940 fs_info->metadata_ratio = 0;
1937 fs_info->defrag_inodes = RB_ROOT; 1941 fs_info->defrag_inodes = RB_ROOT;
1938 fs_info->trans_no_join = 0; 1942 fs_info->trans_no_join = 0;
1939 fs_info->free_chunk_space = 0; 1943 fs_info->free_chunk_space = 0;
1944 fs_info->tree_mod_log = RB_ROOT;
1940 1945
1941 /* readahead state */ 1946 /* readahead state */
1942 INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT); 1947 INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT);
@@ -2001,7 +2006,8 @@ int open_ctree(struct super_block *sb,
2001 BTRFS_I(fs_info->btree_inode)->root = tree_root; 2006 BTRFS_I(fs_info->btree_inode)->root = tree_root;
2002 memset(&BTRFS_I(fs_info->btree_inode)->location, 0, 2007 memset(&BTRFS_I(fs_info->btree_inode)->location, 0,
2003 sizeof(struct btrfs_key)); 2008 sizeof(struct btrfs_key));
2004 BTRFS_I(fs_info->btree_inode)->dummy_inode = 1; 2009 set_bit(BTRFS_INODE_DUMMY,
2010 &BTRFS_I(fs_info->btree_inode)->runtime_flags);
2005 insert_inode_hash(fs_info->btree_inode); 2011 insert_inode_hash(fs_info->btree_inode);
2006 2012
2007 spin_lock_init(&fs_info->block_group_cache_lock); 2013 spin_lock_init(&fs_info->block_group_cache_lock);
@@ -2353,6 +2359,13 @@ retry_root_backup:
2353 fs_info->generation = generation; 2359 fs_info->generation = generation;
2354 fs_info->last_trans_committed = generation; 2360 fs_info->last_trans_committed = generation;
2355 2361
2362 ret = btrfs_init_dev_stats(fs_info);
2363 if (ret) {
2364 printk(KERN_ERR "btrfs: failed to init dev_stats: %d\n",
2365 ret);
2366 goto fail_block_groups;
2367 }
2368
2356 ret = btrfs_init_space_info(fs_info); 2369 ret = btrfs_init_space_info(fs_info);
2357 if (ret) { 2370 if (ret) {
2358 printk(KERN_ERR "Failed to initial space info: %d\n", ret); 2371 printk(KERN_ERR "Failed to initial space info: %d\n", ret);
@@ -2556,18 +2569,19 @@ recovery_tree_root:
2556 2569
2557static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate) 2570static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate)
2558{ 2571{
2559 char b[BDEVNAME_SIZE];
2560
2561 if (uptodate) { 2572 if (uptodate) {
2562 set_buffer_uptodate(bh); 2573 set_buffer_uptodate(bh);
2563 } else { 2574 } else {
2575 struct btrfs_device *device = (struct btrfs_device *)
2576 bh->b_private;
2577
2564 printk_ratelimited(KERN_WARNING "lost page write due to " 2578 printk_ratelimited(KERN_WARNING "lost page write due to "
2565 "I/O error on %s\n", 2579 "I/O error on %s\n", device->name);
2566 bdevname(bh->b_bdev, b));
2567 /* note, we dont' set_buffer_write_io_error because we have 2580 /* note, we dont' set_buffer_write_io_error because we have
2568 * our own ways of dealing with the IO errors 2581 * our own ways of dealing with the IO errors
2569 */ 2582 */
2570 clear_buffer_uptodate(bh); 2583 clear_buffer_uptodate(bh);
2584 btrfs_dev_stat_inc_and_print(device, BTRFS_DEV_STAT_WRITE_ERRS);
2571 } 2585 }
2572 unlock_buffer(bh); 2586 unlock_buffer(bh);
2573 put_bh(bh); 2587 put_bh(bh);
@@ -2682,6 +2696,7 @@ static int write_dev_supers(struct btrfs_device *device,
2682 set_buffer_uptodate(bh); 2696 set_buffer_uptodate(bh);
2683 lock_buffer(bh); 2697 lock_buffer(bh);
2684 bh->b_end_io = btrfs_end_buffer_write_sync; 2698 bh->b_end_io = btrfs_end_buffer_write_sync;
2699 bh->b_private = device;
2685 } 2700 }
2686 2701
2687 /* 2702 /*
@@ -2740,6 +2755,9 @@ static int write_dev_flush(struct btrfs_device *device, int wait)
2740 } 2755 }
2741 if (!bio_flagged(bio, BIO_UPTODATE)) { 2756 if (!bio_flagged(bio, BIO_UPTODATE)) {
2742 ret = -EIO; 2757 ret = -EIO;
2758 if (!bio_flagged(bio, BIO_EOPNOTSUPP))
2759 btrfs_dev_stat_inc_and_print(device,
2760 BTRFS_DEV_STAT_FLUSH_ERRS);
2743 } 2761 }
2744 2762
2745 /* drop the reference from the wait == 0 run */ 2763 /* drop the reference from the wait == 0 run */
@@ -2902,19 +2920,6 @@ int write_ctree_super(struct btrfs_trans_handle *trans,
2902 return ret; 2920 return ret;
2903} 2921}
2904 2922
2905/* Kill all outstanding I/O */
2906void btrfs_abort_devices(struct btrfs_root *root)
2907{
2908 struct list_head *head;
2909 struct btrfs_device *dev;
2910 mutex_lock(&root->fs_info->fs_devices->device_list_mutex);
2911 head = &root->fs_info->fs_devices->devices;
2912 list_for_each_entry_rcu(dev, head, dev_list) {
2913 blk_abort_queue(dev->bdev->bd_disk->queue);
2914 }
2915 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
2916}
2917
2918void btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root) 2923void btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
2919{ 2924{
2920 spin_lock(&fs_info->fs_roots_radix_lock); 2925 spin_lock(&fs_info->fs_roots_radix_lock);
@@ -3671,17 +3676,6 @@ int btrfs_cleanup_transaction(struct btrfs_root *root)
3671 return 0; 3676 return 0;
3672} 3677}
3673 3678
3674static int btree_writepage_io_failed_hook(struct bio *bio, struct page *page,
3675 u64 start, u64 end,
3676 struct extent_state *state)
3677{
3678 struct super_block *sb = page->mapping->host->i_sb;
3679 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
3680 btrfs_error(fs_info, -EIO,
3681 "Error occured while writing out btree at %llu", start);
3682 return -EIO;
3683}
3684
3685static struct extent_io_ops btree_extent_io_ops = { 3679static struct extent_io_ops btree_extent_io_ops = {
3686 .write_cache_pages_lock_hook = btree_lock_page_hook, 3680 .write_cache_pages_lock_hook = btree_lock_page_hook,
3687 .readpage_end_io_hook = btree_readpage_end_io_hook, 3681 .readpage_end_io_hook = btree_readpage_end_io_hook,
@@ -3689,5 +3683,4 @@ static struct extent_io_ops btree_extent_io_ops = {
3689 .submit_bio_hook = btree_submit_bio_hook, 3683 .submit_bio_hook = btree_submit_bio_hook,
3690 /* note we're sharing with inode.c for the merge bio hook */ 3684 /* note we're sharing with inode.c for the merge bio hook */
3691 .merge_bio_hook = btrfs_merge_bio_hook, 3685 .merge_bio_hook = btrfs_merge_bio_hook,
3692 .writepage_io_failed_hook = btree_writepage_io_failed_hook,
3693}; 3686};
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index ab1830aaf0ed..05b3fab39f7e 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -89,7 +89,6 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
89int btrfs_cleanup_transaction(struct btrfs_root *root); 89int btrfs_cleanup_transaction(struct btrfs_root *root);
90void btrfs_cleanup_one_transaction(struct btrfs_transaction *trans, 90void btrfs_cleanup_one_transaction(struct btrfs_transaction *trans,
91 struct btrfs_root *root); 91 struct btrfs_root *root);
92void btrfs_abort_devices(struct btrfs_root *root);
93 92
94#ifdef CONFIG_DEBUG_LOCK_ALLOC 93#ifdef CONFIG_DEBUG_LOCK_ALLOC
95void btrfs_init_lockdep(void); 94void btrfs_init_lockdep(void);
diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c
index e887ee62b6d4..614f34a899c2 100644
--- a/fs/btrfs/export.c
+++ b/fs/btrfs/export.c
@@ -13,15 +13,14 @@
13 parent_root_objectid) / 4) 13 parent_root_objectid) / 4)
14#define BTRFS_FID_SIZE_CONNECTABLE_ROOT (sizeof(struct btrfs_fid) / 4) 14#define BTRFS_FID_SIZE_CONNECTABLE_ROOT (sizeof(struct btrfs_fid) / 4)
15 15
16static int btrfs_encode_fh(struct dentry *dentry, u32 *fh, int *max_len, 16static int btrfs_encode_fh(struct inode *inode, u32 *fh, int *max_len,
17 int connectable) 17 struct inode *parent)
18{ 18{
19 struct btrfs_fid *fid = (struct btrfs_fid *)fh; 19 struct btrfs_fid *fid = (struct btrfs_fid *)fh;
20 struct inode *inode = dentry->d_inode;
21 int len = *max_len; 20 int len = *max_len;
22 int type; 21 int type;
23 22
24 if (connectable && (len < BTRFS_FID_SIZE_CONNECTABLE)) { 23 if (parent && (len < BTRFS_FID_SIZE_CONNECTABLE)) {
25 *max_len = BTRFS_FID_SIZE_CONNECTABLE; 24 *max_len = BTRFS_FID_SIZE_CONNECTABLE;
26 return 255; 25 return 255;
27 } else if (len < BTRFS_FID_SIZE_NON_CONNECTABLE) { 26 } else if (len < BTRFS_FID_SIZE_NON_CONNECTABLE) {
@@ -36,19 +35,13 @@ static int btrfs_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
36 fid->root_objectid = BTRFS_I(inode)->root->objectid; 35 fid->root_objectid = BTRFS_I(inode)->root->objectid;
37 fid->gen = inode->i_generation; 36 fid->gen = inode->i_generation;
38 37
39 if (connectable && !S_ISDIR(inode->i_mode)) { 38 if (parent) {
40 struct inode *parent;
41 u64 parent_root_id; 39 u64 parent_root_id;
42 40
43 spin_lock(&dentry->d_lock);
44
45 parent = dentry->d_parent->d_inode;
46 fid->parent_objectid = BTRFS_I(parent)->location.objectid; 41 fid->parent_objectid = BTRFS_I(parent)->location.objectid;
47 fid->parent_gen = parent->i_generation; 42 fid->parent_gen = parent->i_generation;
48 parent_root_id = BTRFS_I(parent)->root->objectid; 43 parent_root_id = BTRFS_I(parent)->root->objectid;
49 44
50 spin_unlock(&dentry->d_lock);
51
52 if (parent_root_id != fid->root_objectid) { 45 if (parent_root_id != fid->root_objectid) {
53 fid->parent_root_objectid = parent_root_id; 46 fid->parent_root_objectid = parent_root_id;
54 len = BTRFS_FID_SIZE_CONNECTABLE_ROOT; 47 len = BTRFS_FID_SIZE_CONNECTABLE_ROOT;
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 49fd7b66d57b..4b5a1e1bdefb 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3578,7 +3578,7 @@ again:
3578 space_info->chunk_alloc = 0; 3578 space_info->chunk_alloc = 0;
3579 spin_unlock(&space_info->lock); 3579 spin_unlock(&space_info->lock);
3580out: 3580out:
3581 mutex_unlock(&extent_root->fs_info->chunk_mutex); 3581 mutex_unlock(&fs_info->chunk_mutex);
3582 return ret; 3582 return ret;
3583} 3583}
3584 3584
@@ -4355,10 +4355,9 @@ static unsigned drop_outstanding_extent(struct inode *inode)
4355 BTRFS_I(inode)->outstanding_extents--; 4355 BTRFS_I(inode)->outstanding_extents--;
4356 4356
4357 if (BTRFS_I(inode)->outstanding_extents == 0 && 4357 if (BTRFS_I(inode)->outstanding_extents == 0 &&
4358 BTRFS_I(inode)->delalloc_meta_reserved) { 4358 test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
4359 &BTRFS_I(inode)->runtime_flags))
4359 drop_inode_space = 1; 4360 drop_inode_space = 1;
4360 BTRFS_I(inode)->delalloc_meta_reserved = 0;
4361 }
4362 4361
4363 /* 4362 /*
4364 * If we have more or the same amount of outsanding extents than we have 4363 * If we have more or the same amount of outsanding extents than we have
@@ -4465,7 +4464,8 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
4465 * Add an item to reserve for updating the inode when we complete the 4464 * Add an item to reserve for updating the inode when we complete the
4466 * delalloc io. 4465 * delalloc io.
4467 */ 4466 */
4468 if (!BTRFS_I(inode)->delalloc_meta_reserved) { 4467 if (!test_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
4468 &BTRFS_I(inode)->runtime_flags)) {
4469 nr_extents++; 4469 nr_extents++;
4470 extra_reserve = 1; 4470 extra_reserve = 1;
4471 } 4471 }
@@ -4511,7 +4511,8 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
4511 4511
4512 spin_lock(&BTRFS_I(inode)->lock); 4512 spin_lock(&BTRFS_I(inode)->lock);
4513 if (extra_reserve) { 4513 if (extra_reserve) {
4514 BTRFS_I(inode)->delalloc_meta_reserved = 1; 4514 set_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
4515 &BTRFS_I(inode)->runtime_flags);
4515 nr_extents--; 4516 nr_extents--;
4516 } 4517 }
4517 BTRFS_I(inode)->reserved_extents += nr_extents; 4518 BTRFS_I(inode)->reserved_extents += nr_extents;
@@ -5217,7 +5218,7 @@ out:
5217void btrfs_free_tree_block(struct btrfs_trans_handle *trans, 5218void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
5218 struct btrfs_root *root, 5219 struct btrfs_root *root,
5219 struct extent_buffer *buf, 5220 struct extent_buffer *buf,
5220 u64 parent, int last_ref, int for_cow) 5221 u64 parent, int last_ref)
5221{ 5222{
5222 struct btrfs_block_group_cache *cache = NULL; 5223 struct btrfs_block_group_cache *cache = NULL;
5223 int ret; 5224 int ret;
@@ -5227,7 +5228,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
5227 buf->start, buf->len, 5228 buf->start, buf->len,
5228 parent, root->root_key.objectid, 5229 parent, root->root_key.objectid,
5229 btrfs_header_level(buf), 5230 btrfs_header_level(buf),
5230 BTRFS_DROP_DELAYED_REF, NULL, for_cow); 5231 BTRFS_DROP_DELAYED_REF, NULL, 0);
5231 BUG_ON(ret); /* -ENOMEM */ 5232 BUG_ON(ret); /* -ENOMEM */
5232 } 5233 }
5233 5234
@@ -6249,7 +6250,7 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
6249 struct btrfs_root *root, u32 blocksize, 6250 struct btrfs_root *root, u32 blocksize,
6250 u64 parent, u64 root_objectid, 6251 u64 parent, u64 root_objectid,
6251 struct btrfs_disk_key *key, int level, 6252 struct btrfs_disk_key *key, int level,
6252 u64 hint, u64 empty_size, int for_cow) 6253 u64 hint, u64 empty_size)
6253{ 6254{
6254 struct btrfs_key ins; 6255 struct btrfs_key ins;
6255 struct btrfs_block_rsv *block_rsv; 6256 struct btrfs_block_rsv *block_rsv;
@@ -6297,7 +6298,7 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
6297 ins.objectid, 6298 ins.objectid,
6298 ins.offset, parent, root_objectid, 6299 ins.offset, parent, root_objectid,
6299 level, BTRFS_ADD_DELAYED_EXTENT, 6300 level, BTRFS_ADD_DELAYED_EXTENT,
6300 extent_op, for_cow); 6301 extent_op, 0);
6301 BUG_ON(ret); /* -ENOMEM */ 6302 BUG_ON(ret); /* -ENOMEM */
6302 } 6303 }
6303 return buf; 6304 return buf;
@@ -6715,7 +6716,7 @@ static noinline int walk_up_proc(struct btrfs_trans_handle *trans,
6715 btrfs_header_owner(path->nodes[level + 1])); 6716 btrfs_header_owner(path->nodes[level + 1]));
6716 } 6717 }
6717 6718
6718 btrfs_free_tree_block(trans, root, eb, parent, wc->refs[level] == 1, 0); 6719 btrfs_free_tree_block(trans, root, eb, parent, wc->refs[level] == 1);
6719out: 6720out:
6720 wc->refs[level] = 0; 6721 wc->refs[level] = 0;
6721 wc->flags[level] = 0; 6722 wc->flags[level] = 0;
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index c9018a05036e..2c8f7b204617 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -186,7 +186,6 @@ static struct rb_node *tree_insert(struct rb_root *root, u64 offset,
186 return parent; 186 return parent;
187 } 187 }
188 188
189 entry = rb_entry(node, struct tree_entry, rb_node);
190 rb_link_node(node, parent, p); 189 rb_link_node(node, parent, p);
191 rb_insert_color(node, root); 190 rb_insert_color(node, root);
192 return NULL; 191 return NULL;
@@ -413,7 +412,7 @@ static struct extent_state *next_state(struct extent_state *state)
413 412
414/* 413/*
415 * utility function to clear some bits in an extent state struct. 414 * utility function to clear some bits in an extent state struct.
416 * it will optionally wake up any one waiting on this state (wake == 1) 415 * it will optionally wake up any one waiting on this state (wake == 1).
417 * 416 *
418 * If no bits are set on the state struct after clearing things, the 417 * If no bits are set on the state struct after clearing things, the
419 * struct is freed and removed from the tree 418 * struct is freed and removed from the tree
@@ -570,10 +569,8 @@ hit_next:
570 if (err) 569 if (err)
571 goto out; 570 goto out;
572 if (state->end <= end) { 571 if (state->end <= end) {
573 clear_state_bit(tree, state, &bits, wake); 572 state = clear_state_bit(tree, state, &bits, wake);
574 if (last_end == (u64)-1) 573 goto next;
575 goto out;
576 start = last_end + 1;
577 } 574 }
578 goto search_again; 575 goto search_again;
579 } 576 }
@@ -781,7 +778,6 @@ hit_next:
781 * Just lock what we found and keep going 778 * Just lock what we found and keep going
782 */ 779 */
783 if (state->start == start && state->end <= end) { 780 if (state->start == start && state->end <= end) {
784 struct rb_node *next_node;
785 if (state->state & exclusive_bits) { 781 if (state->state & exclusive_bits) {
786 *failed_start = state->start; 782 *failed_start = state->start;
787 err = -EEXIST; 783 err = -EEXIST;
@@ -789,20 +785,15 @@ hit_next:
789 } 785 }
790 786
791 set_state_bits(tree, state, &bits); 787 set_state_bits(tree, state, &bits);
792
793 cache_state(state, cached_state); 788 cache_state(state, cached_state);
794 merge_state(tree, state); 789 merge_state(tree, state);
795 if (last_end == (u64)-1) 790 if (last_end == (u64)-1)
796 goto out; 791 goto out;
797
798 start = last_end + 1; 792 start = last_end + 1;
799 next_node = rb_next(&state->rb_node); 793 state = next_state(state);
800 if (next_node && start < end && prealloc && !need_resched()) { 794 if (start < end && state && state->start == start &&
801 state = rb_entry(next_node, struct extent_state, 795 !need_resched())
802 rb_node); 796 goto hit_next;
803 if (state->start == start)
804 goto hit_next;
805 }
806 goto search_again; 797 goto search_again;
807 } 798 }
808 799
@@ -845,6 +836,10 @@ hit_next:
845 if (last_end == (u64)-1) 836 if (last_end == (u64)-1)
846 goto out; 837 goto out;
847 start = last_end + 1; 838 start = last_end + 1;
839 state = next_state(state);
840 if (start < end && state && state->start == start &&
841 !need_resched())
842 goto hit_next;
848 } 843 }
849 goto search_again; 844 goto search_again;
850 } 845 }
@@ -994,21 +989,14 @@ hit_next:
994 * Just lock what we found and keep going 989 * Just lock what we found and keep going
995 */ 990 */
996 if (state->start == start && state->end <= end) { 991 if (state->start == start && state->end <= end) {
997 struct rb_node *next_node;
998
999 set_state_bits(tree, state, &bits); 992 set_state_bits(tree, state, &bits);
1000 clear_state_bit(tree, state, &clear_bits, 0); 993 state = clear_state_bit(tree, state, &clear_bits, 0);
1001 if (last_end == (u64)-1) 994 if (last_end == (u64)-1)
1002 goto out; 995 goto out;
1003
1004 start = last_end + 1; 996 start = last_end + 1;
1005 next_node = rb_next(&state->rb_node); 997 if (start < end && state && state->start == start &&
1006 if (next_node && start < end && prealloc && !need_resched()) { 998 !need_resched())
1007 state = rb_entry(next_node, struct extent_state, 999 goto hit_next;
1008 rb_node);
1009 if (state->start == start)
1010 goto hit_next;
1011 }
1012 goto search_again; 1000 goto search_again;
1013 } 1001 }
1014 1002
@@ -1042,10 +1030,13 @@ hit_next:
1042 goto out; 1030 goto out;
1043 if (state->end <= end) { 1031 if (state->end <= end) {
1044 set_state_bits(tree, state, &bits); 1032 set_state_bits(tree, state, &bits);
1045 clear_state_bit(tree, state, &clear_bits, 0); 1033 state = clear_state_bit(tree, state, &clear_bits, 0);
1046 if (last_end == (u64)-1) 1034 if (last_end == (u64)-1)
1047 goto out; 1035 goto out;
1048 start = last_end + 1; 1036 start = last_end + 1;
1037 if (start < end && state && state->start == start &&
1038 !need_resched())
1039 goto hit_next;
1049 } 1040 }
1050 goto search_again; 1041 goto search_again;
1051 } 1042 }
@@ -1173,9 +1164,8 @@ int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
1173 cached_state, mask); 1164 cached_state, mask);
1174} 1165}
1175 1166
1176static int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, 1167int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
1177 u64 end, struct extent_state **cached_state, 1168 struct extent_state **cached_state, gfp_t mask)
1178 gfp_t mask)
1179{ 1169{
1180 return clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, 0, 1170 return clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, 0,
1181 cached_state, mask); 1171 cached_state, mask);
@@ -1293,7 +1283,7 @@ out:
1293 * returned if we find something, and *start_ret and *end_ret are 1283 * returned if we find something, and *start_ret and *end_ret are
1294 * set to reflect the state struct that was found. 1284 * set to reflect the state struct that was found.
1295 * 1285 *
1296 * If nothing was found, 1 is returned, < 0 on error 1286 * If nothing was found, 1 is returned. If found something, return 0.
1297 */ 1287 */
1298int find_first_extent_bit(struct extent_io_tree *tree, u64 start, 1288int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
1299 u64 *start_ret, u64 *end_ret, int bits) 1289 u64 *start_ret, u64 *end_ret, int bits)
@@ -1923,6 +1913,7 @@ int repair_io_failure(struct btrfs_mapping_tree *map_tree, u64 start,
1923 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) { 1913 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) {
1924 /* try to remap that extent elsewhere? */ 1914 /* try to remap that extent elsewhere? */
1925 bio_put(bio); 1915 bio_put(bio);
1916 btrfs_dev_stat_inc_and_print(dev, BTRFS_DEV_STAT_WRITE_ERRS);
1926 return -EIO; 1917 return -EIO;
1927 } 1918 }
1928 1919
@@ -2222,17 +2213,7 @@ int end_extent_writepage(struct page *page, int err, u64 start, u64 end)
2222 uptodate = 0; 2213 uptodate = 0;
2223 } 2214 }
2224 2215
2225 if (!uptodate && tree->ops &&
2226 tree->ops->writepage_io_failed_hook) {
2227 ret = tree->ops->writepage_io_failed_hook(NULL, page,
2228 start, end, NULL);
2229 /* Writeback already completed */
2230 if (ret == 0)
2231 return 1;
2232 }
2233
2234 if (!uptodate) { 2216 if (!uptodate) {
2235 clear_extent_uptodate(tree, start, end, NULL, GFP_NOFS);
2236 ClearPageUptodate(page); 2217 ClearPageUptodate(page);
2237 SetPageError(page); 2218 SetPageError(page);
2238 } 2219 }
@@ -2347,10 +2328,23 @@ static void end_bio_extent_readpage(struct bio *bio, int err)
2347 if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) { 2328 if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) {
2348 ret = tree->ops->readpage_end_io_hook(page, start, end, 2329 ret = tree->ops->readpage_end_io_hook(page, start, end,
2349 state, mirror); 2330 state, mirror);
2350 if (ret) 2331 if (ret) {
2332 /* no IO indicated but software detected errors
2333 * in the block, either checksum errors or
2334 * issues with the contents */
2335 struct btrfs_root *root =
2336 BTRFS_I(page->mapping->host)->root;
2337 struct btrfs_device *device;
2338
2351 uptodate = 0; 2339 uptodate = 0;
2352 else 2340 device = btrfs_find_device_for_logical(
2341 root, start, mirror);
2342 if (device)
2343 btrfs_dev_stat_inc_and_print(device,
2344 BTRFS_DEV_STAT_CORRUPTION_ERRS);
2345 } else {
2353 clean_io_failure(start, page); 2346 clean_io_failure(start, page);
2347 }
2354 } 2348 }
2355 2349
2356 if (!uptodate && tree->ops && tree->ops->readpage_io_failed_hook) { 2350 if (!uptodate && tree->ops && tree->ops->readpage_io_failed_hook) {
@@ -3164,7 +3158,7 @@ static int write_one_eb(struct extent_buffer *eb,
3164 u64 offset = eb->start; 3158 u64 offset = eb->start;
3165 unsigned long i, num_pages; 3159 unsigned long i, num_pages;
3166 int rw = (epd->sync_io ? WRITE_SYNC : WRITE); 3160 int rw = (epd->sync_io ? WRITE_SYNC : WRITE);
3167 int ret; 3161 int ret = 0;
3168 3162
3169 clear_bit(EXTENT_BUFFER_IOERR, &eb->bflags); 3163 clear_bit(EXTENT_BUFFER_IOERR, &eb->bflags);
3170 num_pages = num_extent_pages(eb->start, eb->len); 3164 num_pages = num_extent_pages(eb->start, eb->len);
@@ -3930,6 +3924,7 @@ static struct extent_buffer *__alloc_extent_buffer(struct extent_io_tree *tree,
3930 eb->start = start; 3924 eb->start = start;
3931 eb->len = len; 3925 eb->len = len;
3932 eb->tree = tree; 3926 eb->tree = tree;
3927 eb->bflags = 0;
3933 rwlock_init(&eb->lock); 3928 rwlock_init(&eb->lock);
3934 atomic_set(&eb->write_locks, 0); 3929 atomic_set(&eb->write_locks, 0);
3935 atomic_set(&eb->read_locks, 0); 3930 atomic_set(&eb->read_locks, 0);
@@ -3967,6 +3962,60 @@ static struct extent_buffer *__alloc_extent_buffer(struct extent_io_tree *tree,
3967 return eb; 3962 return eb;
3968} 3963}
3969 3964
3965struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src)
3966{
3967 unsigned long i;
3968 struct page *p;
3969 struct extent_buffer *new;
3970 unsigned long num_pages = num_extent_pages(src->start, src->len);
3971
3972 new = __alloc_extent_buffer(NULL, src->start, src->len, GFP_ATOMIC);
3973 if (new == NULL)
3974 return NULL;
3975
3976 for (i = 0; i < num_pages; i++) {
3977 p = alloc_page(GFP_ATOMIC);
3978 BUG_ON(!p);
3979 attach_extent_buffer_page(new, p);
3980 WARN_ON(PageDirty(p));
3981 SetPageUptodate(p);
3982 new->pages[i] = p;
3983 }
3984
3985 copy_extent_buffer(new, src, 0, 0, src->len);
3986 set_bit(EXTENT_BUFFER_UPTODATE, &new->bflags);
3987 set_bit(EXTENT_BUFFER_DUMMY, &new->bflags);
3988
3989 return new;
3990}
3991
3992struct extent_buffer *alloc_dummy_extent_buffer(u64 start, unsigned long len)
3993{
3994 struct extent_buffer *eb;
3995 unsigned long num_pages = num_extent_pages(0, len);
3996 unsigned long i;
3997
3998 eb = __alloc_extent_buffer(NULL, start, len, GFP_ATOMIC);
3999 if (!eb)
4000 return NULL;
4001
4002 for (i = 0; i < num_pages; i++) {
4003 eb->pages[i] = alloc_page(GFP_ATOMIC);
4004 if (!eb->pages[i])
4005 goto err;
4006 }
4007 set_extent_buffer_uptodate(eb);
4008 btrfs_set_header_nritems(eb, 0);
4009 set_bit(EXTENT_BUFFER_DUMMY, &eb->bflags);
4010
4011 return eb;
4012err:
4013 for (i--; i > 0; i--)
4014 __free_page(eb->pages[i]);
4015 __free_extent_buffer(eb);
4016 return NULL;
4017}
4018
3970static int extent_buffer_under_io(struct extent_buffer *eb) 4019static int extent_buffer_under_io(struct extent_buffer *eb)
3971{ 4020{
3972 return (atomic_read(&eb->io_pages) || 4021 return (atomic_read(&eb->io_pages) ||
@@ -3981,18 +4030,21 @@ static void btrfs_release_extent_buffer_page(struct extent_buffer *eb,
3981 unsigned long start_idx) 4030 unsigned long start_idx)
3982{ 4031{
3983 unsigned long index; 4032 unsigned long index;
4033 unsigned long num_pages;
3984 struct page *page; 4034 struct page *page;
4035 int mapped = !test_bit(EXTENT_BUFFER_DUMMY, &eb->bflags);
3985 4036
3986 BUG_ON(extent_buffer_under_io(eb)); 4037 BUG_ON(extent_buffer_under_io(eb));
3987 4038
3988 index = num_extent_pages(eb->start, eb->len); 4039 num_pages = num_extent_pages(eb->start, eb->len);
4040 index = start_idx + num_pages;
3989 if (start_idx >= index) 4041 if (start_idx >= index)
3990 return; 4042 return;
3991 4043
3992 do { 4044 do {
3993 index--; 4045 index--;
3994 page = extent_buffer_page(eb, index); 4046 page = extent_buffer_page(eb, index);
3995 if (page) { 4047 if (page && mapped) {
3996 spin_lock(&page->mapping->private_lock); 4048 spin_lock(&page->mapping->private_lock);
3997 /* 4049 /*
3998 * We do this since we'll remove the pages after we've 4050 * We do this since we'll remove the pages after we've
@@ -4017,6 +4069,8 @@ static void btrfs_release_extent_buffer_page(struct extent_buffer *eb,
4017 } 4069 }
4018 spin_unlock(&page->mapping->private_lock); 4070 spin_unlock(&page->mapping->private_lock);
4019 4071
4072 }
4073 if (page) {
4020 /* One for when we alloced the page */ 4074 /* One for when we alloced the page */
4021 page_cache_release(page); 4075 page_cache_release(page);
4022 } 4076 }
@@ -4235,14 +4289,18 @@ static void release_extent_buffer(struct extent_buffer *eb, gfp_t mask)
4235{ 4289{
4236 WARN_ON(atomic_read(&eb->refs) == 0); 4290 WARN_ON(atomic_read(&eb->refs) == 0);
4237 if (atomic_dec_and_test(&eb->refs)) { 4291 if (atomic_dec_and_test(&eb->refs)) {
4238 struct extent_io_tree *tree = eb->tree; 4292 if (test_bit(EXTENT_BUFFER_DUMMY, &eb->bflags)) {
4293 spin_unlock(&eb->refs_lock);
4294 } else {
4295 struct extent_io_tree *tree = eb->tree;
4239 4296
4240 spin_unlock(&eb->refs_lock); 4297 spin_unlock(&eb->refs_lock);
4241 4298
4242 spin_lock(&tree->buffer_lock); 4299 spin_lock(&tree->buffer_lock);
4243 radix_tree_delete(&tree->buffer, 4300 radix_tree_delete(&tree->buffer,
4244 eb->start >> PAGE_CACHE_SHIFT); 4301 eb->start >> PAGE_CACHE_SHIFT);
4245 spin_unlock(&tree->buffer_lock); 4302 spin_unlock(&tree->buffer_lock);
4303 }
4246 4304
4247 /* Should be safe to release our pages at this point */ 4305 /* Should be safe to release our pages at this point */
4248 btrfs_release_extent_buffer_page(eb, 0); 4306 btrfs_release_extent_buffer_page(eb, 0);
@@ -4260,6 +4318,10 @@ void free_extent_buffer(struct extent_buffer *eb)
4260 4318
4261 spin_lock(&eb->refs_lock); 4319 spin_lock(&eb->refs_lock);
4262 if (atomic_read(&eb->refs) == 2 && 4320 if (atomic_read(&eb->refs) == 2 &&
4321 test_bit(EXTENT_BUFFER_DUMMY, &eb->bflags))
4322 atomic_dec(&eb->refs);
4323
4324 if (atomic_read(&eb->refs) == 2 &&
4263 test_bit(EXTENT_BUFFER_STALE, &eb->bflags) && 4325 test_bit(EXTENT_BUFFER_STALE, &eb->bflags) &&
4264 !extent_buffer_under_io(eb) && 4326 !extent_buffer_under_io(eb) &&
4265 test_and_clear_bit(EXTENT_BUFFER_TREE_REF, &eb->bflags)) 4327 test_and_clear_bit(EXTENT_BUFFER_TREE_REF, &eb->bflags))
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index b516c3b8dec6..25900af5b15d 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -39,6 +39,7 @@
39#define EXTENT_BUFFER_STALE 6 39#define EXTENT_BUFFER_STALE 6
40#define EXTENT_BUFFER_WRITEBACK 7 40#define EXTENT_BUFFER_WRITEBACK 7
41#define EXTENT_BUFFER_IOERR 8 41#define EXTENT_BUFFER_IOERR 8
42#define EXTENT_BUFFER_DUMMY 9
42 43
43/* these are flags for extent_clear_unlock_delalloc */ 44/* these are flags for extent_clear_unlock_delalloc */
44#define EXTENT_CLEAR_UNLOCK_PAGE 0x1 45#define EXTENT_CLEAR_UNLOCK_PAGE 0x1
@@ -75,9 +76,6 @@ struct extent_io_ops {
75 unsigned long bio_flags); 76 unsigned long bio_flags);
76 int (*readpage_io_hook)(struct page *page, u64 start, u64 end); 77 int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
77 int (*readpage_io_failed_hook)(struct page *page, int failed_mirror); 78 int (*readpage_io_failed_hook)(struct page *page, int failed_mirror);
78 int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
79 u64 start, u64 end,
80 struct extent_state *state);
81 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end, 79 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
82 struct extent_state *state, int mirror); 80 struct extent_state *state, int mirror);
83 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end, 81 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
@@ -225,6 +223,8 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
225 struct extent_state **cached_state, gfp_t mask); 223 struct extent_state **cached_state, gfp_t mask);
226int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, 224int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
227 struct extent_state **cached_state, gfp_t mask); 225 struct extent_state **cached_state, gfp_t mask);
226int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
227 struct extent_state **cached_state, gfp_t mask);
228int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end, 228int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
229 gfp_t mask); 229 gfp_t mask);
230int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, 230int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
@@ -265,6 +265,8 @@ void set_page_extent_mapped(struct page *page);
265 265
266struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, 266struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
267 u64 start, unsigned long len); 267 u64 start, unsigned long len);
268struct extent_buffer *alloc_dummy_extent_buffer(u64 start, unsigned long len);
269struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src);
268struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree, 270struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
269 u64 start, unsigned long len); 271 u64 start, unsigned long len);
270void free_extent_buffer(struct extent_buffer *eb); 272void free_extent_buffer(struct extent_buffer *eb);
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 53bf2d764bbc..70dc8ca73e25 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -65,6 +65,21 @@ struct inode_defrag {
65 int cycled; 65 int cycled;
66}; 66};
67 67
68static int __compare_inode_defrag(struct inode_defrag *defrag1,
69 struct inode_defrag *defrag2)
70{
71 if (defrag1->root > defrag2->root)
72 return 1;
73 else if (defrag1->root < defrag2->root)
74 return -1;
75 else if (defrag1->ino > defrag2->ino)
76 return 1;
77 else if (defrag1->ino < defrag2->ino)
78 return -1;
79 else
80 return 0;
81}
82
68/* pop a record for an inode into the defrag tree. The lock 83/* pop a record for an inode into the defrag tree. The lock
69 * must be held already 84 * must be held already
70 * 85 *
@@ -81,15 +96,17 @@ static void __btrfs_add_inode_defrag(struct inode *inode,
81 struct inode_defrag *entry; 96 struct inode_defrag *entry;
82 struct rb_node **p; 97 struct rb_node **p;
83 struct rb_node *parent = NULL; 98 struct rb_node *parent = NULL;
99 int ret;
84 100
85 p = &root->fs_info->defrag_inodes.rb_node; 101 p = &root->fs_info->defrag_inodes.rb_node;
86 while (*p) { 102 while (*p) {
87 parent = *p; 103 parent = *p;
88 entry = rb_entry(parent, struct inode_defrag, rb_node); 104 entry = rb_entry(parent, struct inode_defrag, rb_node);
89 105
90 if (defrag->ino < entry->ino) 106 ret = __compare_inode_defrag(defrag, entry);
107 if (ret < 0)
91 p = &parent->rb_left; 108 p = &parent->rb_left;
92 else if (defrag->ino > entry->ino) 109 else if (ret > 0)
93 p = &parent->rb_right; 110 p = &parent->rb_right;
94 else { 111 else {
95 /* if we're reinserting an entry for 112 /* if we're reinserting an entry for
@@ -103,7 +120,7 @@ static void __btrfs_add_inode_defrag(struct inode *inode,
103 goto exists; 120 goto exists;
104 } 121 }
105 } 122 }
106 BTRFS_I(inode)->in_defrag = 1; 123 set_bit(BTRFS_INODE_IN_DEFRAG, &BTRFS_I(inode)->runtime_flags);
107 rb_link_node(&defrag->rb_node, parent, p); 124 rb_link_node(&defrag->rb_node, parent, p);
108 rb_insert_color(&defrag->rb_node, &root->fs_info->defrag_inodes); 125 rb_insert_color(&defrag->rb_node, &root->fs_info->defrag_inodes);
109 return; 126 return;
@@ -131,7 +148,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
131 if (btrfs_fs_closing(root->fs_info)) 148 if (btrfs_fs_closing(root->fs_info))
132 return 0; 149 return 0;
133 150
134 if (BTRFS_I(inode)->in_defrag) 151 if (test_bit(BTRFS_INODE_IN_DEFRAG, &BTRFS_I(inode)->runtime_flags))
135 return 0; 152 return 0;
136 153
137 if (trans) 154 if (trans)
@@ -148,7 +165,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
148 defrag->root = root->root_key.objectid; 165 defrag->root = root->root_key.objectid;
149 166
150 spin_lock(&root->fs_info->defrag_inodes_lock); 167 spin_lock(&root->fs_info->defrag_inodes_lock);
151 if (!BTRFS_I(inode)->in_defrag) 168 if (!test_bit(BTRFS_INODE_IN_DEFRAG, &BTRFS_I(inode)->runtime_flags))
152 __btrfs_add_inode_defrag(inode, defrag); 169 __btrfs_add_inode_defrag(inode, defrag);
153 else 170 else
154 kfree(defrag); 171 kfree(defrag);
@@ -159,28 +176,35 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
159/* 176/*
160 * must be called with the defrag_inodes lock held 177 * must be called with the defrag_inodes lock held
161 */ 178 */
162struct inode_defrag *btrfs_find_defrag_inode(struct btrfs_fs_info *info, u64 ino, 179struct inode_defrag *btrfs_find_defrag_inode(struct btrfs_fs_info *info,
180 u64 root, u64 ino,
163 struct rb_node **next) 181 struct rb_node **next)
164{ 182{
165 struct inode_defrag *entry = NULL; 183 struct inode_defrag *entry = NULL;
184 struct inode_defrag tmp;
166 struct rb_node *p; 185 struct rb_node *p;
167 struct rb_node *parent = NULL; 186 struct rb_node *parent = NULL;
187 int ret;
188
189 tmp.ino = ino;
190 tmp.root = root;
168 191
169 p = info->defrag_inodes.rb_node; 192 p = info->defrag_inodes.rb_node;
170 while (p) { 193 while (p) {
171 parent = p; 194 parent = p;
172 entry = rb_entry(parent, struct inode_defrag, rb_node); 195 entry = rb_entry(parent, struct inode_defrag, rb_node);
173 196
174 if (ino < entry->ino) 197 ret = __compare_inode_defrag(&tmp, entry);
198 if (ret < 0)
175 p = parent->rb_left; 199 p = parent->rb_left;
176 else if (ino > entry->ino) 200 else if (ret > 0)
177 p = parent->rb_right; 201 p = parent->rb_right;
178 else 202 else
179 return entry; 203 return entry;
180 } 204 }
181 205
182 if (next) { 206 if (next) {
183 while (parent && ino > entry->ino) { 207 while (parent && __compare_inode_defrag(&tmp, entry) > 0) {
184 parent = rb_next(parent); 208 parent = rb_next(parent);
185 entry = rb_entry(parent, struct inode_defrag, rb_node); 209 entry = rb_entry(parent, struct inode_defrag, rb_node);
186 } 210 }
@@ -202,6 +226,7 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)
202 struct btrfs_key key; 226 struct btrfs_key key;
203 struct btrfs_ioctl_defrag_range_args range; 227 struct btrfs_ioctl_defrag_range_args range;
204 u64 first_ino = 0; 228 u64 first_ino = 0;
229 u64 root_objectid = 0;
205 int num_defrag; 230 int num_defrag;
206 int defrag_batch = 1024; 231 int defrag_batch = 1024;
207 232
@@ -214,11 +239,14 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)
214 n = NULL; 239 n = NULL;
215 240
216 /* find an inode to defrag */ 241 /* find an inode to defrag */
217 defrag = btrfs_find_defrag_inode(fs_info, first_ino, &n); 242 defrag = btrfs_find_defrag_inode(fs_info, root_objectid,
243 first_ino, &n);
218 if (!defrag) { 244 if (!defrag) {
219 if (n) 245 if (n) {
220 defrag = rb_entry(n, struct inode_defrag, rb_node); 246 defrag = rb_entry(n, struct inode_defrag,
221 else if (first_ino) { 247 rb_node);
248 } else if (root_objectid || first_ino) {
249 root_objectid = 0;
222 first_ino = 0; 250 first_ino = 0;
223 continue; 251 continue;
224 } else { 252 } else {
@@ -228,6 +256,7 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)
228 256
229 /* remove it from the rbtree */ 257 /* remove it from the rbtree */
230 first_ino = defrag->ino + 1; 258 first_ino = defrag->ino + 1;
259 root_objectid = defrag->root;
231 rb_erase(&defrag->rb_node, &fs_info->defrag_inodes); 260 rb_erase(&defrag->rb_node, &fs_info->defrag_inodes);
232 261
233 if (btrfs_fs_closing(fs_info)) 262 if (btrfs_fs_closing(fs_info))
@@ -252,7 +281,7 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)
252 goto next; 281 goto next;
253 282
254 /* do a chunk of defrag */ 283 /* do a chunk of defrag */
255 BTRFS_I(inode)->in_defrag = 0; 284 clear_bit(BTRFS_INODE_IN_DEFRAG, &BTRFS_I(inode)->runtime_flags);
256 range.start = defrag->last_offset; 285 range.start = defrag->last_offset;
257 num_defrag = btrfs_defrag_file(inode, NULL, &range, defrag->transid, 286 num_defrag = btrfs_defrag_file(inode, NULL, &range, defrag->transid,
258 defrag_batch); 287 defrag_batch);
@@ -1404,12 +1433,11 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
1404 goto out; 1433 goto out;
1405 } 1434 }
1406 1435
1407 err = btrfs_update_time(file); 1436 err = file_update_time(file);
1408 if (err) { 1437 if (err) {
1409 mutex_unlock(&inode->i_mutex); 1438 mutex_unlock(&inode->i_mutex);
1410 goto out; 1439 goto out;
1411 } 1440 }
1412 BTRFS_I(inode)->sequence++;
1413 1441
1414 start_pos = round_down(pos, root->sectorsize); 1442 start_pos = round_down(pos, root->sectorsize);
1415 if (start_pos > i_size_read(inode)) { 1443 if (start_pos > i_size_read(inode)) {
@@ -1466,8 +1494,8 @@ int btrfs_release_file(struct inode *inode, struct file *filp)
1466 * flush down new bytes that may have been written if the 1494 * flush down new bytes that may have been written if the
1467 * application were using truncate to replace a file in place. 1495 * application were using truncate to replace a file in place.
1468 */ 1496 */
1469 if (BTRFS_I(inode)->ordered_data_close) { 1497 if (test_and_clear_bit(BTRFS_INODE_ORDERED_DATA_CLOSE,
1470 BTRFS_I(inode)->ordered_data_close = 0; 1498 &BTRFS_I(inode)->runtime_flags)) {
1471 btrfs_add_ordered_operation(NULL, BTRFS_I(inode)->root, inode); 1499 btrfs_add_ordered_operation(NULL, BTRFS_I(inode)->root, inode);
1472 if (inode->i_size > BTRFS_ORDERED_OPERATIONS_FLUSH_LIMIT) 1500 if (inode->i_size > BTRFS_ORDERED_OPERATIONS_FLUSH_LIMIT)
1473 filemap_flush(inode->i_mapping); 1501 filemap_flush(inode->i_mapping);
@@ -1498,14 +1526,15 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
1498 1526
1499 trace_btrfs_sync_file(file, datasync); 1527 trace_btrfs_sync_file(file, datasync);
1500 1528
1501 ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
1502 if (ret)
1503 return ret;
1504 mutex_lock(&inode->i_mutex); 1529 mutex_lock(&inode->i_mutex);
1505 1530
1506 /* we wait first, since the writeback may change the inode */ 1531 /*
1532 * we wait first, since the writeback may change the inode, also wait
1533 * ordered range does a filemape_write_and_wait_range which is why we
1534 * don't do it above like other file systems.
1535 */
1507 root->log_batch++; 1536 root->log_batch++;
1508 btrfs_wait_ordered_range(inode, 0, (u64)-1); 1537 btrfs_wait_ordered_range(inode, start, end);
1509 root->log_batch++; 1538 root->log_batch++;
1510 1539
1511 /* 1540 /*
@@ -1523,7 +1552,8 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
1523 * syncing 1552 * syncing
1524 */ 1553 */
1525 smp_mb(); 1554 smp_mb();
1526 if (BTRFS_I(inode)->last_trans <= 1555 if (btrfs_inode_in_log(inode, root->fs_info->generation) ||
1556 BTRFS_I(inode)->last_trans <=
1527 root->fs_info->last_trans_committed) { 1557 root->fs_info->last_trans_committed) {
1528 BTRFS_I(inode)->last_trans = 0; 1558 BTRFS_I(inode)->last_trans = 0;
1529 mutex_unlock(&inode->i_mutex); 1559 mutex_unlock(&inode->i_mutex);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 202008ec367d..81296c57405a 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -33,6 +33,8 @@
33 33
34static int link_free_space(struct btrfs_free_space_ctl *ctl, 34static int link_free_space(struct btrfs_free_space_ctl *ctl,
35 struct btrfs_free_space *info); 35 struct btrfs_free_space *info);
36static void unlink_free_space(struct btrfs_free_space_ctl *ctl,
37 struct btrfs_free_space *info);
36 38
37static struct inode *__lookup_free_space_inode(struct btrfs_root *root, 39static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
38 struct btrfs_path *path, 40 struct btrfs_path *path,
@@ -75,7 +77,8 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
75 return ERR_PTR(-ENOENT); 77 return ERR_PTR(-ENOENT);
76 } 78 }
77 79
78 inode->i_mapping->flags &= ~__GFP_FS; 80 mapping_set_gfp_mask(inode->i_mapping,
81 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
79 82
80 return inode; 83 return inode;
81} 84}
@@ -365,7 +368,7 @@ static int io_ctl_prepare_pages(struct io_ctl *io_ctl, struct inode *inode,
365 368
366static void io_ctl_set_generation(struct io_ctl *io_ctl, u64 generation) 369static void io_ctl_set_generation(struct io_ctl *io_ctl, u64 generation)
367{ 370{
368 u64 *val; 371 __le64 *val;
369 372
370 io_ctl_map_page(io_ctl, 1); 373 io_ctl_map_page(io_ctl, 1);
371 374
@@ -388,7 +391,7 @@ static void io_ctl_set_generation(struct io_ctl *io_ctl, u64 generation)
388 391
389static int io_ctl_check_generation(struct io_ctl *io_ctl, u64 generation) 392static int io_ctl_check_generation(struct io_ctl *io_ctl, u64 generation)
390{ 393{
391 u64 *gen; 394 __le64 *gen;
392 395
393 /* 396 /*
394 * Skip the crc area. If we don't check crcs then we just have a 64bit 397 * Skip the crc area. If we don't check crcs then we just have a 64bit
@@ -584,6 +587,44 @@ static int io_ctl_read_bitmap(struct io_ctl *io_ctl,
584 return 0; 587 return 0;
585} 588}
586 589
590/*
591 * Since we attach pinned extents after the fact we can have contiguous sections
592 * of free space that are split up in entries. This poses a problem with the
593 * tree logging stuff since it could have allocated across what appears to be 2
594 * entries since we would have merged the entries when adding the pinned extents
595 * back to the free space cache. So run through the space cache that we just
596 * loaded and merge contiguous entries. This will make the log replay stuff not
597 * blow up and it will make for nicer allocator behavior.
598 */
599static void merge_space_tree(struct btrfs_free_space_ctl *ctl)
600{
601 struct btrfs_free_space *e, *prev = NULL;
602 struct rb_node *n;
603
604again:
605 spin_lock(&ctl->tree_lock);
606 for (n = rb_first(&ctl->free_space_offset); n; n = rb_next(n)) {
607 e = rb_entry(n, struct btrfs_free_space, offset_index);
608 if (!prev)
609 goto next;
610 if (e->bitmap || prev->bitmap)
611 goto next;
612 if (prev->offset + prev->bytes == e->offset) {
613 unlink_free_space(ctl, prev);
614 unlink_free_space(ctl, e);
615 prev->bytes += e->bytes;
616 kmem_cache_free(btrfs_free_space_cachep, e);
617 link_free_space(ctl, prev);
618 prev = NULL;
619 spin_unlock(&ctl->tree_lock);
620 goto again;
621 }
622next:
623 prev = e;
624 }
625 spin_unlock(&ctl->tree_lock);
626}
627
587int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, 628int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
588 struct btrfs_free_space_ctl *ctl, 629 struct btrfs_free_space_ctl *ctl,
589 struct btrfs_path *path, u64 offset) 630 struct btrfs_path *path, u64 offset)
@@ -726,6 +767,7 @@ int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
726 } 767 }
727 768
728 io_ctl_drop_pages(&io_ctl); 769 io_ctl_drop_pages(&io_ctl);
770 merge_space_tree(ctl);
729 ret = 1; 771 ret = 1;
730out: 772out:
731 io_ctl_free(&io_ctl); 773 io_ctl_free(&io_ctl);
@@ -972,9 +1014,7 @@ int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
972 goto out; 1014 goto out;
973 1015
974 1016
975 ret = filemap_write_and_wait(inode->i_mapping); 1017 btrfs_wait_ordered_range(inode, 0, (u64)-1);
976 if (ret)
977 goto out;
978 1018
979 key.objectid = BTRFS_FREE_SPACE_OBJECTID; 1019 key.objectid = BTRFS_FREE_SPACE_OBJECTID;
980 key.offset = offset; 1020 key.offset = offset;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index ceb7b9c9edcc..f6ab6f5e635a 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -89,7 +89,7 @@ static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = {
89 89
90static int btrfs_setsize(struct inode *inode, loff_t newsize); 90static int btrfs_setsize(struct inode *inode, loff_t newsize);
91static int btrfs_truncate(struct inode *inode); 91static int btrfs_truncate(struct inode *inode);
92static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end); 92static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent);
93static noinline int cow_file_range(struct inode *inode, 93static noinline int cow_file_range(struct inode *inode,
94 struct page *locked_page, 94 struct page *locked_page,
95 u64 start, u64 end, int *page_started, 95 u64 start, u64 end, int *page_started,
@@ -257,10 +257,13 @@ static noinline int cow_file_range_inline(struct btrfs_trans_handle *trans,
257 ret = insert_inline_extent(trans, root, inode, start, 257 ret = insert_inline_extent(trans, root, inode, start,
258 inline_len, compressed_size, 258 inline_len, compressed_size,
259 compress_type, compressed_pages); 259 compress_type, compressed_pages);
260 if (ret) { 260 if (ret && ret != -ENOSPC) {
261 btrfs_abort_transaction(trans, root, ret); 261 btrfs_abort_transaction(trans, root, ret);
262 return ret; 262 return ret;
263 } else if (ret == -ENOSPC) {
264 return 1;
263 } 265 }
266
264 btrfs_delalloc_release_metadata(inode, end + 1 - start); 267 btrfs_delalloc_release_metadata(inode, end + 1 - start);
265 btrfs_drop_extent_cache(inode, start, aligned_end - 1, 0); 268 btrfs_drop_extent_cache(inode, start, aligned_end - 1, 0);
266 return 0; 269 return 0;
@@ -1572,11 +1575,11 @@ static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
1572 if (btrfs_is_free_space_inode(root, inode)) 1575 if (btrfs_is_free_space_inode(root, inode))
1573 metadata = 2; 1576 metadata = 2;
1574 1577
1575 ret = btrfs_bio_wq_end_io(root->fs_info, bio, metadata);
1576 if (ret)
1577 return ret;
1578
1579 if (!(rw & REQ_WRITE)) { 1578 if (!(rw & REQ_WRITE)) {
1579 ret = btrfs_bio_wq_end_io(root->fs_info, bio, metadata);
1580 if (ret)
1581 return ret;
1582
1580 if (bio_flags & EXTENT_BIO_COMPRESSED) { 1583 if (bio_flags & EXTENT_BIO_COMPRESSED) {
1581 return btrfs_submit_compressed_read(inode, bio, 1584 return btrfs_submit_compressed_read(inode, bio,
1582 mirror_num, bio_flags); 1585 mirror_num, bio_flags);
@@ -1815,25 +1818,24 @@ out:
1815 * an ordered extent if the range of bytes in the file it covers are 1818 * an ordered extent if the range of bytes in the file it covers are
1816 * fully written. 1819 * fully written.
1817 */ 1820 */
1818static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) 1821static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
1819{ 1822{
1823 struct inode *inode = ordered_extent->inode;
1820 struct btrfs_root *root = BTRFS_I(inode)->root; 1824 struct btrfs_root *root = BTRFS_I(inode)->root;
1821 struct btrfs_trans_handle *trans = NULL; 1825 struct btrfs_trans_handle *trans = NULL;
1822 struct btrfs_ordered_extent *ordered_extent = NULL;
1823 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; 1826 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
1824 struct extent_state *cached_state = NULL; 1827 struct extent_state *cached_state = NULL;
1825 int compress_type = 0; 1828 int compress_type = 0;
1826 int ret; 1829 int ret;
1827 bool nolock; 1830 bool nolock;
1828 1831
1829 ret = btrfs_dec_test_ordered_pending(inode, &ordered_extent, start,
1830 end - start + 1);
1831 if (!ret)
1832 return 0;
1833 BUG_ON(!ordered_extent); /* Logic error */
1834
1835 nolock = btrfs_is_free_space_inode(root, inode); 1832 nolock = btrfs_is_free_space_inode(root, inode);
1836 1833
1834 if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) {
1835 ret = -EIO;
1836 goto out;
1837 }
1838
1837 if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) { 1839 if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) {
1838 BUG_ON(!list_empty(&ordered_extent->list)); /* Logic error */ 1840 BUG_ON(!list_empty(&ordered_extent->list)); /* Logic error */
1839 ret = btrfs_ordered_update_i_size(inode, 0, ordered_extent); 1841 ret = btrfs_ordered_update_i_size(inode, 0, ordered_extent);
@@ -1889,12 +1891,10 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)
1889 ordered_extent->file_offset, 1891 ordered_extent->file_offset,
1890 ordered_extent->len); 1892 ordered_extent->len);
1891 } 1893 }
1892 unlock_extent_cached(io_tree, ordered_extent->file_offset, 1894
1893 ordered_extent->file_offset +
1894 ordered_extent->len - 1, &cached_state, GFP_NOFS);
1895 if (ret < 0) { 1895 if (ret < 0) {
1896 btrfs_abort_transaction(trans, root, ret); 1896 btrfs_abort_transaction(trans, root, ret);
1897 goto out; 1897 goto out_unlock;
1898 } 1898 }
1899 1899
1900 add_pending_csums(trans, inode, ordered_extent->file_offset, 1900 add_pending_csums(trans, inode, ordered_extent->file_offset,
@@ -1905,10 +1905,14 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)
1905 ret = btrfs_update_inode_fallback(trans, root, inode); 1905 ret = btrfs_update_inode_fallback(trans, root, inode);
1906 if (ret) { /* -ENOMEM or corruption */ 1906 if (ret) { /* -ENOMEM or corruption */
1907 btrfs_abort_transaction(trans, root, ret); 1907 btrfs_abort_transaction(trans, root, ret);
1908 goto out; 1908 goto out_unlock;
1909 } 1909 }
1910 } 1910 }
1911 ret = 0; 1911 ret = 0;
1912out_unlock:
1913 unlock_extent_cached(io_tree, ordered_extent->file_offset,
1914 ordered_extent->file_offset +
1915 ordered_extent->len - 1, &cached_state, GFP_NOFS);
1912out: 1916out:
1913 if (root != root->fs_info->tree_root) 1917 if (root != root->fs_info->tree_root)
1914 btrfs_delalloc_release_metadata(inode, ordered_extent->len); 1918 btrfs_delalloc_release_metadata(inode, ordered_extent->len);
@@ -1919,26 +1923,57 @@ out:
1919 btrfs_end_transaction(trans, root); 1923 btrfs_end_transaction(trans, root);
1920 } 1924 }
1921 1925
1926 if (ret)
1927 clear_extent_uptodate(io_tree, ordered_extent->file_offset,
1928 ordered_extent->file_offset +
1929 ordered_extent->len - 1, NULL, GFP_NOFS);
1930
1931 /*
1932 * This needs to be dont to make sure anybody waiting knows we are done
1933 * upating everything for this ordered extent.
1934 */
1935 btrfs_remove_ordered_extent(inode, ordered_extent);
1936
1922 /* once for us */ 1937 /* once for us */
1923 btrfs_put_ordered_extent(ordered_extent); 1938 btrfs_put_ordered_extent(ordered_extent);
1924 /* once for the tree */ 1939 /* once for the tree */
1925 btrfs_put_ordered_extent(ordered_extent); 1940 btrfs_put_ordered_extent(ordered_extent);
1926 1941
1927 return 0; 1942 return ret;
1928out_unlock: 1943}
1929 unlock_extent_cached(io_tree, ordered_extent->file_offset, 1944
1930 ordered_extent->file_offset + 1945static void finish_ordered_fn(struct btrfs_work *work)
1931 ordered_extent->len - 1, &cached_state, GFP_NOFS); 1946{
1932 goto out; 1947 struct btrfs_ordered_extent *ordered_extent;
1948 ordered_extent = container_of(work, struct btrfs_ordered_extent, work);
1949 btrfs_finish_ordered_io(ordered_extent);
1933} 1950}
1934 1951
1935static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end, 1952static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end,
1936 struct extent_state *state, int uptodate) 1953 struct extent_state *state, int uptodate)
1937{ 1954{
1955 struct inode *inode = page->mapping->host;
1956 struct btrfs_root *root = BTRFS_I(inode)->root;
1957 struct btrfs_ordered_extent *ordered_extent = NULL;
1958 struct btrfs_workers *workers;
1959
1938 trace_btrfs_writepage_end_io_hook(page, start, end, uptodate); 1960 trace_btrfs_writepage_end_io_hook(page, start, end, uptodate);
1939 1961
1940 ClearPagePrivate2(page); 1962 ClearPagePrivate2(page);
1941 return btrfs_finish_ordered_io(page->mapping->host, start, end); 1963 if (!btrfs_dec_test_ordered_pending(inode, &ordered_extent, start,
1964 end - start + 1, uptodate))
1965 return 0;
1966
1967 ordered_extent->work.func = finish_ordered_fn;
1968 ordered_extent->work.flags = 0;
1969
1970 if (btrfs_is_free_space_inode(root, inode))
1971 workers = &root->fs_info->endio_freespace_worker;
1972 else
1973 workers = &root->fs_info->endio_write_workers;
1974 btrfs_queue_worker(workers, &ordered_extent->work);
1975
1976 return 0;
1942} 1977}
1943 1978
1944/* 1979/*
@@ -2072,12 +2107,12 @@ void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans,
2072 struct btrfs_block_rsv *block_rsv; 2107 struct btrfs_block_rsv *block_rsv;
2073 int ret; 2108 int ret;
2074 2109
2075 if (!list_empty(&root->orphan_list) || 2110 if (atomic_read(&root->orphan_inodes) ||
2076 root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE) 2111 root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE)
2077 return; 2112 return;
2078 2113
2079 spin_lock(&root->orphan_lock); 2114 spin_lock(&root->orphan_lock);
2080 if (!list_empty(&root->orphan_list)) { 2115 if (atomic_read(&root->orphan_inodes)) {
2081 spin_unlock(&root->orphan_lock); 2116 spin_unlock(&root->orphan_lock);
2082 return; 2117 return;
2083 } 2118 }
@@ -2134,8 +2169,8 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
2134 block_rsv = NULL; 2169 block_rsv = NULL;
2135 } 2170 }
2136 2171
2137 if (list_empty(&BTRFS_I(inode)->i_orphan)) { 2172 if (!test_and_set_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
2138 list_add(&BTRFS_I(inode)->i_orphan, &root->orphan_list); 2173 &BTRFS_I(inode)->runtime_flags)) {
2139#if 0 2174#if 0
2140 /* 2175 /*
2141 * For proper ENOSPC handling, we should do orphan 2176 * For proper ENOSPC handling, we should do orphan
@@ -2148,12 +2183,12 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
2148 insert = 1; 2183 insert = 1;
2149#endif 2184#endif
2150 insert = 1; 2185 insert = 1;
2186 atomic_dec(&root->orphan_inodes);
2151 } 2187 }
2152 2188
2153 if (!BTRFS_I(inode)->orphan_meta_reserved) { 2189 if (!test_and_set_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
2154 BTRFS_I(inode)->orphan_meta_reserved = 1; 2190 &BTRFS_I(inode)->runtime_flags))
2155 reserve = 1; 2191 reserve = 1;
2156 }
2157 spin_unlock(&root->orphan_lock); 2192 spin_unlock(&root->orphan_lock);
2158 2193
2159 /* grab metadata reservation from transaction handle */ 2194 /* grab metadata reservation from transaction handle */
@@ -2166,6 +2201,8 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
2166 if (insert >= 1) { 2201 if (insert >= 1) {
2167 ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode)); 2202 ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode));
2168 if (ret && ret != -EEXIST) { 2203 if (ret && ret != -EEXIST) {
2204 clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
2205 &BTRFS_I(inode)->runtime_flags);
2169 btrfs_abort_transaction(trans, root, ret); 2206 btrfs_abort_transaction(trans, root, ret);
2170 return ret; 2207 return ret;
2171 } 2208 }
@@ -2196,15 +2233,13 @@ int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode)
2196 int ret = 0; 2233 int ret = 0;
2197 2234
2198 spin_lock(&root->orphan_lock); 2235 spin_lock(&root->orphan_lock);
2199 if (!list_empty(&BTRFS_I(inode)->i_orphan)) { 2236 if (test_and_clear_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
2200 list_del_init(&BTRFS_I(inode)->i_orphan); 2237 &BTRFS_I(inode)->runtime_flags))
2201 delete_item = 1; 2238 delete_item = 1;
2202 }
2203 2239
2204 if (BTRFS_I(inode)->orphan_meta_reserved) { 2240 if (test_and_clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
2205 BTRFS_I(inode)->orphan_meta_reserved = 0; 2241 &BTRFS_I(inode)->runtime_flags))
2206 release_rsv = 1; 2242 release_rsv = 1;
2207 }
2208 spin_unlock(&root->orphan_lock); 2243 spin_unlock(&root->orphan_lock);
2209 2244
2210 if (trans && delete_item) { 2245 if (trans && delete_item) {
@@ -2212,8 +2247,10 @@ int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode)
2212 BUG_ON(ret); /* -ENOMEM or corruption (JDM: Recheck) */ 2247 BUG_ON(ret); /* -ENOMEM or corruption (JDM: Recheck) */
2213 } 2248 }
2214 2249
2215 if (release_rsv) 2250 if (release_rsv) {
2216 btrfs_orphan_release_metadata(inode); 2251 btrfs_orphan_release_metadata(inode);
2252 atomic_dec(&root->orphan_inodes);
2253 }
2217 2254
2218 return 0; 2255 return 0;
2219} 2256}
@@ -2341,6 +2378,8 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
2341 ret = PTR_ERR(trans); 2378 ret = PTR_ERR(trans);
2342 goto out; 2379 goto out;
2343 } 2380 }
2381 printk(KERN_ERR "auto deleting %Lu\n",
2382 found_key.objectid);
2344 ret = btrfs_del_orphan_item(trans, root, 2383 ret = btrfs_del_orphan_item(trans, root,
2345 found_key.objectid); 2384 found_key.objectid);
2346 BUG_ON(ret); /* -ENOMEM or corruption (JDM: Recheck) */ 2385 BUG_ON(ret); /* -ENOMEM or corruption (JDM: Recheck) */
@@ -2352,9 +2391,8 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
2352 * add this inode to the orphan list so btrfs_orphan_del does 2391 * add this inode to the orphan list so btrfs_orphan_del does
2353 * the proper thing when we hit it 2392 * the proper thing when we hit it
2354 */ 2393 */
2355 spin_lock(&root->orphan_lock); 2394 set_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
2356 list_add(&BTRFS_I(inode)->i_orphan, &root->orphan_list); 2395 &BTRFS_I(inode)->runtime_flags);
2357 spin_unlock(&root->orphan_lock);
2358 2396
2359 /* if we have links, this was a truncate, lets do that */ 2397 /* if we have links, this was a truncate, lets do that */
2360 if (inode->i_nlink) { 2398 if (inode->i_nlink) {
@@ -2510,7 +2548,7 @@ static void btrfs_read_locked_inode(struct inode *inode)
2510 2548
2511 inode_set_bytes(inode, btrfs_inode_nbytes(leaf, inode_item)); 2549 inode_set_bytes(inode, btrfs_inode_nbytes(leaf, inode_item));
2512 BTRFS_I(inode)->generation = btrfs_inode_generation(leaf, inode_item); 2550 BTRFS_I(inode)->generation = btrfs_inode_generation(leaf, inode_item);
2513 BTRFS_I(inode)->sequence = btrfs_inode_sequence(leaf, inode_item); 2551 inode->i_version = btrfs_inode_sequence(leaf, inode_item);
2514 inode->i_generation = BTRFS_I(inode)->generation; 2552 inode->i_generation = BTRFS_I(inode)->generation;
2515 inode->i_rdev = 0; 2553 inode->i_rdev = 0;
2516 rdev = btrfs_inode_rdev(leaf, inode_item); 2554 rdev = btrfs_inode_rdev(leaf, inode_item);
@@ -2594,7 +2632,7 @@ static void fill_inode_item(struct btrfs_trans_handle *trans,
2594 2632
2595 btrfs_set_inode_nbytes(leaf, item, inode_get_bytes(inode)); 2633 btrfs_set_inode_nbytes(leaf, item, inode_get_bytes(inode));
2596 btrfs_set_inode_generation(leaf, item, BTRFS_I(inode)->generation); 2634 btrfs_set_inode_generation(leaf, item, BTRFS_I(inode)->generation);
2597 btrfs_set_inode_sequence(leaf, item, BTRFS_I(inode)->sequence); 2635 btrfs_set_inode_sequence(leaf, item, inode->i_version);
2598 btrfs_set_inode_transid(leaf, item, trans->transid); 2636 btrfs_set_inode_transid(leaf, item, trans->transid);
2599 btrfs_set_inode_rdev(leaf, item, inode->i_rdev); 2637 btrfs_set_inode_rdev(leaf, item, inode->i_rdev);
2600 btrfs_set_inode_flags(leaf, item, BTRFS_I(inode)->flags); 2638 btrfs_set_inode_flags(leaf, item, BTRFS_I(inode)->flags);
@@ -2752,6 +2790,8 @@ err:
2752 goto out; 2790 goto out;
2753 2791
2754 btrfs_i_size_write(dir, dir->i_size - name_len * 2); 2792 btrfs_i_size_write(dir, dir->i_size - name_len * 2);
2793 inode_inc_iversion(inode);
2794 inode_inc_iversion(dir);
2755 inode->i_ctime = dir->i_mtime = dir->i_ctime = CURRENT_TIME; 2795 inode->i_ctime = dir->i_mtime = dir->i_ctime = CURRENT_TIME;
2756 btrfs_update_inode(trans, root, dir); 2796 btrfs_update_inode(trans, root, dir);
2757out: 2797out:
@@ -3089,6 +3129,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
3089 } 3129 }
3090 3130
3091 btrfs_i_size_write(dir, dir->i_size - name_len * 2); 3131 btrfs_i_size_write(dir, dir->i_size - name_len * 2);
3132 inode_inc_iversion(dir);
3092 dir->i_mtime = dir->i_ctime = CURRENT_TIME; 3133 dir->i_mtime = dir->i_ctime = CURRENT_TIME;
3093 ret = btrfs_update_inode(trans, root, dir); 3134 ret = btrfs_update_inode(trans, root, dir);
3094 if (ret) 3135 if (ret)
@@ -3607,7 +3648,8 @@ static int btrfs_setsize(struct inode *inode, loff_t newsize)
3607 * any new writes get down to disk quickly. 3648 * any new writes get down to disk quickly.
3608 */ 3649 */
3609 if (newsize == 0) 3650 if (newsize == 0)
3610 BTRFS_I(inode)->ordered_data_close = 1; 3651 set_bit(BTRFS_INODE_ORDERED_DATA_CLOSE,
3652 &BTRFS_I(inode)->runtime_flags);
3611 3653
3612 /* we don't support swapfiles, so vmtruncate shouldn't fail */ 3654 /* we don't support swapfiles, so vmtruncate shouldn't fail */
3613 truncate_setsize(inode, newsize); 3655 truncate_setsize(inode, newsize);
@@ -3638,6 +3680,7 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)
3638 3680
3639 if (attr->ia_valid) { 3681 if (attr->ia_valid) {
3640 setattr_copy(inode, attr); 3682 setattr_copy(inode, attr);
3683 inode_inc_iversion(inode);
3641 err = btrfs_dirty_inode(inode); 3684 err = btrfs_dirty_inode(inode);
3642 3685
3643 if (!err && attr->ia_valid & ATTR_MODE) 3686 if (!err && attr->ia_valid & ATTR_MODE)
@@ -3671,7 +3714,8 @@ void btrfs_evict_inode(struct inode *inode)
3671 btrfs_wait_ordered_range(inode, 0, (u64)-1); 3714 btrfs_wait_ordered_range(inode, 0, (u64)-1);
3672 3715
3673 if (root->fs_info->log_root_recovering) { 3716 if (root->fs_info->log_root_recovering) {
3674 BUG_ON(!list_empty(&BTRFS_I(inode)->i_orphan)); 3717 BUG_ON(!test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
3718 &BTRFS_I(inode)->runtime_flags));
3675 goto no_delete; 3719 goto no_delete;
3676 } 3720 }
3677 3721
@@ -4066,7 +4110,7 @@ static struct inode *new_simple_dir(struct super_block *s,
4066 4110
4067 BTRFS_I(inode)->root = root; 4111 BTRFS_I(inode)->root = root;
4068 memcpy(&BTRFS_I(inode)->location, key, sizeof(*key)); 4112 memcpy(&BTRFS_I(inode)->location, key, sizeof(*key));
4069 BTRFS_I(inode)->dummy_inode = 1; 4113 set_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags);
4070 4114
4071 inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID; 4115 inode->i_ino = BTRFS_EMPTY_SUBVOL_DIR_OBJECTID;
4072 inode->i_op = &btrfs_dir_ro_inode_operations; 4116 inode->i_op = &btrfs_dir_ro_inode_operations;
@@ -4370,7 +4414,7 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc)
4370 int ret = 0; 4414 int ret = 0;
4371 bool nolock = false; 4415 bool nolock = false;
4372 4416
4373 if (BTRFS_I(inode)->dummy_inode) 4417 if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags))
4374 return 0; 4418 return 0;
4375 4419
4376 if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(root, inode)) 4420 if (btrfs_fs_closing(root->fs_info) && btrfs_is_free_space_inode(root, inode))
@@ -4403,7 +4447,7 @@ int btrfs_dirty_inode(struct inode *inode)
4403 struct btrfs_trans_handle *trans; 4447 struct btrfs_trans_handle *trans;
4404 int ret; 4448 int ret;
4405 4449
4406 if (BTRFS_I(inode)->dummy_inode) 4450 if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags))
4407 return 0; 4451 return 0;
4408 4452
4409 trans = btrfs_join_transaction(root); 4453 trans = btrfs_join_transaction(root);
@@ -4431,46 +4475,18 @@ int btrfs_dirty_inode(struct inode *inode)
4431 * This is a copy of file_update_time. We need this so we can return error on 4475 * This is a copy of file_update_time. We need this so we can return error on
4432 * ENOSPC for updating the inode in the case of file write and mmap writes. 4476 * ENOSPC for updating the inode in the case of file write and mmap writes.
4433 */ 4477 */
4434int btrfs_update_time(struct file *file) 4478static int btrfs_update_time(struct inode *inode, struct timespec *now,
4479 int flags)
4435{ 4480{
4436 struct inode *inode = file->f_path.dentry->d_inode; 4481 if (flags & S_VERSION)
4437 struct timespec now;
4438 int ret;
4439 enum { S_MTIME = 1, S_CTIME = 2, S_VERSION = 4 } sync_it = 0;
4440
4441 /* First try to exhaust all avenues to not sync */
4442 if (IS_NOCMTIME(inode))
4443 return 0;
4444
4445 now = current_fs_time(inode->i_sb);
4446 if (!timespec_equal(&inode->i_mtime, &now))
4447 sync_it = S_MTIME;
4448
4449 if (!timespec_equal(&inode->i_ctime, &now))
4450 sync_it |= S_CTIME;
4451
4452 if (IS_I_VERSION(inode))
4453 sync_it |= S_VERSION;
4454
4455 if (!sync_it)
4456 return 0;
4457
4458 /* Finally allowed to write? Takes lock. */
4459 if (mnt_want_write_file(file))
4460 return 0;
4461
4462 /* Only change inode inside the lock region */
4463 if (sync_it & S_VERSION)
4464 inode_inc_iversion(inode); 4482 inode_inc_iversion(inode);
4465 if (sync_it & S_CTIME) 4483 if (flags & S_CTIME)
4466 inode->i_ctime = now; 4484 inode->i_ctime = *now;
4467 if (sync_it & S_MTIME) 4485 if (flags & S_MTIME)
4468 inode->i_mtime = now; 4486 inode->i_mtime = *now;
4469 ret = btrfs_dirty_inode(inode); 4487 if (flags & S_ATIME)
4470 if (!ret) 4488 inode->i_atime = *now;
4471 mark_inode_dirty_sync(inode); 4489 return btrfs_dirty_inode(inode);
4472 mnt_drop_write(file->f_path.mnt);
4473 return ret;
4474} 4490}
4475 4491
4476/* 4492/*
@@ -4730,6 +4746,7 @@ int btrfs_add_link(struct btrfs_trans_handle *trans,
4730 4746
4731 btrfs_i_size_write(parent_inode, parent_inode->i_size + 4747 btrfs_i_size_write(parent_inode, parent_inode->i_size +
4732 name_len * 2); 4748 name_len * 2);
4749 inode_inc_iversion(parent_inode);
4733 parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME; 4750 parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME;
4734 ret = btrfs_update_inode(trans, root, parent_inode); 4751 ret = btrfs_update_inode(trans, root, parent_inode);
4735 if (ret) 4752 if (ret)
@@ -4937,6 +4954,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
4937 } 4954 }
4938 4955
4939 btrfs_inc_nlink(inode); 4956 btrfs_inc_nlink(inode);
4957 inode_inc_iversion(inode);
4940 inode->i_ctime = CURRENT_TIME; 4958 inode->i_ctime = CURRENT_TIME;
4941 ihold(inode); 4959 ihold(inode);
4942 4960
@@ -5903,9 +5921,7 @@ static void btrfs_endio_direct_write(struct bio *bio, int err)
5903 struct btrfs_dio_private *dip = bio->bi_private; 5921 struct btrfs_dio_private *dip = bio->bi_private;
5904 struct inode *inode = dip->inode; 5922 struct inode *inode = dip->inode;
5905 struct btrfs_root *root = BTRFS_I(inode)->root; 5923 struct btrfs_root *root = BTRFS_I(inode)->root;
5906 struct btrfs_trans_handle *trans;
5907 struct btrfs_ordered_extent *ordered = NULL; 5924 struct btrfs_ordered_extent *ordered = NULL;
5908 struct extent_state *cached_state = NULL;
5909 u64 ordered_offset = dip->logical_offset; 5925 u64 ordered_offset = dip->logical_offset;
5910 u64 ordered_bytes = dip->bytes; 5926 u64 ordered_bytes = dip->bytes;
5911 int ret; 5927 int ret;
@@ -5915,73 +5931,14 @@ static void btrfs_endio_direct_write(struct bio *bio, int err)
5915again: 5931again:
5916 ret = btrfs_dec_test_first_ordered_pending(inode, &ordered, 5932 ret = btrfs_dec_test_first_ordered_pending(inode, &ordered,
5917 &ordered_offset, 5933 &ordered_offset,
5918 ordered_bytes); 5934 ordered_bytes, !err);
5919 if (!ret) 5935 if (!ret)
5920 goto out_test; 5936 goto out_test;
5921 5937
5922 BUG_ON(!ordered); 5938 ordered->work.func = finish_ordered_fn;
5923 5939 ordered->work.flags = 0;
5924 trans = btrfs_join_transaction(root); 5940 btrfs_queue_worker(&root->fs_info->endio_write_workers,
5925 if (IS_ERR(trans)) { 5941 &ordered->work);
5926 err = -ENOMEM;
5927 goto out;
5928 }
5929 trans->block_rsv = &root->fs_info->delalloc_block_rsv;
5930
5931 if (test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags)) {
5932 ret = btrfs_ordered_update_i_size(inode, 0, ordered);
5933 if (!ret)
5934 err = btrfs_update_inode_fallback(trans, root, inode);
5935 goto out;
5936 }
5937
5938 lock_extent_bits(&BTRFS_I(inode)->io_tree, ordered->file_offset,
5939 ordered->file_offset + ordered->len - 1, 0,
5940 &cached_state);
5941
5942 if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags)) {
5943 ret = btrfs_mark_extent_written(trans, inode,
5944 ordered->file_offset,
5945 ordered->file_offset +
5946 ordered->len);
5947 if (ret) {
5948 err = ret;
5949 goto out_unlock;
5950 }
5951 } else {
5952 ret = insert_reserved_file_extent(trans, inode,
5953 ordered->file_offset,
5954 ordered->start,
5955 ordered->disk_len,
5956 ordered->len,
5957 ordered->len,
5958 0, 0, 0,
5959 BTRFS_FILE_EXTENT_REG);
5960 unpin_extent_cache(&BTRFS_I(inode)->extent_tree,
5961 ordered->file_offset, ordered->len);
5962 if (ret) {
5963 err = ret;
5964 WARN_ON(1);
5965 goto out_unlock;
5966 }
5967 }
5968
5969 add_pending_csums(trans, inode, ordered->file_offset, &ordered->list);
5970 ret = btrfs_ordered_update_i_size(inode, 0, ordered);
5971 if (!ret || !test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags))
5972 btrfs_update_inode_fallback(trans, root, inode);
5973 ret = 0;
5974out_unlock:
5975 unlock_extent_cached(&BTRFS_I(inode)->io_tree, ordered->file_offset,
5976 ordered->file_offset + ordered->len - 1,
5977 &cached_state, GFP_NOFS);
5978out:
5979 btrfs_delalloc_release_metadata(inode, ordered->len);
5980 btrfs_end_transaction(trans, root);
5981 ordered_offset = ordered->file_offset + ordered->len;
5982 btrfs_put_ordered_extent(ordered);
5983 btrfs_put_ordered_extent(ordered);
5984
5985out_test: 5942out_test:
5986 /* 5943 /*
5987 * our bio might span multiple ordered extents. If we haven't 5944 * our bio might span multiple ordered extents. If we haven't
@@ -5990,12 +5947,12 @@ out_test:
5990 if (ordered_offset < dip->logical_offset + dip->bytes) { 5947 if (ordered_offset < dip->logical_offset + dip->bytes) {
5991 ordered_bytes = dip->logical_offset + dip->bytes - 5948 ordered_bytes = dip->logical_offset + dip->bytes -
5992 ordered_offset; 5949 ordered_offset;
5950 ordered = NULL;
5993 goto again; 5951 goto again;
5994 } 5952 }
5995out_done: 5953out_done:
5996 bio->bi_private = dip->private; 5954 bio->bi_private = dip->private;
5997 5955
5998 kfree(dip->csums);
5999 kfree(dip); 5956 kfree(dip);
6000 5957
6001 /* If we had an error make sure to clear the uptodate flag */ 5958 /* If we had an error make sure to clear the uptodate flag */
@@ -6063,9 +6020,12 @@ static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode,
6063 int ret; 6020 int ret;
6064 6021
6065 bio_get(bio); 6022 bio_get(bio);
6066 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0); 6023
6067 if (ret) 6024 if (!write) {
6068 goto err; 6025 ret = btrfs_bio_wq_end_io(root->fs_info, bio, 0);
6026 if (ret)
6027 goto err;
6028 }
6069 6029
6070 if (skip_sum) 6030 if (skip_sum)
6071 goto map; 6031 goto map;
@@ -6485,13 +6445,13 @@ static int btrfs_releasepage(struct page *page, gfp_t gfp_flags)
6485 6445
6486static void btrfs_invalidatepage(struct page *page, unsigned long offset) 6446static void btrfs_invalidatepage(struct page *page, unsigned long offset)
6487{ 6447{
6448 struct inode *inode = page->mapping->host;
6488 struct extent_io_tree *tree; 6449 struct extent_io_tree *tree;
6489 struct btrfs_ordered_extent *ordered; 6450 struct btrfs_ordered_extent *ordered;
6490 struct extent_state *cached_state = NULL; 6451 struct extent_state *cached_state = NULL;
6491 u64 page_start = page_offset(page); 6452 u64 page_start = page_offset(page);
6492 u64 page_end = page_start + PAGE_CACHE_SIZE - 1; 6453 u64 page_end = page_start + PAGE_CACHE_SIZE - 1;
6493 6454
6494
6495 /* 6455 /*
6496 * we have the page locked, so new writeback can't start, 6456 * we have the page locked, so new writeback can't start,
6497 * and the dirty bit won't be cleared while we are here. 6457 * and the dirty bit won't be cleared while we are here.
@@ -6501,13 +6461,13 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset)
6501 */ 6461 */
6502 wait_on_page_writeback(page); 6462 wait_on_page_writeback(page);
6503 6463
6504 tree = &BTRFS_I(page->mapping->host)->io_tree; 6464 tree = &BTRFS_I(inode)->io_tree;
6505 if (offset) { 6465 if (offset) {
6506 btrfs_releasepage(page, GFP_NOFS); 6466 btrfs_releasepage(page, GFP_NOFS);
6507 return; 6467 return;
6508 } 6468 }
6509 lock_extent_bits(tree, page_start, page_end, 0, &cached_state); 6469 lock_extent_bits(tree, page_start, page_end, 0, &cached_state);
6510 ordered = btrfs_lookup_ordered_extent(page->mapping->host, 6470 ordered = btrfs_lookup_ordered_extent(inode,
6511 page_offset(page)); 6471 page_offset(page));
6512 if (ordered) { 6472 if (ordered) {
6513 /* 6473 /*
@@ -6522,9 +6482,10 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset)
6522 * whoever cleared the private bit is responsible 6482 * whoever cleared the private bit is responsible
6523 * for the finish_ordered_io 6483 * for the finish_ordered_io
6524 */ 6484 */
6525 if (TestClearPagePrivate2(page)) { 6485 if (TestClearPagePrivate2(page) &&
6526 btrfs_finish_ordered_io(page->mapping->host, 6486 btrfs_dec_test_ordered_pending(inode, &ordered, page_start,
6527 page_start, page_end); 6487 PAGE_CACHE_SIZE, 1)) {
6488 btrfs_finish_ordered_io(ordered);
6528 } 6489 }
6529 btrfs_put_ordered_extent(ordered); 6490 btrfs_put_ordered_extent(ordered);
6530 cached_state = NULL; 6491 cached_state = NULL;
@@ -6576,7 +6537,7 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
6576 6537
6577 ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); 6538 ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE);
6578 if (!ret) { 6539 if (!ret) {
6579 ret = btrfs_update_time(vma->vm_file); 6540 ret = file_update_time(vma->vm_file);
6580 reserved = 1; 6541 reserved = 1;
6581 } 6542 }
6582 if (ret) { 6543 if (ret) {
@@ -6771,7 +6732,8 @@ static int btrfs_truncate(struct inode *inode)
6771 * using truncate to replace the contents of the file will 6732 * using truncate to replace the contents of the file will
6772 * end up with a zero length file after a crash. 6733 * end up with a zero length file after a crash.
6773 */ 6734 */
6774 if (inode->i_size == 0 && BTRFS_I(inode)->ordered_data_close) 6735 if (inode->i_size == 0 && test_bit(BTRFS_INODE_ORDERED_DATA_CLOSE,
6736 &BTRFS_I(inode)->runtime_flags))
6775 btrfs_add_ordered_operation(trans, root, inode); 6737 btrfs_add_ordered_operation(trans, root, inode);
6776 6738
6777 while (1) { 6739 while (1) {
@@ -6894,7 +6856,6 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
6894 ei->root = NULL; 6856 ei->root = NULL;
6895 ei->space_info = NULL; 6857 ei->space_info = NULL;
6896 ei->generation = 0; 6858 ei->generation = 0;
6897 ei->sequence = 0;
6898 ei->last_trans = 0; 6859 ei->last_trans = 0;
6899 ei->last_sub_trans = 0; 6860 ei->last_sub_trans = 0;
6900 ei->logged_trans = 0; 6861 ei->logged_trans = 0;
@@ -6909,11 +6870,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
6909 ei->outstanding_extents = 0; 6870 ei->outstanding_extents = 0;
6910 ei->reserved_extents = 0; 6871 ei->reserved_extents = 0;
6911 6872
6912 ei->ordered_data_close = 0; 6873 ei->runtime_flags = 0;
6913 ei->orphan_meta_reserved = 0;
6914 ei->dummy_inode = 0;
6915 ei->in_defrag = 0;
6916 ei->delalloc_meta_reserved = 0;
6917 ei->force_compress = BTRFS_COMPRESS_NONE; 6874 ei->force_compress = BTRFS_COMPRESS_NONE;
6918 6875
6919 ei->delayed_node = NULL; 6876 ei->delayed_node = NULL;
@@ -6927,7 +6884,6 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
6927 mutex_init(&ei->log_mutex); 6884 mutex_init(&ei->log_mutex);
6928 mutex_init(&ei->delalloc_mutex); 6885 mutex_init(&ei->delalloc_mutex);
6929 btrfs_ordered_inode_tree_init(&ei->ordered_tree); 6886 btrfs_ordered_inode_tree_init(&ei->ordered_tree);
6930 INIT_LIST_HEAD(&ei->i_orphan);
6931 INIT_LIST_HEAD(&ei->delalloc_inodes); 6887 INIT_LIST_HEAD(&ei->delalloc_inodes);
6932 INIT_LIST_HEAD(&ei->ordered_operations); 6888 INIT_LIST_HEAD(&ei->ordered_operations);
6933 RB_CLEAR_NODE(&ei->rb_node); 6889 RB_CLEAR_NODE(&ei->rb_node);
@@ -6972,13 +6928,12 @@ void btrfs_destroy_inode(struct inode *inode)
6972 spin_unlock(&root->fs_info->ordered_extent_lock); 6928 spin_unlock(&root->fs_info->ordered_extent_lock);
6973 } 6929 }
6974 6930
6975 spin_lock(&root->orphan_lock); 6931 if (test_bit(BTRFS_INODE_HAS_ORPHAN_ITEM,
6976 if (!list_empty(&BTRFS_I(inode)->i_orphan)) { 6932 &BTRFS_I(inode)->runtime_flags)) {
6977 printk(KERN_INFO "BTRFS: inode %llu still on the orphan list\n", 6933 printk(KERN_INFO "BTRFS: inode %llu still on the orphan list\n",
6978 (unsigned long long)btrfs_ino(inode)); 6934 (unsigned long long)btrfs_ino(inode));
6979 list_del_init(&BTRFS_I(inode)->i_orphan); 6935 atomic_dec(&root->orphan_inodes);
6980 } 6936 }
6981 spin_unlock(&root->orphan_lock);
6982 6937
6983 while (1) { 6938 while (1) {
6984 ordered = btrfs_lookup_first_ordered_extent(inode, (u64)-1); 6939 ordered = btrfs_lookup_first_ordered_extent(inode, (u64)-1);
@@ -7193,6 +7148,9 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
7193 if (new_inode && new_inode->i_size && S_ISREG(old_inode->i_mode)) 7148 if (new_inode && new_inode->i_size && S_ISREG(old_inode->i_mode))
7194 btrfs_add_ordered_operation(trans, root, old_inode); 7149 btrfs_add_ordered_operation(trans, root, old_inode);
7195 7150
7151 inode_inc_iversion(old_dir);
7152 inode_inc_iversion(new_dir);
7153 inode_inc_iversion(old_inode);
7196 old_dir->i_ctime = old_dir->i_mtime = ctime; 7154 old_dir->i_ctime = old_dir->i_mtime = ctime;
7197 new_dir->i_ctime = new_dir->i_mtime = ctime; 7155 new_dir->i_ctime = new_dir->i_mtime = ctime;
7198 old_inode->i_ctime = ctime; 7156 old_inode->i_ctime = ctime;
@@ -7219,6 +7177,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
7219 } 7177 }
7220 7178
7221 if (new_inode) { 7179 if (new_inode) {
7180 inode_inc_iversion(new_inode);
7222 new_inode->i_ctime = CURRENT_TIME; 7181 new_inode->i_ctime = CURRENT_TIME;
7223 if (unlikely(btrfs_ino(new_inode) == 7182 if (unlikely(btrfs_ino(new_inode) ==
7224 BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { 7183 BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) {
@@ -7490,6 +7449,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
7490 cur_offset += ins.offset; 7449 cur_offset += ins.offset;
7491 *alloc_hint = ins.objectid + ins.offset; 7450 *alloc_hint = ins.objectid + ins.offset;
7492 7451
7452 inode_inc_iversion(inode);
7493 inode->i_ctime = CURRENT_TIME; 7453 inode->i_ctime = CURRENT_TIME;
7494 BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; 7454 BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC;
7495 if (!(mode & FALLOC_FL_KEEP_SIZE) && 7455 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
@@ -7647,6 +7607,7 @@ static const struct inode_operations btrfs_file_inode_operations = {
7647 .permission = btrfs_permission, 7607 .permission = btrfs_permission,
7648 .fiemap = btrfs_fiemap, 7608 .fiemap = btrfs_fiemap,
7649 .get_acl = btrfs_get_acl, 7609 .get_acl = btrfs_get_acl,
7610 .update_time = btrfs_update_time,
7650}; 7611};
7651static const struct inode_operations btrfs_special_inode_operations = { 7612static const struct inode_operations btrfs_special_inode_operations = {
7652 .getattr = btrfs_getattr, 7613 .getattr = btrfs_getattr,
@@ -7657,6 +7618,7 @@ static const struct inode_operations btrfs_special_inode_operations = {
7657 .listxattr = btrfs_listxattr, 7618 .listxattr = btrfs_listxattr,
7658 .removexattr = btrfs_removexattr, 7619 .removexattr = btrfs_removexattr,
7659 .get_acl = btrfs_get_acl, 7620 .get_acl = btrfs_get_acl,
7621 .update_time = btrfs_update_time,
7660}; 7622};
7661static const struct inode_operations btrfs_symlink_inode_operations = { 7623static const struct inode_operations btrfs_symlink_inode_operations = {
7662 .readlink = generic_readlink, 7624 .readlink = generic_readlink,
@@ -7670,6 +7632,7 @@ static const struct inode_operations btrfs_symlink_inode_operations = {
7670 .listxattr = btrfs_listxattr, 7632 .listxattr = btrfs_listxattr,
7671 .removexattr = btrfs_removexattr, 7633 .removexattr = btrfs_removexattr,
7672 .get_acl = btrfs_get_acl, 7634 .get_acl = btrfs_get_acl,
7635 .update_time = btrfs_update_time,
7673}; 7636};
7674 7637
7675const struct dentry_operations btrfs_dentry_operations = { 7638const struct dentry_operations btrfs_dentry_operations = {
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 14f8e1faa46e..24b776c08d99 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -261,6 +261,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
261 } 261 }
262 262
263 btrfs_update_iflags(inode); 263 btrfs_update_iflags(inode);
264 inode_inc_iversion(inode);
264 inode->i_ctime = CURRENT_TIME; 265 inode->i_ctime = CURRENT_TIME;
265 ret = btrfs_update_inode(trans, root, inode); 266 ret = btrfs_update_inode(trans, root, inode);
266 267
@@ -367,7 +368,7 @@ static noinline int create_subvol(struct btrfs_root *root,
367 return PTR_ERR(trans); 368 return PTR_ERR(trans);
368 369
369 leaf = btrfs_alloc_free_block(trans, root, root->leafsize, 370 leaf = btrfs_alloc_free_block(trans, root, root->leafsize,
370 0, objectid, NULL, 0, 0, 0, 0); 371 0, objectid, NULL, 0, 0, 0);
371 if (IS_ERR(leaf)) { 372 if (IS_ERR(leaf)) {
372 ret = PTR_ERR(leaf); 373 ret = PTR_ERR(leaf);
373 goto fail; 374 goto fail;
@@ -2262,10 +2263,12 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
2262 di_args->bytes_used = dev->bytes_used; 2263 di_args->bytes_used = dev->bytes_used;
2263 di_args->total_bytes = dev->total_bytes; 2264 di_args->total_bytes = dev->total_bytes;
2264 memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid)); 2265 memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid));
2265 if (dev->name) 2266 if (dev->name) {
2266 strncpy(di_args->path, dev->name, sizeof(di_args->path)); 2267 strncpy(di_args->path, dev->name, sizeof(di_args->path));
2267 else 2268 di_args->path[sizeof(di_args->path) - 1] = 0;
2269 } else {
2268 di_args->path[0] = '\0'; 2270 di_args->path[0] = '\0';
2271 }
2269 2272
2270out: 2273out:
2271 if (ret == 0 && copy_to_user(arg, di_args, sizeof(*di_args))) 2274 if (ret == 0 && copy_to_user(arg, di_args, sizeof(*di_args)))
@@ -2622,6 +2625,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
2622 btrfs_mark_buffer_dirty(leaf); 2625 btrfs_mark_buffer_dirty(leaf);
2623 btrfs_release_path(path); 2626 btrfs_release_path(path);
2624 2627
2628 inode_inc_iversion(inode);
2625 inode->i_mtime = inode->i_ctime = CURRENT_TIME; 2629 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
2626 2630
2627 /* 2631 /*
@@ -2914,7 +2918,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
2914 up_read(&info->groups_sem); 2918 up_read(&info->groups_sem);
2915 } 2919 }
2916 2920
2917 user_dest = (struct btrfs_ioctl_space_info *) 2921 user_dest = (struct btrfs_ioctl_space_info __user *)
2918 (arg + sizeof(struct btrfs_ioctl_space_args)); 2922 (arg + sizeof(struct btrfs_ioctl_space_args));
2919 2923
2920 if (copy_to_user(user_dest, dest_orig, alloc_size)) 2924 if (copy_to_user(user_dest, dest_orig, alloc_size))
@@ -3042,6 +3046,28 @@ static long btrfs_ioctl_scrub_progress(struct btrfs_root *root,
3042 return ret; 3046 return ret;
3043} 3047}
3044 3048
3049static long btrfs_ioctl_get_dev_stats(struct btrfs_root *root,
3050 void __user *arg, int reset_after_read)
3051{
3052 struct btrfs_ioctl_get_dev_stats *sa;
3053 int ret;
3054
3055 if (reset_after_read && !capable(CAP_SYS_ADMIN))
3056 return -EPERM;
3057
3058 sa = memdup_user(arg, sizeof(*sa));
3059 if (IS_ERR(sa))
3060 return PTR_ERR(sa);
3061
3062 ret = btrfs_get_dev_stats(root, sa, reset_after_read);
3063
3064 if (copy_to_user(arg, sa, sizeof(*sa)))
3065 ret = -EFAULT;
3066
3067 kfree(sa);
3068 return ret;
3069}
3070
3045static long btrfs_ioctl_ino_to_path(struct btrfs_root *root, void __user *arg) 3071static long btrfs_ioctl_ino_to_path(struct btrfs_root *root, void __user *arg)
3046{ 3072{
3047 int ret = 0; 3073 int ret = 0;
@@ -3212,8 +3238,9 @@ void update_ioctl_balance_args(struct btrfs_fs_info *fs_info, int lock,
3212 } 3238 }
3213} 3239}
3214 3240
3215static long btrfs_ioctl_balance(struct btrfs_root *root, void __user *arg) 3241static long btrfs_ioctl_balance(struct file *file, void __user *arg)
3216{ 3242{
3243 struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
3217 struct btrfs_fs_info *fs_info = root->fs_info; 3244 struct btrfs_fs_info *fs_info = root->fs_info;
3218 struct btrfs_ioctl_balance_args *bargs; 3245 struct btrfs_ioctl_balance_args *bargs;
3219 struct btrfs_balance_control *bctl; 3246 struct btrfs_balance_control *bctl;
@@ -3225,6 +3252,10 @@ static long btrfs_ioctl_balance(struct btrfs_root *root, void __user *arg)
3225 if (fs_info->sb->s_flags & MS_RDONLY) 3252 if (fs_info->sb->s_flags & MS_RDONLY)
3226 return -EROFS; 3253 return -EROFS;
3227 3254
3255 ret = mnt_want_write(file->f_path.mnt);
3256 if (ret)
3257 return ret;
3258
3228 mutex_lock(&fs_info->volume_mutex); 3259 mutex_lock(&fs_info->volume_mutex);
3229 mutex_lock(&fs_info->balance_mutex); 3260 mutex_lock(&fs_info->balance_mutex);
3230 3261
@@ -3291,6 +3322,7 @@ out_bargs:
3291out: 3322out:
3292 mutex_unlock(&fs_info->balance_mutex); 3323 mutex_unlock(&fs_info->balance_mutex);
3293 mutex_unlock(&fs_info->volume_mutex); 3324 mutex_unlock(&fs_info->volume_mutex);
3325 mnt_drop_write(file->f_path.mnt);
3294 return ret; 3326 return ret;
3295} 3327}
3296 3328
@@ -3386,7 +3418,7 @@ long btrfs_ioctl(struct file *file, unsigned int
3386 case BTRFS_IOC_DEV_INFO: 3418 case BTRFS_IOC_DEV_INFO:
3387 return btrfs_ioctl_dev_info(root, argp); 3419 return btrfs_ioctl_dev_info(root, argp);
3388 case BTRFS_IOC_BALANCE: 3420 case BTRFS_IOC_BALANCE:
3389 return btrfs_ioctl_balance(root, NULL); 3421 return btrfs_ioctl_balance(file, NULL);
3390 case BTRFS_IOC_CLONE: 3422 case BTRFS_IOC_CLONE:
3391 return btrfs_ioctl_clone(file, arg, 0, 0, 0); 3423 return btrfs_ioctl_clone(file, arg, 0, 0, 0);
3392 case BTRFS_IOC_CLONE_RANGE: 3424 case BTRFS_IOC_CLONE_RANGE:
@@ -3419,11 +3451,15 @@ long btrfs_ioctl(struct file *file, unsigned int
3419 case BTRFS_IOC_SCRUB_PROGRESS: 3451 case BTRFS_IOC_SCRUB_PROGRESS:
3420 return btrfs_ioctl_scrub_progress(root, argp); 3452 return btrfs_ioctl_scrub_progress(root, argp);
3421 case BTRFS_IOC_BALANCE_V2: 3453 case BTRFS_IOC_BALANCE_V2:
3422 return btrfs_ioctl_balance(root, argp); 3454 return btrfs_ioctl_balance(file, argp);
3423 case BTRFS_IOC_BALANCE_CTL: 3455 case BTRFS_IOC_BALANCE_CTL:
3424 return btrfs_ioctl_balance_ctl(root, arg); 3456 return btrfs_ioctl_balance_ctl(root, arg);
3425 case BTRFS_IOC_BALANCE_PROGRESS: 3457 case BTRFS_IOC_BALANCE_PROGRESS:
3426 return btrfs_ioctl_balance_progress(root, argp); 3458 return btrfs_ioctl_balance_progress(root, argp);
3459 case BTRFS_IOC_GET_DEV_STATS:
3460 return btrfs_ioctl_get_dev_stats(root, argp, 0);
3461 case BTRFS_IOC_GET_AND_RESET_DEV_STATS:
3462 return btrfs_ioctl_get_dev_stats(root, argp, 1);
3427 } 3463 }
3428 3464
3429 return -ENOTTY; 3465 return -ENOTTY;
diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
index 086e6bdae1c4..497c530724cf 100644
--- a/fs/btrfs/ioctl.h
+++ b/fs/btrfs/ioctl.h
@@ -266,6 +266,35 @@ struct btrfs_ioctl_logical_ino_args {
266 __u64 inodes; 266 __u64 inodes;
267}; 267};
268 268
269enum btrfs_dev_stat_values {
270 /* disk I/O failure stats */
271 BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */
272 BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */
273 BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */
274
275 /* stats for indirect indications for I/O failures */
276 BTRFS_DEV_STAT_CORRUPTION_ERRS, /* checksum error, bytenr error or
277 * contents is illegal: this is an
278 * indication that the block was damaged
279 * during read or write, or written to
280 * wrong location or read from wrong
281 * location */
282 BTRFS_DEV_STAT_GENERATION_ERRS, /* an indication that blocks have not
283 * been written */
284
285 BTRFS_DEV_STAT_VALUES_MAX
286};
287
288struct btrfs_ioctl_get_dev_stats {
289 __u64 devid; /* in */
290 __u64 nr_items; /* in/out */
291
292 /* out values: */
293 __u64 values[BTRFS_DEV_STAT_VALUES_MAX];
294
295 __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
296};
297
269#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ 298#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
270 struct btrfs_ioctl_vol_args) 299 struct btrfs_ioctl_vol_args)
271#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \ 300#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
@@ -330,5 +359,9 @@ struct btrfs_ioctl_logical_ino_args {
330 struct btrfs_ioctl_ino_path_args) 359 struct btrfs_ioctl_ino_path_args)
331#define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \ 360#define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
332 struct btrfs_ioctl_ino_path_args) 361 struct btrfs_ioctl_ino_path_args)
362#define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
363 struct btrfs_ioctl_get_dev_stats)
364#define BTRFS_IOC_GET_AND_RESET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 53, \
365 struct btrfs_ioctl_get_dev_stats)
333 366
334#endif 367#endif
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index bbf6d0d9aebe..9e138cdc36c5 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -196,7 +196,7 @@ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
196 entry->len = len; 196 entry->len = len;
197 entry->disk_len = disk_len; 197 entry->disk_len = disk_len;
198 entry->bytes_left = len; 198 entry->bytes_left = len;
199 entry->inode = inode; 199 entry->inode = igrab(inode);
200 entry->compress_type = compress_type; 200 entry->compress_type = compress_type;
201 if (type != BTRFS_ORDERED_IO_DONE && type != BTRFS_ORDERED_COMPLETE) 201 if (type != BTRFS_ORDERED_IO_DONE && type != BTRFS_ORDERED_COMPLETE)
202 set_bit(type, &entry->flags); 202 set_bit(type, &entry->flags);
@@ -212,12 +212,12 @@ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
212 212
213 trace_btrfs_ordered_extent_add(inode, entry); 213 trace_btrfs_ordered_extent_add(inode, entry);
214 214
215 spin_lock(&tree->lock); 215 spin_lock_irq(&tree->lock);
216 node = tree_insert(&tree->tree, file_offset, 216 node = tree_insert(&tree->tree, file_offset,
217 &entry->rb_node); 217 &entry->rb_node);
218 if (node) 218 if (node)
219 ordered_data_tree_panic(inode, -EEXIST, file_offset); 219 ordered_data_tree_panic(inode, -EEXIST, file_offset);
220 spin_unlock(&tree->lock); 220 spin_unlock_irq(&tree->lock);
221 221
222 spin_lock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock); 222 spin_lock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock);
223 list_add_tail(&entry->root_extent_list, 223 list_add_tail(&entry->root_extent_list,
@@ -264,9 +264,9 @@ void btrfs_add_ordered_sum(struct inode *inode,
264 struct btrfs_ordered_inode_tree *tree; 264 struct btrfs_ordered_inode_tree *tree;
265 265
266 tree = &BTRFS_I(inode)->ordered_tree; 266 tree = &BTRFS_I(inode)->ordered_tree;
267 spin_lock(&tree->lock); 267 spin_lock_irq(&tree->lock);
268 list_add_tail(&sum->list, &entry->list); 268 list_add_tail(&sum->list, &entry->list);
269 spin_unlock(&tree->lock); 269 spin_unlock_irq(&tree->lock);
270} 270}
271 271
272/* 272/*
@@ -283,18 +283,19 @@ void btrfs_add_ordered_sum(struct inode *inode,
283 */ 283 */
284int btrfs_dec_test_first_ordered_pending(struct inode *inode, 284int btrfs_dec_test_first_ordered_pending(struct inode *inode,
285 struct btrfs_ordered_extent **cached, 285 struct btrfs_ordered_extent **cached,
286 u64 *file_offset, u64 io_size) 286 u64 *file_offset, u64 io_size, int uptodate)
287{ 287{
288 struct btrfs_ordered_inode_tree *tree; 288 struct btrfs_ordered_inode_tree *tree;
289 struct rb_node *node; 289 struct rb_node *node;
290 struct btrfs_ordered_extent *entry = NULL; 290 struct btrfs_ordered_extent *entry = NULL;
291 int ret; 291 int ret;
292 unsigned long flags;
292 u64 dec_end; 293 u64 dec_end;
293 u64 dec_start; 294 u64 dec_start;
294 u64 to_dec; 295 u64 to_dec;
295 296
296 tree = &BTRFS_I(inode)->ordered_tree; 297 tree = &BTRFS_I(inode)->ordered_tree;
297 spin_lock(&tree->lock); 298 spin_lock_irqsave(&tree->lock, flags);
298 node = tree_search(tree, *file_offset); 299 node = tree_search(tree, *file_offset);
299 if (!node) { 300 if (!node) {
300 ret = 1; 301 ret = 1;
@@ -323,6 +324,9 @@ int btrfs_dec_test_first_ordered_pending(struct inode *inode,
323 (unsigned long long)to_dec); 324 (unsigned long long)to_dec);
324 } 325 }
325 entry->bytes_left -= to_dec; 326 entry->bytes_left -= to_dec;
327 if (!uptodate)
328 set_bit(BTRFS_ORDERED_IOERR, &entry->flags);
329
326 if (entry->bytes_left == 0) 330 if (entry->bytes_left == 0)
327 ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags); 331 ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags);
328 else 332 else
@@ -332,7 +336,7 @@ out:
332 *cached = entry; 336 *cached = entry;
333 atomic_inc(&entry->refs); 337 atomic_inc(&entry->refs);
334 } 338 }
335 spin_unlock(&tree->lock); 339 spin_unlock_irqrestore(&tree->lock, flags);
336 return ret == 0; 340 return ret == 0;
337} 341}
338 342
@@ -347,15 +351,21 @@ out:
347 */ 351 */
348int btrfs_dec_test_ordered_pending(struct inode *inode, 352int btrfs_dec_test_ordered_pending(struct inode *inode,
349 struct btrfs_ordered_extent **cached, 353 struct btrfs_ordered_extent **cached,
350 u64 file_offset, u64 io_size) 354 u64 file_offset, u64 io_size, int uptodate)
351{ 355{
352 struct btrfs_ordered_inode_tree *tree; 356 struct btrfs_ordered_inode_tree *tree;
353 struct rb_node *node; 357 struct rb_node *node;
354 struct btrfs_ordered_extent *entry = NULL; 358 struct btrfs_ordered_extent *entry = NULL;
359 unsigned long flags;
355 int ret; 360 int ret;
356 361
357 tree = &BTRFS_I(inode)->ordered_tree; 362 tree = &BTRFS_I(inode)->ordered_tree;
358 spin_lock(&tree->lock); 363 spin_lock_irqsave(&tree->lock, flags);
364 if (cached && *cached) {
365 entry = *cached;
366 goto have_entry;
367 }
368
359 node = tree_search(tree, file_offset); 369 node = tree_search(tree, file_offset);
360 if (!node) { 370 if (!node) {
361 ret = 1; 371 ret = 1;
@@ -363,6 +373,7 @@ int btrfs_dec_test_ordered_pending(struct inode *inode,
363 } 373 }
364 374
365 entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); 375 entry = rb_entry(node, struct btrfs_ordered_extent, rb_node);
376have_entry:
366 if (!offset_in_entry(entry, file_offset)) { 377 if (!offset_in_entry(entry, file_offset)) {
367 ret = 1; 378 ret = 1;
368 goto out; 379 goto out;
@@ -374,6 +385,9 @@ int btrfs_dec_test_ordered_pending(struct inode *inode,
374 (unsigned long long)io_size); 385 (unsigned long long)io_size);
375 } 386 }
376 entry->bytes_left -= io_size; 387 entry->bytes_left -= io_size;
388 if (!uptodate)
389 set_bit(BTRFS_ORDERED_IOERR, &entry->flags);
390
377 if (entry->bytes_left == 0) 391 if (entry->bytes_left == 0)
378 ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags); 392 ret = test_and_set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags);
379 else 393 else
@@ -383,7 +397,7 @@ out:
383 *cached = entry; 397 *cached = entry;
384 atomic_inc(&entry->refs); 398 atomic_inc(&entry->refs);
385 } 399 }
386 spin_unlock(&tree->lock); 400 spin_unlock_irqrestore(&tree->lock, flags);
387 return ret == 0; 401 return ret == 0;
388} 402}
389 403
@@ -399,6 +413,8 @@ void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry)
399 trace_btrfs_ordered_extent_put(entry->inode, entry); 413 trace_btrfs_ordered_extent_put(entry->inode, entry);
400 414
401 if (atomic_dec_and_test(&entry->refs)) { 415 if (atomic_dec_and_test(&entry->refs)) {
416 if (entry->inode)
417 btrfs_add_delayed_iput(entry->inode);
402 while (!list_empty(&entry->list)) { 418 while (!list_empty(&entry->list)) {
403 cur = entry->list.next; 419 cur = entry->list.next;
404 sum = list_entry(cur, struct btrfs_ordered_sum, list); 420 sum = list_entry(cur, struct btrfs_ordered_sum, list);
@@ -411,21 +427,22 @@ void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry)
411 427
412/* 428/*
413 * remove an ordered extent from the tree. No references are dropped 429 * remove an ordered extent from the tree. No references are dropped
414 * and you must wake_up entry->wait. You must hold the tree lock 430 * and waiters are woken up.
415 * while you call this function.
416 */ 431 */
417static void __btrfs_remove_ordered_extent(struct inode *inode, 432void btrfs_remove_ordered_extent(struct inode *inode,
418 struct btrfs_ordered_extent *entry) 433 struct btrfs_ordered_extent *entry)
419{ 434{
420 struct btrfs_ordered_inode_tree *tree; 435 struct btrfs_ordered_inode_tree *tree;
421 struct btrfs_root *root = BTRFS_I(inode)->root; 436 struct btrfs_root *root = BTRFS_I(inode)->root;
422 struct rb_node *node; 437 struct rb_node *node;
423 438
424 tree = &BTRFS_I(inode)->ordered_tree; 439 tree = &BTRFS_I(inode)->ordered_tree;
440 spin_lock_irq(&tree->lock);
425 node = &entry->rb_node; 441 node = &entry->rb_node;
426 rb_erase(node, &tree->tree); 442 rb_erase(node, &tree->tree);
427 tree->last = NULL; 443 tree->last = NULL;
428 set_bit(BTRFS_ORDERED_COMPLETE, &entry->flags); 444 set_bit(BTRFS_ORDERED_COMPLETE, &entry->flags);
445 spin_unlock_irq(&tree->lock);
429 446
430 spin_lock(&root->fs_info->ordered_extent_lock); 447 spin_lock(&root->fs_info->ordered_extent_lock);
431 list_del_init(&entry->root_extent_list); 448 list_del_init(&entry->root_extent_list);
@@ -442,21 +459,6 @@ static void __btrfs_remove_ordered_extent(struct inode *inode,
442 list_del_init(&BTRFS_I(inode)->ordered_operations); 459 list_del_init(&BTRFS_I(inode)->ordered_operations);
443 } 460 }
444 spin_unlock(&root->fs_info->ordered_extent_lock); 461 spin_unlock(&root->fs_info->ordered_extent_lock);
445}
446
447/*
448 * remove an ordered extent from the tree. No references are dropped
449 * but any waiters are woken.
450 */
451void btrfs_remove_ordered_extent(struct inode *inode,
452 struct btrfs_ordered_extent *entry)
453{
454 struct btrfs_ordered_inode_tree *tree;
455
456 tree = &BTRFS_I(inode)->ordered_tree;
457 spin_lock(&tree->lock);
458 __btrfs_remove_ordered_extent(inode, entry);
459 spin_unlock(&tree->lock);
460 wake_up(&entry->wait); 462 wake_up(&entry->wait);
461} 463}
462 464
@@ -621,19 +623,11 @@ void btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len)
621 if (orig_end > INT_LIMIT(loff_t)) 623 if (orig_end > INT_LIMIT(loff_t))
622 orig_end = INT_LIMIT(loff_t); 624 orig_end = INT_LIMIT(loff_t);
623 } 625 }
624again: 626
625 /* start IO across the range first to instantiate any delalloc 627 /* start IO across the range first to instantiate any delalloc
626 * extents 628 * extents
627 */ 629 */
628 filemap_fdatawrite_range(inode->i_mapping, start, orig_end); 630 filemap_write_and_wait_range(inode->i_mapping, start, orig_end);
629
630 /* The compression code will leave pages locked but return from
631 * writepage without setting the page writeback. Starting again
632 * with WB_SYNC_ALL will end up waiting for the IO to actually start.
633 */
634 filemap_fdatawrite_range(inode->i_mapping, start, orig_end);
635
636 filemap_fdatawait_range(inode->i_mapping, start, orig_end);
637 631
638 end = orig_end; 632 end = orig_end;
639 found = 0; 633 found = 0;
@@ -657,11 +651,6 @@ again:
657 break; 651 break;
658 end--; 652 end--;
659 } 653 }
660 if (found || test_range_bit(&BTRFS_I(inode)->io_tree, start, orig_end,
661 EXTENT_DELALLOC, 0, NULL)) {
662 schedule_timeout(1);
663 goto again;
664 }
665} 654}
666 655
667/* 656/*
@@ -676,7 +665,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode,
676 struct btrfs_ordered_extent *entry = NULL; 665 struct btrfs_ordered_extent *entry = NULL;
677 666
678 tree = &BTRFS_I(inode)->ordered_tree; 667 tree = &BTRFS_I(inode)->ordered_tree;
679 spin_lock(&tree->lock); 668 spin_lock_irq(&tree->lock);
680 node = tree_search(tree, file_offset); 669 node = tree_search(tree, file_offset);
681 if (!node) 670 if (!node)
682 goto out; 671 goto out;
@@ -687,7 +676,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode,
687 if (entry) 676 if (entry)
688 atomic_inc(&entry->refs); 677 atomic_inc(&entry->refs);
689out: 678out:
690 spin_unlock(&tree->lock); 679 spin_unlock_irq(&tree->lock);
691 return entry; 680 return entry;
692} 681}
693 682
@@ -703,7 +692,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_range(struct inode *inode,
703 struct btrfs_ordered_extent *entry = NULL; 692 struct btrfs_ordered_extent *entry = NULL;
704 693
705 tree = &BTRFS_I(inode)->ordered_tree; 694 tree = &BTRFS_I(inode)->ordered_tree;
706 spin_lock(&tree->lock); 695 spin_lock_irq(&tree->lock);
707 node = tree_search(tree, file_offset); 696 node = tree_search(tree, file_offset);
708 if (!node) { 697 if (!node) {
709 node = tree_search(tree, file_offset + len); 698 node = tree_search(tree, file_offset + len);
@@ -728,7 +717,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_range(struct inode *inode,
728out: 717out:
729 if (entry) 718 if (entry)
730 atomic_inc(&entry->refs); 719 atomic_inc(&entry->refs);
731 spin_unlock(&tree->lock); 720 spin_unlock_irq(&tree->lock);
732 return entry; 721 return entry;
733} 722}
734 723
@@ -744,7 +733,7 @@ btrfs_lookup_first_ordered_extent(struct inode *inode, u64 file_offset)
744 struct btrfs_ordered_extent *entry = NULL; 733 struct btrfs_ordered_extent *entry = NULL;
745 734
746 tree = &BTRFS_I(inode)->ordered_tree; 735 tree = &BTRFS_I(inode)->ordered_tree;
747 spin_lock(&tree->lock); 736 spin_lock_irq(&tree->lock);
748 node = tree_search(tree, file_offset); 737 node = tree_search(tree, file_offset);
749 if (!node) 738 if (!node)
750 goto out; 739 goto out;
@@ -752,7 +741,7 @@ btrfs_lookup_first_ordered_extent(struct inode *inode, u64 file_offset)
752 entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); 741 entry = rb_entry(node, struct btrfs_ordered_extent, rb_node);
753 atomic_inc(&entry->refs); 742 atomic_inc(&entry->refs);
754out: 743out:
755 spin_unlock(&tree->lock); 744 spin_unlock_irq(&tree->lock);
756 return entry; 745 return entry;
757} 746}
758 747
@@ -764,7 +753,6 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset,
764 struct btrfs_ordered_extent *ordered) 753 struct btrfs_ordered_extent *ordered)
765{ 754{
766 struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree; 755 struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree;
767 struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
768 u64 disk_i_size; 756 u64 disk_i_size;
769 u64 new_i_size; 757 u64 new_i_size;
770 u64 i_size_test; 758 u64 i_size_test;
@@ -779,7 +767,7 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset,
779 else 767 else
780 offset = ALIGN(offset, BTRFS_I(inode)->root->sectorsize); 768 offset = ALIGN(offset, BTRFS_I(inode)->root->sectorsize);
781 769
782 spin_lock(&tree->lock); 770 spin_lock_irq(&tree->lock);
783 disk_i_size = BTRFS_I(inode)->disk_i_size; 771 disk_i_size = BTRFS_I(inode)->disk_i_size;
784 772
785 /* truncate file */ 773 /* truncate file */
@@ -798,14 +786,6 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset,
798 } 786 }
799 787
800 /* 788 /*
801 * we can't update the disk_isize if there are delalloc bytes
802 * between disk_i_size and this ordered extent
803 */
804 if (test_range_bit(io_tree, disk_i_size, offset - 1,
805 EXTENT_DELALLOC, 0, NULL)) {
806 goto out;
807 }
808 /*
809 * walk backward from this ordered extent to disk_i_size. 789 * walk backward from this ordered extent to disk_i_size.
810 * if we find an ordered extent then we can't update disk i_size 790 * if we find an ordered extent then we can't update disk i_size
811 * yet 791 * yet
@@ -825,15 +805,18 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset,
825 } 805 }
826 node = prev; 806 node = prev;
827 } 807 }
828 while (node) { 808 for (; node; node = rb_prev(node)) {
829 test = rb_entry(node, struct btrfs_ordered_extent, rb_node); 809 test = rb_entry(node, struct btrfs_ordered_extent, rb_node);
810
811 /* We treat this entry as if it doesnt exist */
812 if (test_bit(BTRFS_ORDERED_UPDATED_ISIZE, &test->flags))
813 continue;
830 if (test->file_offset + test->len <= disk_i_size) 814 if (test->file_offset + test->len <= disk_i_size)
831 break; 815 break;
832 if (test->file_offset >= i_size) 816 if (test->file_offset >= i_size)
833 break; 817 break;
834 if (test->file_offset >= disk_i_size) 818 if (test->file_offset >= disk_i_size)
835 goto out; 819 goto out;
836 node = rb_prev(node);
837 } 820 }
838 new_i_size = min_t(u64, offset, i_size); 821 new_i_size = min_t(u64, offset, i_size);
839 822
@@ -851,43 +834,49 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset,
851 else 834 else
852 node = rb_first(&tree->tree); 835 node = rb_first(&tree->tree);
853 } 836 }
854 i_size_test = 0; 837
855 if (node) { 838 /*
856 /* 839 * We are looking for an area between our current extent and the next
857 * do we have an area where IO might have finished 840 * ordered extent to update the i_size to. There are 3 cases here
858 * between our ordered extent and the next one. 841 *
859 */ 842 * 1) We don't actually have anything and we can update to i_size.
843 * 2) We have stuff but they already did their i_size update so again we
844 * can just update to i_size.
845 * 3) We have an outstanding ordered extent so the most we can update
846 * our disk_i_size to is the start of the next offset.
847 */
848 i_size_test = i_size;
849 for (; node; node = rb_next(node)) {
860 test = rb_entry(node, struct btrfs_ordered_extent, rb_node); 850 test = rb_entry(node, struct btrfs_ordered_extent, rb_node);
861 if (test->file_offset > offset) 851
852 if (test_bit(BTRFS_ORDERED_UPDATED_ISIZE, &test->flags))
853 continue;
854 if (test->file_offset > offset) {
862 i_size_test = test->file_offset; 855 i_size_test = test->file_offset;
863 } else { 856 break;
864 i_size_test = i_size; 857 }
865 } 858 }
866 859
867 /* 860 /*
868 * i_size_test is the end of a region after this ordered 861 * i_size_test is the end of a region after this ordered
869 * extent where there are no ordered extents. As long as there 862 * extent where there are no ordered extents, we can safely set
870 * are no delalloc bytes in this area, it is safe to update 863 * disk_i_size to this.
871 * disk_i_size to the end of the region.
872 */ 864 */
873 if (i_size_test > offset && 865 if (i_size_test > offset)
874 !test_range_bit(io_tree, offset, i_size_test - 1,
875 EXTENT_DELALLOC, 0, NULL)) {
876 new_i_size = min_t(u64, i_size_test, i_size); 866 new_i_size = min_t(u64, i_size_test, i_size);
877 }
878 BTRFS_I(inode)->disk_i_size = new_i_size; 867 BTRFS_I(inode)->disk_i_size = new_i_size;
879 ret = 0; 868 ret = 0;
880out: 869out:
881 /* 870 /*
882 * we need to remove the ordered extent with the tree lock held 871 * We need to do this because we can't remove ordered extents until
883 * so that other people calling this function don't find our fully 872 * after the i_disk_size has been updated and then the inode has been
884 * processed ordered entry and skip updating the i_size 873 * updated to reflect the change, so we need to tell anybody who finds
874 * this ordered extent that we've already done all the real work, we
875 * just haven't completed all the other work.
885 */ 876 */
886 if (ordered) 877 if (ordered)
887 __btrfs_remove_ordered_extent(inode, ordered); 878 set_bit(BTRFS_ORDERED_UPDATED_ISIZE, &ordered->flags);
888 spin_unlock(&tree->lock); 879 spin_unlock_irq(&tree->lock);
889 if (ordered)
890 wake_up(&ordered->wait);
891 return ret; 880 return ret;
892} 881}
893 882
@@ -912,7 +901,7 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr,
912 if (!ordered) 901 if (!ordered)
913 return 1; 902 return 1;
914 903
915 spin_lock(&tree->lock); 904 spin_lock_irq(&tree->lock);
916 list_for_each_entry_reverse(ordered_sum, &ordered->list, list) { 905 list_for_each_entry_reverse(ordered_sum, &ordered->list, list) {
917 if (disk_bytenr >= ordered_sum->bytenr) { 906 if (disk_bytenr >= ordered_sum->bytenr) {
918 num_sectors = ordered_sum->len / sectorsize; 907 num_sectors = ordered_sum->len / sectorsize;
@@ -927,7 +916,7 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr,
927 } 916 }
928 } 917 }
929out: 918out:
930 spin_unlock(&tree->lock); 919 spin_unlock_irq(&tree->lock);
931 btrfs_put_ordered_extent(ordered); 920 btrfs_put_ordered_extent(ordered);
932 return ret; 921 return ret;
933} 922}
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index c355ad4dc1a6..e03c560d2997 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -74,6 +74,12 @@ struct btrfs_ordered_sum {
74 74
75#define BTRFS_ORDERED_DIRECT 5 /* set when we're doing DIO with this extent */ 75#define BTRFS_ORDERED_DIRECT 5 /* set when we're doing DIO with this extent */
76 76
77#define BTRFS_ORDERED_IOERR 6 /* We had an io error when writing this out */
78
79#define BTRFS_ORDERED_UPDATED_ISIZE 7 /* indicates wether this ordered extent
80 * has done its due diligence in updating
81 * the isize. */
82
77struct btrfs_ordered_extent { 83struct btrfs_ordered_extent {
78 /* logical offset in the file */ 84 /* logical offset in the file */
79 u64 file_offset; 85 u64 file_offset;
@@ -113,6 +119,8 @@ struct btrfs_ordered_extent {
113 119
114 /* a per root list of all the pending ordered extents */ 120 /* a per root list of all the pending ordered extents */
115 struct list_head root_extent_list; 121 struct list_head root_extent_list;
122
123 struct btrfs_work work;
116}; 124};
117 125
118 126
@@ -143,10 +151,11 @@ void btrfs_remove_ordered_extent(struct inode *inode,
143 struct btrfs_ordered_extent *entry); 151 struct btrfs_ordered_extent *entry);
144int btrfs_dec_test_ordered_pending(struct inode *inode, 152int btrfs_dec_test_ordered_pending(struct inode *inode,
145 struct btrfs_ordered_extent **cached, 153 struct btrfs_ordered_extent **cached,
146 u64 file_offset, u64 io_size); 154 u64 file_offset, u64 io_size, int uptodate);
147int btrfs_dec_test_first_ordered_pending(struct inode *inode, 155int btrfs_dec_test_first_ordered_pending(struct inode *inode,
148 struct btrfs_ordered_extent **cached, 156 struct btrfs_ordered_extent **cached,
149 u64 *file_offset, u64 io_size); 157 u64 *file_offset, u64 io_size,
158 int uptodate);
150int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, 159int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
151 u64 start, u64 len, u64 disk_len, int type); 160 u64 start, u64 len, u64 disk_len, int type);
152int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset, 161int btrfs_add_ordered_extent_dio(struct inode *inode, u64 file_offset,
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index f38e452486b8..5e23684887eb 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -294,6 +294,9 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
294 btrfs_dev_extent_chunk_offset(l, dev_extent), 294 btrfs_dev_extent_chunk_offset(l, dev_extent),
295 (unsigned long long) 295 (unsigned long long)
296 btrfs_dev_extent_length(l, dev_extent)); 296 btrfs_dev_extent_length(l, dev_extent));
297 case BTRFS_DEV_STATS_KEY:
298 printk(KERN_INFO "\t\tdevice stats\n");
299 break;
297 }; 300 };
298 } 301 }
299} 302}
diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c
index ac5d01085884..48a4882d8ad5 100644
--- a/fs/btrfs/reada.c
+++ b/fs/btrfs/reada.c
@@ -718,13 +718,18 @@ static void reada_start_machine_worker(struct btrfs_work *work)
718{ 718{
719 struct reada_machine_work *rmw; 719 struct reada_machine_work *rmw;
720 struct btrfs_fs_info *fs_info; 720 struct btrfs_fs_info *fs_info;
721 int old_ioprio;
721 722
722 rmw = container_of(work, struct reada_machine_work, work); 723 rmw = container_of(work, struct reada_machine_work, work);
723 fs_info = rmw->fs_info; 724 fs_info = rmw->fs_info;
724 725
725 kfree(rmw); 726 kfree(rmw);
726 727
728 old_ioprio = IOPRIO_PRIO_VALUE(task_nice_ioclass(current),
729 task_nice_ioprio(current));
730 set_task_ioprio(current, BTRFS_IOPRIO_READA);
727 __reada_start_machine(fs_info); 731 __reada_start_machine(fs_info);
732 set_task_ioprio(current, old_ioprio);
728} 733}
729 734
730static void __reada_start_machine(struct btrfs_fs_info *fs_info) 735static void __reada_start_machine(struct btrfs_fs_info *fs_info)
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 2f3d6f917fb3..a38cfa4f251e 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -50,7 +50,7 @@ struct scrub_dev;
50struct scrub_page { 50struct scrub_page {
51 struct scrub_block *sblock; 51 struct scrub_block *sblock;
52 struct page *page; 52 struct page *page;
53 struct block_device *bdev; 53 struct btrfs_device *dev;
54 u64 flags; /* extent flags */ 54 u64 flags; /* extent flags */
55 u64 generation; 55 u64 generation;
56 u64 logical; 56 u64 logical;
@@ -86,6 +86,7 @@ struct scrub_block {
86 unsigned int header_error:1; 86 unsigned int header_error:1;
87 unsigned int checksum_error:1; 87 unsigned int checksum_error:1;
88 unsigned int no_io_error_seen:1; 88 unsigned int no_io_error_seen:1;
89 unsigned int generation_error:1; /* also sets header_error */
89 }; 90 };
90}; 91};
91 92
@@ -675,6 +676,8 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
675 sdev->stat.read_errors++; 676 sdev->stat.read_errors++;
676 sdev->stat.uncorrectable_errors++; 677 sdev->stat.uncorrectable_errors++;
677 spin_unlock(&sdev->stat_lock); 678 spin_unlock(&sdev->stat_lock);
679 btrfs_dev_stat_inc_and_print(sdev->dev,
680 BTRFS_DEV_STAT_READ_ERRS);
678 goto out; 681 goto out;
679 } 682 }
680 683
@@ -686,6 +689,8 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
686 sdev->stat.read_errors++; 689 sdev->stat.read_errors++;
687 sdev->stat.uncorrectable_errors++; 690 sdev->stat.uncorrectable_errors++;
688 spin_unlock(&sdev->stat_lock); 691 spin_unlock(&sdev->stat_lock);
692 btrfs_dev_stat_inc_and_print(sdev->dev,
693 BTRFS_DEV_STAT_READ_ERRS);
689 goto out; 694 goto out;
690 } 695 }
691 BUG_ON(failed_mirror_index >= BTRFS_MAX_MIRRORS); 696 BUG_ON(failed_mirror_index >= BTRFS_MAX_MIRRORS);
@@ -699,6 +704,8 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
699 sdev->stat.read_errors++; 704 sdev->stat.read_errors++;
700 sdev->stat.uncorrectable_errors++; 705 sdev->stat.uncorrectable_errors++;
701 spin_unlock(&sdev->stat_lock); 706 spin_unlock(&sdev->stat_lock);
707 btrfs_dev_stat_inc_and_print(sdev->dev,
708 BTRFS_DEV_STAT_READ_ERRS);
702 goto out; 709 goto out;
703 } 710 }
704 711
@@ -725,12 +732,16 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
725 spin_unlock(&sdev->stat_lock); 732 spin_unlock(&sdev->stat_lock);
726 if (__ratelimit(&_rs)) 733 if (__ratelimit(&_rs))
727 scrub_print_warning("i/o error", sblock_to_check); 734 scrub_print_warning("i/o error", sblock_to_check);
735 btrfs_dev_stat_inc_and_print(sdev->dev,
736 BTRFS_DEV_STAT_READ_ERRS);
728 } else if (sblock_bad->checksum_error) { 737 } else if (sblock_bad->checksum_error) {
729 spin_lock(&sdev->stat_lock); 738 spin_lock(&sdev->stat_lock);
730 sdev->stat.csum_errors++; 739 sdev->stat.csum_errors++;
731 spin_unlock(&sdev->stat_lock); 740 spin_unlock(&sdev->stat_lock);
732 if (__ratelimit(&_rs)) 741 if (__ratelimit(&_rs))
733 scrub_print_warning("checksum error", sblock_to_check); 742 scrub_print_warning("checksum error", sblock_to_check);
743 btrfs_dev_stat_inc_and_print(sdev->dev,
744 BTRFS_DEV_STAT_CORRUPTION_ERRS);
734 } else if (sblock_bad->header_error) { 745 } else if (sblock_bad->header_error) {
735 spin_lock(&sdev->stat_lock); 746 spin_lock(&sdev->stat_lock);
736 sdev->stat.verify_errors++; 747 sdev->stat.verify_errors++;
@@ -738,6 +749,12 @@ static int scrub_handle_errored_block(struct scrub_block *sblock_to_check)
738 if (__ratelimit(&_rs)) 749 if (__ratelimit(&_rs))
739 scrub_print_warning("checksum/header error", 750 scrub_print_warning("checksum/header error",
740 sblock_to_check); 751 sblock_to_check);
752 if (sblock_bad->generation_error)
753 btrfs_dev_stat_inc_and_print(sdev->dev,
754 BTRFS_DEV_STAT_GENERATION_ERRS);
755 else
756 btrfs_dev_stat_inc_and_print(sdev->dev,
757 BTRFS_DEV_STAT_CORRUPTION_ERRS);
741 } 758 }
742 759
743 if (sdev->readonly) 760 if (sdev->readonly)
@@ -998,8 +1015,8 @@ static int scrub_setup_recheck_block(struct scrub_dev *sdev,
998 page = sblock->pagev + page_index; 1015 page = sblock->pagev + page_index;
999 page->logical = logical; 1016 page->logical = logical;
1000 page->physical = bbio->stripes[mirror_index].physical; 1017 page->physical = bbio->stripes[mirror_index].physical;
1001 /* for missing devices, bdev is NULL */ 1018 /* for missing devices, dev->bdev is NULL */
1002 page->bdev = bbio->stripes[mirror_index].dev->bdev; 1019 page->dev = bbio->stripes[mirror_index].dev;
1003 page->mirror_num = mirror_index + 1; 1020 page->mirror_num = mirror_index + 1;
1004 page->page = alloc_page(GFP_NOFS); 1021 page->page = alloc_page(GFP_NOFS);
1005 if (!page->page) { 1022 if (!page->page) {
@@ -1043,7 +1060,7 @@ static int scrub_recheck_block(struct btrfs_fs_info *fs_info,
1043 struct scrub_page *page = sblock->pagev + page_num; 1060 struct scrub_page *page = sblock->pagev + page_num;
1044 DECLARE_COMPLETION_ONSTACK(complete); 1061 DECLARE_COMPLETION_ONSTACK(complete);
1045 1062
1046 if (page->bdev == NULL) { 1063 if (page->dev->bdev == NULL) {
1047 page->io_error = 1; 1064 page->io_error = 1;
1048 sblock->no_io_error_seen = 0; 1065 sblock->no_io_error_seen = 0;
1049 continue; 1066 continue;
@@ -1053,7 +1070,7 @@ static int scrub_recheck_block(struct btrfs_fs_info *fs_info,
1053 bio = bio_alloc(GFP_NOFS, 1); 1070 bio = bio_alloc(GFP_NOFS, 1);
1054 if (!bio) 1071 if (!bio)
1055 return -EIO; 1072 return -EIO;
1056 bio->bi_bdev = page->bdev; 1073 bio->bi_bdev = page->dev->bdev;
1057 bio->bi_sector = page->physical >> 9; 1074 bio->bi_sector = page->physical >> 9;
1058 bio->bi_end_io = scrub_complete_bio_end_io; 1075 bio->bi_end_io = scrub_complete_bio_end_io;
1059 bio->bi_private = &complete; 1076 bio->bi_private = &complete;
@@ -1102,11 +1119,14 @@ static void scrub_recheck_block_checksum(struct btrfs_fs_info *fs_info,
1102 h = (struct btrfs_header *)mapped_buffer; 1119 h = (struct btrfs_header *)mapped_buffer;
1103 1120
1104 if (sblock->pagev[0].logical != le64_to_cpu(h->bytenr) || 1121 if (sblock->pagev[0].logical != le64_to_cpu(h->bytenr) ||
1105 generation != le64_to_cpu(h->generation) ||
1106 memcmp(h->fsid, fs_info->fsid, BTRFS_UUID_SIZE) || 1122 memcmp(h->fsid, fs_info->fsid, BTRFS_UUID_SIZE) ||
1107 memcmp(h->chunk_tree_uuid, fs_info->chunk_tree_uuid, 1123 memcmp(h->chunk_tree_uuid, fs_info->chunk_tree_uuid,
1108 BTRFS_UUID_SIZE)) 1124 BTRFS_UUID_SIZE)) {
1109 sblock->header_error = 1; 1125 sblock->header_error = 1;
1126 } else if (generation != le64_to_cpu(h->generation)) {
1127 sblock->header_error = 1;
1128 sblock->generation_error = 1;
1129 }
1110 csum = h->csum; 1130 csum = h->csum;
1111 } else { 1131 } else {
1112 if (!have_csum) 1132 if (!have_csum)
@@ -1182,7 +1202,7 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
1182 bio = bio_alloc(GFP_NOFS, 1); 1202 bio = bio_alloc(GFP_NOFS, 1);
1183 if (!bio) 1203 if (!bio)
1184 return -EIO; 1204 return -EIO;
1185 bio->bi_bdev = page_bad->bdev; 1205 bio->bi_bdev = page_bad->dev->bdev;
1186 bio->bi_sector = page_bad->physical >> 9; 1206 bio->bi_sector = page_bad->physical >> 9;
1187 bio->bi_end_io = scrub_complete_bio_end_io; 1207 bio->bi_end_io = scrub_complete_bio_end_io;
1188 bio->bi_private = &complete; 1208 bio->bi_private = &complete;
@@ -1196,6 +1216,12 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
1196 1216
1197 /* this will also unplug the queue */ 1217 /* this will also unplug the queue */
1198 wait_for_completion(&complete); 1218 wait_for_completion(&complete);
1219 if (!bio_flagged(bio, BIO_UPTODATE)) {
1220 btrfs_dev_stat_inc_and_print(page_bad->dev,
1221 BTRFS_DEV_STAT_WRITE_ERRS);
1222 bio_put(bio);
1223 return -EIO;
1224 }
1199 bio_put(bio); 1225 bio_put(bio);
1200 } 1226 }
1201 1227
@@ -1352,7 +1378,8 @@ static int scrub_checksum_super(struct scrub_block *sblock)
1352 u64 mapped_size; 1378 u64 mapped_size;
1353 void *p; 1379 void *p;
1354 u32 crc = ~(u32)0; 1380 u32 crc = ~(u32)0;
1355 int fail = 0; 1381 int fail_gen = 0;
1382 int fail_cor = 0;
1356 u64 len; 1383 u64 len;
1357 int index; 1384 int index;
1358 1385
@@ -1363,13 +1390,13 @@ static int scrub_checksum_super(struct scrub_block *sblock)
1363 memcpy(on_disk_csum, s->csum, sdev->csum_size); 1390 memcpy(on_disk_csum, s->csum, sdev->csum_size);
1364 1391
1365 if (sblock->pagev[0].logical != le64_to_cpu(s->bytenr)) 1392 if (sblock->pagev[0].logical != le64_to_cpu(s->bytenr))
1366 ++fail; 1393 ++fail_cor;
1367 1394
1368 if (sblock->pagev[0].generation != le64_to_cpu(s->generation)) 1395 if (sblock->pagev[0].generation != le64_to_cpu(s->generation))
1369 ++fail; 1396 ++fail_gen;
1370 1397
1371 if (memcmp(s->fsid, fs_info->fsid, BTRFS_UUID_SIZE)) 1398 if (memcmp(s->fsid, fs_info->fsid, BTRFS_UUID_SIZE))
1372 ++fail; 1399 ++fail_cor;
1373 1400
1374 len = BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE; 1401 len = BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE;
1375 mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE; 1402 mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE;
@@ -1394,9 +1421,9 @@ static int scrub_checksum_super(struct scrub_block *sblock)
1394 1421
1395 btrfs_csum_final(crc, calculated_csum); 1422 btrfs_csum_final(crc, calculated_csum);
1396 if (memcmp(calculated_csum, on_disk_csum, sdev->csum_size)) 1423 if (memcmp(calculated_csum, on_disk_csum, sdev->csum_size))
1397 ++fail; 1424 ++fail_cor;
1398 1425
1399 if (fail) { 1426 if (fail_cor + fail_gen) {
1400 /* 1427 /*
1401 * if we find an error in a super block, we just report it. 1428 * if we find an error in a super block, we just report it.
1402 * They will get written with the next transaction commit 1429 * They will get written with the next transaction commit
@@ -1405,9 +1432,15 @@ static int scrub_checksum_super(struct scrub_block *sblock)
1405 spin_lock(&sdev->stat_lock); 1432 spin_lock(&sdev->stat_lock);
1406 ++sdev->stat.super_errors; 1433 ++sdev->stat.super_errors;
1407 spin_unlock(&sdev->stat_lock); 1434 spin_unlock(&sdev->stat_lock);
1435 if (fail_cor)
1436 btrfs_dev_stat_inc_and_print(sdev->dev,
1437 BTRFS_DEV_STAT_CORRUPTION_ERRS);
1438 else
1439 btrfs_dev_stat_inc_and_print(sdev->dev,
1440 BTRFS_DEV_STAT_GENERATION_ERRS);
1408 } 1441 }
1409 1442
1410 return fail; 1443 return fail_cor + fail_gen;
1411} 1444}
1412 1445
1413static void scrub_block_get(struct scrub_block *sblock) 1446static void scrub_block_get(struct scrub_block *sblock)
@@ -1551,7 +1584,7 @@ static int scrub_pages(struct scrub_dev *sdev, u64 logical, u64 len,
1551 return -ENOMEM; 1584 return -ENOMEM;
1552 } 1585 }
1553 spage->sblock = sblock; 1586 spage->sblock = sblock;
1554 spage->bdev = sdev->dev->bdev; 1587 spage->dev = sdev->dev;
1555 spage->flags = flags; 1588 spage->flags = flags;
1556 spage->generation = gen; 1589 spage->generation = gen;
1557 spage->logical = logical; 1590 spage->logical = logical;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index c5f8fca4195f..96eb9fef7bd2 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -188,7 +188,8 @@ void btrfs_printk(struct btrfs_fs_info *fs_info, const char *fmt, ...)
188 va_start(args, fmt); 188 va_start(args, fmt);
189 189
190 if (fmt[0] == '<' && isdigit(fmt[1]) && fmt[2] == '>') { 190 if (fmt[0] == '<' && isdigit(fmt[1]) && fmt[2] == '>') {
191 strncpy(lvl, fmt, 3); 191 memcpy(lvl, fmt, 3);
192 lvl[3] = '\0';
192 fmt += 3; 193 fmt += 3;
193 type = logtypes[fmt[1] - '0']; 194 type = logtypes[fmt[1] - '0'];
194 } else 195 } else
@@ -435,11 +436,8 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
435 case Opt_thread_pool: 436 case Opt_thread_pool:
436 intarg = 0; 437 intarg = 0;
437 match_int(&args[0], &intarg); 438 match_int(&args[0], &intarg);
438 if (intarg) { 439 if (intarg)
439 info->thread_pool_size = intarg; 440 info->thread_pool_size = intarg;
440 printk(KERN_INFO "btrfs: thread pool %d\n",
441 info->thread_pool_size);
442 }
443 break; 441 break;
444 case Opt_max_inline: 442 case Opt_max_inline:
445 num = match_strdup(&args[0]); 443 num = match_strdup(&args[0]);
@@ -769,7 +767,7 @@ static int btrfs_fill_super(struct super_block *sb,
769#ifdef CONFIG_BTRFS_FS_POSIX_ACL 767#ifdef CONFIG_BTRFS_FS_POSIX_ACL
770 sb->s_flags |= MS_POSIXACL; 768 sb->s_flags |= MS_POSIXACL;
771#endif 769#endif
772 770 sb->s_flags |= MS_I_VERSION;
773 err = open_ctree(sb, fs_devices, (char *)data); 771 err = open_ctree(sb, fs_devices, (char *)data);
774 if (err) { 772 if (err) {
775 printk("btrfs: open_ctree failed\n"); 773 printk("btrfs: open_ctree failed\n");
@@ -925,63 +923,48 @@ static inline int is_subvolume_inode(struct inode *inode)
925 */ 923 */
926static char *setup_root_args(char *args) 924static char *setup_root_args(char *args)
927{ 925{
928 unsigned copied = 0; 926 unsigned len = strlen(args) + 2 + 1;
929 unsigned len = strlen(args) + 2; 927 char *src, *dst, *buf;
930 char *pos;
931 char *ret;
932 928
933 /* 929 /*
934 * We need the same args as before, but minus 930 * We need the same args as before, but with this substitution:
935 * 931 * s!subvol=[^,]+!subvolid=0!
936 * subvol=a
937 *
938 * and add
939 *
940 * subvolid=0
941 * 932 *
942 * which is a difference of 2 characters, so we allocate strlen(args) + 933 * Since the replacement string is up to 2 bytes longer than the
943 * 2 characters. 934 * original, allocate strlen(args) + 2 + 1 bytes.
944 */ 935 */
945 ret = kzalloc(len * sizeof(char), GFP_NOFS);
946 if (!ret)
947 return NULL;
948 pos = strstr(args, "subvol=");
949 936
937 src = strstr(args, "subvol=");
950 /* This shouldn't happen, but just in case.. */ 938 /* This shouldn't happen, but just in case.. */
951 if (!pos) { 939 if (!src)
952 kfree(ret); 940 return NULL;
941
942 buf = dst = kmalloc(len, GFP_NOFS);
943 if (!buf)
953 return NULL; 944 return NULL;
954 }
955 945
956 /* 946 /*
957 * The subvol=<> arg is not at the front of the string, copy everybody 947 * If the subvol= arg is not at the start of the string,
958 * up to that into ret. 948 * copy whatever precedes it into buf.
959 */ 949 */
960 if (pos != args) { 950 if (src != args) {
961 *pos = '\0'; 951 *src++ = '\0';
962 strcpy(ret, args); 952 strcpy(buf, args);
963 copied += strlen(args); 953 dst += strlen(args);
964 pos++;
965 } 954 }
966 955
967 strncpy(ret + copied, "subvolid=0", len - copied); 956 strcpy(dst, "subvolid=0");
968 957 dst += strlen("subvolid=0");
969 /* Length of subvolid=0 */
970 copied += 10;
971 958
972 /* 959 /*
973 * If there is no , after the subvol= option then we know there's no 960 * If there is a "," after the original subvol=... string,
974 * other options and we can just return. 961 * copy that suffix into our buffer. Otherwise, we're done.
975 */ 962 */
976 pos = strchr(pos, ','); 963 src = strchr(src, ',');
977 if (!pos) 964 if (src)
978 return ret; 965 strcpy(dst, src);
979 966
980 /* Copy the rest of the arguments into our buffer */ 967 return buf;
981 strncpy(ret + copied, pos, len - copied);
982 copied += strlen(pos);
983
984 return ret;
985} 968}
986 969
987static struct dentry *mount_subvol(const char *subvol_name, int flags, 970static struct dentry *mount_subvol(const char *subvol_name, int flags,
@@ -1118,6 +1101,40 @@ error_fs_info:
1118 return ERR_PTR(error); 1101 return ERR_PTR(error);
1119} 1102}
1120 1103
1104static void btrfs_set_max_workers(struct btrfs_workers *workers, int new_limit)
1105{
1106 spin_lock_irq(&workers->lock);
1107 workers->max_workers = new_limit;
1108 spin_unlock_irq(&workers->lock);
1109}
1110
1111static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info,
1112 int new_pool_size, int old_pool_size)
1113{
1114 if (new_pool_size == old_pool_size)
1115 return;
1116
1117 fs_info->thread_pool_size = new_pool_size;
1118
1119 printk(KERN_INFO "btrfs: resize thread pool %d -> %d\n",
1120 old_pool_size, new_pool_size);
1121
1122 btrfs_set_max_workers(&fs_info->generic_worker, new_pool_size);
1123 btrfs_set_max_workers(&fs_info->workers, new_pool_size);
1124 btrfs_set_max_workers(&fs_info->delalloc_workers, new_pool_size);
1125 btrfs_set_max_workers(&fs_info->submit_workers, new_pool_size);
1126 btrfs_set_max_workers(&fs_info->caching_workers, new_pool_size);
1127 btrfs_set_max_workers(&fs_info->fixup_workers, new_pool_size);
1128 btrfs_set_max_workers(&fs_info->endio_workers, new_pool_size);
1129 btrfs_set_max_workers(&fs_info->endio_meta_workers, new_pool_size);
1130 btrfs_set_max_workers(&fs_info->endio_meta_write_workers, new_pool_size);
1131 btrfs_set_max_workers(&fs_info->endio_write_workers, new_pool_size);
1132 btrfs_set_max_workers(&fs_info->endio_freespace_worker, new_pool_size);
1133 btrfs_set_max_workers(&fs_info->delayed_workers, new_pool_size);
1134 btrfs_set_max_workers(&fs_info->readahead_workers, new_pool_size);
1135 btrfs_set_max_workers(&fs_info->scrub_workers, new_pool_size);
1136}
1137
1121static int btrfs_remount(struct super_block *sb, int *flags, char *data) 1138static int btrfs_remount(struct super_block *sb, int *flags, char *data)
1122{ 1139{
1123 struct btrfs_fs_info *fs_info = btrfs_sb(sb); 1140 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
@@ -1137,6 +1154,9 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
1137 goto restore; 1154 goto restore;
1138 } 1155 }
1139 1156
1157 btrfs_resize_thread_pool(fs_info,
1158 fs_info->thread_pool_size, old_thread_pool_size);
1159
1140 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) 1160 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1141 return 0; 1161 return 0;
1142 1162
@@ -1180,7 +1200,8 @@ restore:
1180 fs_info->compress_type = old_compress_type; 1200 fs_info->compress_type = old_compress_type;
1181 fs_info->max_inline = old_max_inline; 1201 fs_info->max_inline = old_max_inline;
1182 fs_info->alloc_start = old_alloc_start; 1202 fs_info->alloc_start = old_alloc_start;
1183 fs_info->thread_pool_size = old_thread_pool_size; 1203 btrfs_resize_thread_pool(fs_info,
1204 old_thread_pool_size, fs_info->thread_pool_size);
1184 fs_info->metadata_ratio = old_metadata_ratio; 1205 fs_info->metadata_ratio = old_metadata_ratio;
1185 return ret; 1206 return ret;
1186} 1207}
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 36422254ef67..1791c6e3d834 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -28,6 +28,7 @@
28#include "locking.h" 28#include "locking.h"
29#include "tree-log.h" 29#include "tree-log.h"
30#include "inode-map.h" 30#include "inode-map.h"
31#include "volumes.h"
31 32
32#define BTRFS_ROOT_TRANS_TAG 0 33#define BTRFS_ROOT_TRANS_TAG 0
33 34
@@ -55,48 +56,49 @@ static noinline void switch_commit_root(struct btrfs_root *root)
55static noinline int join_transaction(struct btrfs_root *root, int nofail) 56static noinline int join_transaction(struct btrfs_root *root, int nofail)
56{ 57{
57 struct btrfs_transaction *cur_trans; 58 struct btrfs_transaction *cur_trans;
59 struct btrfs_fs_info *fs_info = root->fs_info;
58 60
59 spin_lock(&root->fs_info->trans_lock); 61 spin_lock(&fs_info->trans_lock);
60loop: 62loop:
61 /* The file system has been taken offline. No new transactions. */ 63 /* The file system has been taken offline. No new transactions. */
62 if (root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) { 64 if (fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) {
63 spin_unlock(&root->fs_info->trans_lock); 65 spin_unlock(&fs_info->trans_lock);
64 return -EROFS; 66 return -EROFS;
65 } 67 }
66 68
67 if (root->fs_info->trans_no_join) { 69 if (fs_info->trans_no_join) {
68 if (!nofail) { 70 if (!nofail) {
69 spin_unlock(&root->fs_info->trans_lock); 71 spin_unlock(&fs_info->trans_lock);
70 return -EBUSY; 72 return -EBUSY;
71 } 73 }
72 } 74 }
73 75
74 cur_trans = root->fs_info->running_transaction; 76 cur_trans = fs_info->running_transaction;
75 if (cur_trans) { 77 if (cur_trans) {
76 if (cur_trans->aborted) { 78 if (cur_trans->aborted) {
77 spin_unlock(&root->fs_info->trans_lock); 79 spin_unlock(&fs_info->trans_lock);
78 return cur_trans->aborted; 80 return cur_trans->aborted;
79 } 81 }
80 atomic_inc(&cur_trans->use_count); 82 atomic_inc(&cur_trans->use_count);
81 atomic_inc(&cur_trans->num_writers); 83 atomic_inc(&cur_trans->num_writers);
82 cur_trans->num_joined++; 84 cur_trans->num_joined++;
83 spin_unlock(&root->fs_info->trans_lock); 85 spin_unlock(&fs_info->trans_lock);
84 return 0; 86 return 0;
85 } 87 }
86 spin_unlock(&root->fs_info->trans_lock); 88 spin_unlock(&fs_info->trans_lock);
87 89
88 cur_trans = kmem_cache_alloc(btrfs_transaction_cachep, GFP_NOFS); 90 cur_trans = kmem_cache_alloc(btrfs_transaction_cachep, GFP_NOFS);
89 if (!cur_trans) 91 if (!cur_trans)
90 return -ENOMEM; 92 return -ENOMEM;
91 93
92 spin_lock(&root->fs_info->trans_lock); 94 spin_lock(&fs_info->trans_lock);
93 if (root->fs_info->running_transaction) { 95 if (fs_info->running_transaction) {
94 /* 96 /*
95 * someone started a transaction after we unlocked. Make sure 97 * someone started a transaction after we unlocked. Make sure
96 * to redo the trans_no_join checks above 98 * to redo the trans_no_join checks above
97 */ 99 */
98 kmem_cache_free(btrfs_transaction_cachep, cur_trans); 100 kmem_cache_free(btrfs_transaction_cachep, cur_trans);
99 cur_trans = root->fs_info->running_transaction; 101 cur_trans = fs_info->running_transaction;
100 goto loop; 102 goto loop;
101 } 103 }
102 104
@@ -121,20 +123,38 @@ loop:
121 cur_trans->delayed_refs.flushing = 0; 123 cur_trans->delayed_refs.flushing = 0;
122 cur_trans->delayed_refs.run_delayed_start = 0; 124 cur_trans->delayed_refs.run_delayed_start = 0;
123 cur_trans->delayed_refs.seq = 1; 125 cur_trans->delayed_refs.seq = 1;
126
127 /*
128 * although the tree mod log is per file system and not per transaction,
129 * the log must never go across transaction boundaries.
130 */
131 smp_mb();
132 if (!list_empty(&fs_info->tree_mod_seq_list)) {
133 printk(KERN_ERR "btrfs: tree_mod_seq_list not empty when "
134 "creating a fresh transaction\n");
135 WARN_ON(1);
136 }
137 if (!RB_EMPTY_ROOT(&fs_info->tree_mod_log)) {
138 printk(KERN_ERR "btrfs: tree_mod_log rb tree not empty when "
139 "creating a fresh transaction\n");
140 WARN_ON(1);
141 }
142 atomic_set(&fs_info->tree_mod_seq, 0);
143
124 init_waitqueue_head(&cur_trans->delayed_refs.seq_wait); 144 init_waitqueue_head(&cur_trans->delayed_refs.seq_wait);
125 spin_lock_init(&cur_trans->commit_lock); 145 spin_lock_init(&cur_trans->commit_lock);
126 spin_lock_init(&cur_trans->delayed_refs.lock); 146 spin_lock_init(&cur_trans->delayed_refs.lock);
127 INIT_LIST_HEAD(&cur_trans->delayed_refs.seq_head); 147 INIT_LIST_HEAD(&cur_trans->delayed_refs.seq_head);
128 148
129 INIT_LIST_HEAD(&cur_trans->pending_snapshots); 149 INIT_LIST_HEAD(&cur_trans->pending_snapshots);
130 list_add_tail(&cur_trans->list, &root->fs_info->trans_list); 150 list_add_tail(&cur_trans->list, &fs_info->trans_list);
131 extent_io_tree_init(&cur_trans->dirty_pages, 151 extent_io_tree_init(&cur_trans->dirty_pages,
132 root->fs_info->btree_inode->i_mapping); 152 fs_info->btree_inode->i_mapping);
133 root->fs_info->generation++; 153 fs_info->generation++;
134 cur_trans->transid = root->fs_info->generation; 154 cur_trans->transid = fs_info->generation;
135 root->fs_info->running_transaction = cur_trans; 155 fs_info->running_transaction = cur_trans;
136 cur_trans->aborted = 0; 156 cur_trans->aborted = 0;
137 spin_unlock(&root->fs_info->trans_lock); 157 spin_unlock(&fs_info->trans_lock);
138 158
139 return 0; 159 return 0;
140} 160}
@@ -758,6 +778,9 @@ static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans,
758 if (ret) 778 if (ret)
759 return ret; 779 return ret;
760 780
781 ret = btrfs_run_dev_stats(trans, root->fs_info);
782 BUG_ON(ret);
783
761 while (!list_empty(&fs_info->dirty_cowonly_roots)) { 784 while (!list_empty(&fs_info->dirty_cowonly_roots)) {
762 next = fs_info->dirty_cowonly_roots.next; 785 next = fs_info->dirty_cowonly_roots.next;
763 list_del_init(next); 786 list_del_init(next);
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index eb1ae908582c..2017d0ff511c 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -1628,7 +1628,9 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
1628 int i; 1628 int i;
1629 int ret; 1629 int ret;
1630 1630
1631 btrfs_read_buffer(eb, gen); 1631 ret = btrfs_read_buffer(eb, gen);
1632 if (ret)
1633 return ret;
1632 1634
1633 level = btrfs_header_level(eb); 1635 level = btrfs_header_level(eb);
1634 1636
@@ -1749,7 +1751,11 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
1749 1751
1750 path->slots[*level]++; 1752 path->slots[*level]++;
1751 if (wc->free) { 1753 if (wc->free) {
1752 btrfs_read_buffer(next, ptr_gen); 1754 ret = btrfs_read_buffer(next, ptr_gen);
1755 if (ret) {
1756 free_extent_buffer(next);
1757 return ret;
1758 }
1753 1759
1754 btrfs_tree_lock(next); 1760 btrfs_tree_lock(next);
1755 btrfs_set_lock_blocking(next); 1761 btrfs_set_lock_blocking(next);
@@ -1766,7 +1772,11 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,
1766 free_extent_buffer(next); 1772 free_extent_buffer(next);
1767 continue; 1773 continue;
1768 } 1774 }
1769 btrfs_read_buffer(next, ptr_gen); 1775 ret = btrfs_read_buffer(next, ptr_gen);
1776 if (ret) {
1777 free_extent_buffer(next);
1778 return ret;
1779 }
1770 1780
1771 WARN_ON(*level <= 0); 1781 WARN_ON(*level <= 0);
1772 if (path->nodes[*level-1]) 1782 if (path->nodes[*level-1])
@@ -2657,6 +2667,8 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans,
2657 btrfs_release_path(path); 2667 btrfs_release_path(path);
2658 } 2668 }
2659 btrfs_release_path(path); 2669 btrfs_release_path(path);
2670 if (ret > 0)
2671 ret = 0;
2660 return ret; 2672 return ret;
2661} 2673}
2662 2674
@@ -3028,21 +3040,6 @@ out:
3028 return ret; 3040 return ret;
3029} 3041}
3030 3042
3031static int inode_in_log(struct btrfs_trans_handle *trans,
3032 struct inode *inode)
3033{
3034 struct btrfs_root *root = BTRFS_I(inode)->root;
3035 int ret = 0;
3036
3037 mutex_lock(&root->log_mutex);
3038 if (BTRFS_I(inode)->logged_trans == trans->transid &&
3039 BTRFS_I(inode)->last_sub_trans <= root->last_log_commit)
3040 ret = 1;
3041 mutex_unlock(&root->log_mutex);
3042 return ret;
3043}
3044
3045
3046/* 3043/*
3047 * helper function around btrfs_log_inode to make sure newly created 3044 * helper function around btrfs_log_inode to make sure newly created
3048 * parent directories also end up in the log. A minimal inode and backref 3045 * parent directories also end up in the log. A minimal inode and backref
@@ -3083,7 +3080,7 @@ int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
3083 if (ret) 3080 if (ret)
3084 goto end_no_trans; 3081 goto end_no_trans;
3085 3082
3086 if (inode_in_log(trans, inode)) { 3083 if (btrfs_inode_in_log(inode, trans->transid)) {
3087 ret = BTRFS_NO_LOG_SYNC; 3084 ret = BTRFS_NO_LOG_SYNC;
3088 goto end_no_trans; 3085 goto end_no_trans;
3089 } 3086 }
diff --git a/fs/btrfs/ulist.c b/fs/btrfs/ulist.c
index 12f5147bd2b1..ab942f46b3dd 100644
--- a/fs/btrfs/ulist.c
+++ b/fs/btrfs/ulist.c
@@ -23,9 +23,9 @@
23 * 23 *
24 * ulist = ulist_alloc(); 24 * ulist = ulist_alloc();
25 * ulist_add(ulist, root); 25 * ulist_add(ulist, root);
26 * elem = NULL; 26 * ULIST_ITER_INIT(&uiter);
27 * 27 *
28 * while ((elem = ulist_next(ulist, elem)) { 28 * while ((elem = ulist_next(ulist, &uiter)) {
29 * for (all child nodes n in elem) 29 * for (all child nodes n in elem)
30 * ulist_add(ulist, n); 30 * ulist_add(ulist, n);
31 * do something useful with the node; 31 * do something useful with the node;
@@ -95,7 +95,7 @@ EXPORT_SYMBOL(ulist_reinit);
95 * 95 *
96 * The allocated ulist will be returned in an initialized state. 96 * The allocated ulist will be returned in an initialized state.
97 */ 97 */
98struct ulist *ulist_alloc(unsigned long gfp_mask) 98struct ulist *ulist_alloc(gfp_t gfp_mask)
99{ 99{
100 struct ulist *ulist = kmalloc(sizeof(*ulist), gfp_mask); 100 struct ulist *ulist = kmalloc(sizeof(*ulist), gfp_mask);
101 101
@@ -144,13 +144,22 @@ EXPORT_SYMBOL(ulist_free);
144 * unaltered. 144 * unaltered.
145 */ 145 */
146int ulist_add(struct ulist *ulist, u64 val, unsigned long aux, 146int ulist_add(struct ulist *ulist, u64 val, unsigned long aux,
147 unsigned long gfp_mask) 147 gfp_t gfp_mask)
148{
149 return ulist_add_merge(ulist, val, aux, NULL, gfp_mask);
150}
151
152int ulist_add_merge(struct ulist *ulist, u64 val, unsigned long aux,
153 unsigned long *old_aux, gfp_t gfp_mask)
148{ 154{
149 int i; 155 int i;
150 156
151 for (i = 0; i < ulist->nnodes; ++i) { 157 for (i = 0; i < ulist->nnodes; ++i) {
152 if (ulist->nodes[i].val == val) 158 if (ulist->nodes[i].val == val) {
159 if (old_aux)
160 *old_aux = ulist->nodes[i].aux;
153 return 0; 161 return 0;
162 }
154 } 163 }
155 164
156 if (ulist->nnodes >= ulist->nodes_alloced) { 165 if (ulist->nnodes >= ulist->nodes_alloced) {
@@ -188,33 +197,26 @@ EXPORT_SYMBOL(ulist_add);
188/** 197/**
189 * ulist_next - iterate ulist 198 * ulist_next - iterate ulist
190 * @ulist: ulist to iterate 199 * @ulist: ulist to iterate
191 * @prev: previously returned element or %NULL to start iteration 200 * @uiter: iterator variable, initialized with ULIST_ITER_INIT(&iterator)
192 * 201 *
193 * Note: locking must be provided by the caller. In case of rwlocks only read 202 * Note: locking must be provided by the caller. In case of rwlocks only read
194 * locking is needed 203 * locking is needed
195 * 204 *
196 * This function is used to iterate an ulist. The iteration is started with 205 * This function is used to iterate an ulist.
197 * @prev = %NULL. It returns the next element from the ulist or %NULL when the 206 * It returns the next element from the ulist or %NULL when the
198 * end is reached. No guarantee is made with respect to the order in which 207 * end is reached. No guarantee is made with respect to the order in which
199 * the elements are returned. They might neither be returned in order of 208 * the elements are returned. They might neither be returned in order of
200 * addition nor in ascending order. 209 * addition nor in ascending order.
201 * It is allowed to call ulist_add during an enumeration. Newly added items 210 * It is allowed to call ulist_add during an enumeration. Newly added items
202 * are guaranteed to show up in the running enumeration. 211 * are guaranteed to show up in the running enumeration.
203 */ 212 */
204struct ulist_node *ulist_next(struct ulist *ulist, struct ulist_node *prev) 213struct ulist_node *ulist_next(struct ulist *ulist, struct ulist_iterator *uiter)
205{ 214{
206 int next;
207
208 if (ulist->nnodes == 0) 215 if (ulist->nnodes == 0)
209 return NULL; 216 return NULL;
210 217 if (uiter->i < 0 || uiter->i >= ulist->nnodes)
211 if (!prev)
212 return &ulist->nodes[0];
213
214 next = (prev - ulist->nodes) + 1;
215 if (next < 0 || next >= ulist->nnodes)
216 return NULL; 218 return NULL;
217 219
218 return &ulist->nodes[next]; 220 return &ulist->nodes[uiter->i++];
219} 221}
220EXPORT_SYMBOL(ulist_next); 222EXPORT_SYMBOL(ulist_next);
diff --git a/fs/btrfs/ulist.h b/fs/btrfs/ulist.h
index 2e25dec58ec0..21bdc8ec8130 100644
--- a/fs/btrfs/ulist.h
+++ b/fs/btrfs/ulist.h
@@ -24,6 +24,10 @@
24 */ 24 */
25#define ULIST_SIZE 16 25#define ULIST_SIZE 16
26 26
27struct ulist_iterator {
28 int i;
29};
30
27/* 31/*
28 * element of the list 32 * element of the list
29 */ 33 */
@@ -59,10 +63,15 @@ struct ulist {
59void ulist_init(struct ulist *ulist); 63void ulist_init(struct ulist *ulist);
60void ulist_fini(struct ulist *ulist); 64void ulist_fini(struct ulist *ulist);
61void ulist_reinit(struct ulist *ulist); 65void ulist_reinit(struct ulist *ulist);
62struct ulist *ulist_alloc(unsigned long gfp_mask); 66struct ulist *ulist_alloc(gfp_t gfp_mask);
63void ulist_free(struct ulist *ulist); 67void ulist_free(struct ulist *ulist);
64int ulist_add(struct ulist *ulist, u64 val, unsigned long aux, 68int ulist_add(struct ulist *ulist, u64 val, unsigned long aux,
65 unsigned long gfp_mask); 69 gfp_t gfp_mask);
66struct ulist_node *ulist_next(struct ulist *ulist, struct ulist_node *prev); 70int ulist_add_merge(struct ulist *ulist, u64 val, unsigned long aux,
71 unsigned long *old_aux, gfp_t gfp_mask);
72struct ulist_node *ulist_next(struct ulist *ulist,
73 struct ulist_iterator *uiter);
74
75#define ULIST_ITER_INIT(uiter) ((uiter)->i = 0)
67 76
68#endif 77#endif
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 1411b99555a4..7782020996fe 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -23,6 +23,7 @@
23#include <linux/random.h> 23#include <linux/random.h>
24#include <linux/iocontext.h> 24#include <linux/iocontext.h>
25#include <linux/capability.h> 25#include <linux/capability.h>
26#include <linux/ratelimit.h>
26#include <linux/kthread.h> 27#include <linux/kthread.h>
27#include <asm/div64.h> 28#include <asm/div64.h>
28#include "compat.h" 29#include "compat.h"
@@ -39,6 +40,8 @@ static int init_first_rw_device(struct btrfs_trans_handle *trans,
39 struct btrfs_root *root, 40 struct btrfs_root *root,
40 struct btrfs_device *device); 41 struct btrfs_device *device);
41static int btrfs_relocate_sys_chunks(struct btrfs_root *root); 42static int btrfs_relocate_sys_chunks(struct btrfs_root *root);
43static void __btrfs_reset_dev_stats(struct btrfs_device *dev);
44static void btrfs_dev_stat_print_on_load(struct btrfs_device *device);
42 45
43static DEFINE_MUTEX(uuid_mutex); 46static DEFINE_MUTEX(uuid_mutex);
44static LIST_HEAD(fs_uuids); 47static LIST_HEAD(fs_uuids);
@@ -361,6 +364,7 @@ static noinline int device_list_add(const char *path,
361 return -ENOMEM; 364 return -ENOMEM;
362 } 365 }
363 device->devid = devid; 366 device->devid = devid;
367 device->dev_stats_valid = 0;
364 device->work.func = pending_bios_fn; 368 device->work.func = pending_bios_fn;
365 memcpy(device->uuid, disk_super->dev_item.uuid, 369 memcpy(device->uuid, disk_super->dev_item.uuid,
366 BTRFS_UUID_SIZE); 370 BTRFS_UUID_SIZE);
@@ -1633,7 +1637,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
1633 int ret = 0; 1637 int ret = 0;
1634 1638
1635 if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding) 1639 if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding)
1636 return -EINVAL; 1640 return -EROFS;
1637 1641
1638 bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL, 1642 bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
1639 root->fs_info->bdev_holder); 1643 root->fs_info->bdev_holder);
@@ -4001,13 +4005,58 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
4001 return 0; 4005 return 0;
4002} 4006}
4003 4007
4008static void *merge_stripe_index_into_bio_private(void *bi_private,
4009 unsigned int stripe_index)
4010{
4011 /*
4012 * with single, dup, RAID0, RAID1 and RAID10, stripe_index is
4013 * at most 1.
4014 * The alternative solution (instead of stealing bits from the
4015 * pointer) would be to allocate an intermediate structure
4016 * that contains the old private pointer plus the stripe_index.
4017 */
4018 BUG_ON((((uintptr_t)bi_private) & 3) != 0);
4019 BUG_ON(stripe_index > 3);
4020 return (void *)(((uintptr_t)bi_private) | stripe_index);
4021}
4022
4023static struct btrfs_bio *extract_bbio_from_bio_private(void *bi_private)
4024{
4025 return (struct btrfs_bio *)(((uintptr_t)bi_private) & ~((uintptr_t)3));
4026}
4027
4028static unsigned int extract_stripe_index_from_bio_private(void *bi_private)
4029{
4030 return (unsigned int)((uintptr_t)bi_private) & 3;
4031}
4032
4004static void btrfs_end_bio(struct bio *bio, int err) 4033static void btrfs_end_bio(struct bio *bio, int err)
4005{ 4034{
4006 struct btrfs_bio *bbio = bio->bi_private; 4035 struct btrfs_bio *bbio = extract_bbio_from_bio_private(bio->bi_private);
4007 int is_orig_bio = 0; 4036 int is_orig_bio = 0;
4008 4037
4009 if (err) 4038 if (err) {
4010 atomic_inc(&bbio->error); 4039 atomic_inc(&bbio->error);
4040 if (err == -EIO || err == -EREMOTEIO) {
4041 unsigned int stripe_index =
4042 extract_stripe_index_from_bio_private(
4043 bio->bi_private);
4044 struct btrfs_device *dev;
4045
4046 BUG_ON(stripe_index >= bbio->num_stripes);
4047 dev = bbio->stripes[stripe_index].dev;
4048 if (bio->bi_rw & WRITE)
4049 btrfs_dev_stat_inc(dev,
4050 BTRFS_DEV_STAT_WRITE_ERRS);
4051 else
4052 btrfs_dev_stat_inc(dev,
4053 BTRFS_DEV_STAT_READ_ERRS);
4054 if ((bio->bi_rw & WRITE_FLUSH) == WRITE_FLUSH)
4055 btrfs_dev_stat_inc(dev,
4056 BTRFS_DEV_STAT_FLUSH_ERRS);
4057 btrfs_dev_stat_print_on_error(dev);
4058 }
4059 }
4011 4060
4012 if (bio == bbio->orig_bio) 4061 if (bio == bbio->orig_bio)
4013 is_orig_bio = 1; 4062 is_orig_bio = 1;
@@ -4149,6 +4198,8 @@ int btrfs_map_bio(struct btrfs_root *root, int rw, struct bio *bio,
4149 bio = first_bio; 4198 bio = first_bio;
4150 } 4199 }
4151 bio->bi_private = bbio; 4200 bio->bi_private = bbio;
4201 bio->bi_private = merge_stripe_index_into_bio_private(
4202 bio->bi_private, (unsigned int)dev_nr);
4152 bio->bi_end_io = btrfs_end_bio; 4203 bio->bi_end_io = btrfs_end_bio;
4153 bio->bi_sector = bbio->stripes[dev_nr].physical >> 9; 4204 bio->bi_sector = bbio->stripes[dev_nr].physical >> 9;
4154 dev = bbio->stripes[dev_nr].dev; 4205 dev = bbio->stripes[dev_nr].dev;
@@ -4509,6 +4560,28 @@ int btrfs_read_sys_array(struct btrfs_root *root)
4509 return ret; 4560 return ret;
4510} 4561}
4511 4562
4563struct btrfs_device *btrfs_find_device_for_logical(struct btrfs_root *root,
4564 u64 logical, int mirror_num)
4565{
4566 struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree;
4567 int ret;
4568 u64 map_length = 0;
4569 struct btrfs_bio *bbio = NULL;
4570 struct btrfs_device *device;
4571
4572 BUG_ON(mirror_num == 0);
4573 ret = btrfs_map_block(map_tree, WRITE, logical, &map_length, &bbio,
4574 mirror_num);
4575 if (ret) {
4576 BUG_ON(bbio != NULL);
4577 return NULL;
4578 }
4579 BUG_ON(mirror_num != bbio->mirror_num);
4580 device = bbio->stripes[mirror_num - 1].dev;
4581 kfree(bbio);
4582 return device;
4583}
4584
4512int btrfs_read_chunk_tree(struct btrfs_root *root) 4585int btrfs_read_chunk_tree(struct btrfs_root *root)
4513{ 4586{
4514 struct btrfs_path *path; 4587 struct btrfs_path *path;
@@ -4583,3 +4656,230 @@ error:
4583 btrfs_free_path(path); 4656 btrfs_free_path(path);
4584 return ret; 4657 return ret;
4585} 4658}
4659
4660static void __btrfs_reset_dev_stats(struct btrfs_device *dev)
4661{
4662 int i;
4663
4664 for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++)
4665 btrfs_dev_stat_reset(dev, i);
4666}
4667
4668int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info)
4669{
4670 struct btrfs_key key;
4671 struct btrfs_key found_key;
4672 struct btrfs_root *dev_root = fs_info->dev_root;
4673 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
4674 struct extent_buffer *eb;
4675 int slot;
4676 int ret = 0;
4677 struct btrfs_device *device;
4678 struct btrfs_path *path = NULL;
4679 int i;
4680
4681 path = btrfs_alloc_path();
4682 if (!path) {
4683 ret = -ENOMEM;
4684 goto out;
4685 }
4686
4687 mutex_lock(&fs_devices->device_list_mutex);
4688 list_for_each_entry(device, &fs_devices->devices, dev_list) {
4689 int item_size;
4690 struct btrfs_dev_stats_item *ptr;
4691
4692 key.objectid = 0;
4693 key.type = BTRFS_DEV_STATS_KEY;
4694 key.offset = device->devid;
4695 ret = btrfs_search_slot(NULL, dev_root, &key, path, 0, 0);
4696 if (ret) {
4697 printk(KERN_WARNING "btrfs: no dev_stats entry found for device %s (devid %llu) (OK on first mount after mkfs)\n",
4698 device->name, (unsigned long long)device->devid);
4699 __btrfs_reset_dev_stats(device);
4700 device->dev_stats_valid = 1;
4701 btrfs_release_path(path);
4702 continue;
4703 }
4704 slot = path->slots[0];
4705 eb = path->nodes[0];
4706 btrfs_item_key_to_cpu(eb, &found_key, slot);
4707 item_size = btrfs_item_size_nr(eb, slot);
4708
4709 ptr = btrfs_item_ptr(eb, slot,
4710 struct btrfs_dev_stats_item);
4711
4712 for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++) {
4713 if (item_size >= (1 + i) * sizeof(__le64))
4714 btrfs_dev_stat_set(device, i,
4715 btrfs_dev_stats_value(eb, ptr, i));
4716 else
4717 btrfs_dev_stat_reset(device, i);
4718 }
4719
4720 device->dev_stats_valid = 1;
4721 btrfs_dev_stat_print_on_load(device);
4722 btrfs_release_path(path);
4723 }
4724 mutex_unlock(&fs_devices->device_list_mutex);
4725
4726out:
4727 btrfs_free_path(path);
4728 return ret < 0 ? ret : 0;
4729}
4730
4731static int update_dev_stat_item(struct btrfs_trans_handle *trans,
4732 struct btrfs_root *dev_root,
4733 struct btrfs_device *device)
4734{
4735 struct btrfs_path *path;
4736 struct btrfs_key key;
4737 struct extent_buffer *eb;
4738 struct btrfs_dev_stats_item *ptr;
4739 int ret;
4740 int i;
4741
4742 key.objectid = 0;
4743 key.type = BTRFS_DEV_STATS_KEY;
4744 key.offset = device->devid;
4745
4746 path = btrfs_alloc_path();
4747 BUG_ON(!path);
4748 ret = btrfs_search_slot(trans, dev_root, &key, path, -1, 1);
4749 if (ret < 0) {
4750 printk(KERN_WARNING "btrfs: error %d while searching for dev_stats item for device %s!\n",
4751 ret, device->name);
4752 goto out;
4753 }
4754
4755 if (ret == 0 &&
4756 btrfs_item_size_nr(path->nodes[0], path->slots[0]) < sizeof(*ptr)) {
4757 /* need to delete old one and insert a new one */
4758 ret = btrfs_del_item(trans, dev_root, path);
4759 if (ret != 0) {
4760 printk(KERN_WARNING "btrfs: delete too small dev_stats item for device %s failed %d!\n",
4761 device->name, ret);
4762 goto out;
4763 }
4764 ret = 1;
4765 }
4766
4767 if (ret == 1) {
4768 /* need to insert a new item */
4769 btrfs_release_path(path);
4770 ret = btrfs_insert_empty_item(trans, dev_root, path,
4771 &key, sizeof(*ptr));
4772 if (ret < 0) {
4773 printk(KERN_WARNING "btrfs: insert dev_stats item for device %s failed %d!\n",
4774 device->name, ret);
4775 goto out;
4776 }
4777 }
4778
4779 eb = path->nodes[0];
4780 ptr = btrfs_item_ptr(eb, path->slots[0], struct btrfs_dev_stats_item);
4781 for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++)
4782 btrfs_set_dev_stats_value(eb, ptr, i,
4783 btrfs_dev_stat_read(device, i));
4784 btrfs_mark_buffer_dirty(eb);
4785
4786out:
4787 btrfs_free_path(path);
4788 return ret;
4789}
4790
4791/*
4792 * called from commit_transaction. Writes all changed device stats to disk.
4793 */
4794int btrfs_run_dev_stats(struct btrfs_trans_handle *trans,
4795 struct btrfs_fs_info *fs_info)
4796{
4797 struct btrfs_root *dev_root = fs_info->dev_root;
4798 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
4799 struct btrfs_device *device;
4800 int ret = 0;
4801
4802 mutex_lock(&fs_devices->device_list_mutex);
4803 list_for_each_entry(device, &fs_devices->devices, dev_list) {
4804 if (!device->dev_stats_valid || !device->dev_stats_dirty)
4805 continue;
4806
4807 ret = update_dev_stat_item(trans, dev_root, device);
4808 if (!ret)
4809 device->dev_stats_dirty = 0;
4810 }
4811 mutex_unlock(&fs_devices->device_list_mutex);
4812
4813 return ret;
4814}
4815
4816void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index)
4817{
4818 btrfs_dev_stat_inc(dev, index);
4819 btrfs_dev_stat_print_on_error(dev);
4820}
4821
4822void btrfs_dev_stat_print_on_error(struct btrfs_device *dev)
4823{
4824 if (!dev->dev_stats_valid)
4825 return;
4826 printk_ratelimited(KERN_ERR
4827 "btrfs: bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u\n",
4828 dev->name,
4829 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS),
4830 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_READ_ERRS),
4831 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_FLUSH_ERRS),
4832 btrfs_dev_stat_read(dev,
4833 BTRFS_DEV_STAT_CORRUPTION_ERRS),
4834 btrfs_dev_stat_read(dev,
4835 BTRFS_DEV_STAT_GENERATION_ERRS));
4836}
4837
4838static void btrfs_dev_stat_print_on_load(struct btrfs_device *dev)
4839{
4840 printk(KERN_INFO "btrfs: bdev %s errs: wr %u, rd %u, flush %u, corrupt %u, gen %u\n",
4841 dev->name,
4842 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_WRITE_ERRS),
4843 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_READ_ERRS),
4844 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_FLUSH_ERRS),
4845 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_CORRUPTION_ERRS),
4846 btrfs_dev_stat_read(dev, BTRFS_DEV_STAT_GENERATION_ERRS));
4847}
4848
4849int btrfs_get_dev_stats(struct btrfs_root *root,
4850 struct btrfs_ioctl_get_dev_stats *stats,
4851 int reset_after_read)
4852{
4853 struct btrfs_device *dev;
4854 struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
4855 int i;
4856
4857 mutex_lock(&fs_devices->device_list_mutex);
4858 dev = btrfs_find_device(root, stats->devid, NULL, NULL);
4859 mutex_unlock(&fs_devices->device_list_mutex);
4860
4861 if (!dev) {
4862 printk(KERN_WARNING
4863 "btrfs: get dev_stats failed, device not found\n");
4864 return -ENODEV;
4865 } else if (!dev->dev_stats_valid) {
4866 printk(KERN_WARNING
4867 "btrfs: get dev_stats failed, not yet valid\n");
4868 return -ENODEV;
4869 } else if (reset_after_read) {
4870 for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++) {
4871 if (stats->nr_items > i)
4872 stats->values[i] =
4873 btrfs_dev_stat_read_and_reset(dev, i);
4874 else
4875 btrfs_dev_stat_reset(dev, i);
4876 }
4877 } else {
4878 for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++)
4879 if (stats->nr_items > i)
4880 stats->values[i] = btrfs_dev_stat_read(dev, i);
4881 }
4882 if (stats->nr_items > BTRFS_DEV_STAT_VALUES_MAX)
4883 stats->nr_items = BTRFS_DEV_STAT_VALUES_MAX;
4884 return 0;
4885}
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index bb6b03f97aaa..3406a88ca83e 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -22,6 +22,7 @@
22#include <linux/bio.h> 22#include <linux/bio.h>
23#include <linux/sort.h> 23#include <linux/sort.h>
24#include "async-thread.h" 24#include "async-thread.h"
25#include "ioctl.h"
25 26
26#define BTRFS_STRIPE_LEN (64 * 1024) 27#define BTRFS_STRIPE_LEN (64 * 1024)
27 28
@@ -106,6 +107,11 @@ struct btrfs_device {
106 struct completion flush_wait; 107 struct completion flush_wait;
107 int nobarriers; 108 int nobarriers;
108 109
110 /* disk I/O failure stats. For detailed description refer to
111 * enum btrfs_dev_stat_values in ioctl.h */
112 int dev_stats_valid;
113 int dev_stats_dirty; /* counters need to be written to disk */
114 atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
109}; 115};
110 116
111struct btrfs_fs_devices { 117struct btrfs_fs_devices {
@@ -281,4 +287,50 @@ int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
281int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset); 287int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);
282int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes, 288int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
283 u64 *start, u64 *max_avail); 289 u64 *start, u64 *max_avail);
290struct btrfs_device *btrfs_find_device_for_logical(struct btrfs_root *root,
291 u64 logical, int mirror_num);
292void btrfs_dev_stat_print_on_error(struct btrfs_device *device);
293void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
294int btrfs_get_dev_stats(struct btrfs_root *root,
295 struct btrfs_ioctl_get_dev_stats *stats,
296 int reset_after_read);
297int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info);
298int btrfs_run_dev_stats(struct btrfs_trans_handle *trans,
299 struct btrfs_fs_info *fs_info);
300
301static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
302 int index)
303{
304 atomic_inc(dev->dev_stat_values + index);
305 dev->dev_stats_dirty = 1;
306}
307
308static inline int btrfs_dev_stat_read(struct btrfs_device *dev,
309 int index)
310{
311 return atomic_read(dev->dev_stat_values + index);
312}
313
314static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev,
315 int index)
316{
317 int ret;
318
319 ret = atomic_xchg(dev->dev_stat_values + index, 0);
320 dev->dev_stats_dirty = 1;
321 return ret;
322}
323
324static inline void btrfs_dev_stat_set(struct btrfs_device *dev,
325 int index, unsigned long val)
326{
327 atomic_set(dev->dev_stat_values + index, val);
328 dev->dev_stats_dirty = 1;
329}
330
331static inline void btrfs_dev_stat_reset(struct btrfs_device *dev,
332 int index)
333{
334 btrfs_dev_stat_set(dev, index, 0);
335}
284#endif 336#endif
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c
index e7a5659087e6..3f4e2d69e83a 100644
--- a/fs/btrfs/xattr.c
+++ b/fs/btrfs/xattr.c
@@ -196,6 +196,7 @@ int __btrfs_setxattr(struct btrfs_trans_handle *trans,
196 if (ret) 196 if (ret)
197 goto out; 197 goto out;
198 198
199 inode_inc_iversion(inode);
199 inode->i_ctime = CURRENT_TIME; 200 inode->i_ctime = CURRENT_TIME;
200 ret = btrfs_update_inode(trans, root, inode); 201 ret = btrfs_update_inode(trans, root, inode);
201 BUG_ON(ret); 202 BUG_ON(ret);
diff --git a/fs/buffer.c b/fs/buffer.c
index ad5938ca357c..838a9cf246bd 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -3152,7 +3152,7 @@ SYSCALL_DEFINE2(bdflush, int, func, long, data)
3152/* 3152/*
3153 * Buffer-head allocation 3153 * Buffer-head allocation
3154 */ 3154 */
3155static struct kmem_cache *bh_cachep; 3155static struct kmem_cache *bh_cachep __read_mostly;
3156 3156
3157/* 3157/*
3158 * Once the number of bh's in the machine exceeds this level, we start 3158 * Once the number of bh's in the machine exceeds this level, we start
diff --git a/fs/ceph/export.c b/fs/ceph/export.c
index fbb2a643ef10..8e1b60e557b6 100644
--- a/fs/ceph/export.c
+++ b/fs/ceph/export.c
@@ -40,38 +40,49 @@ struct ceph_nfs_confh {
40 u32 parent_name_hash; 40 u32 parent_name_hash;
41} __attribute__ ((packed)); 41} __attribute__ ((packed));
42 42
43static int ceph_encode_fh(struct dentry *dentry, u32 *rawfh, int *max_len, 43/*
44 int connectable) 44 * The presence of @parent_inode here tells us whether NFS wants a
45 * connectable file handle. However, we want to make a connectionable
46 * file handle unconditionally so that the MDS gets as much of a hint
47 * as possible. That means we only use @parent_dentry to indicate
48 * whether nfsd wants a connectable fh, and whether we should indicate
49 * failure from a too-small @max_len.
50 */
51static int ceph_encode_fh(struct inode *inode, u32 *rawfh, int *max_len,
52 struct inode *parent_inode)
45{ 53{
46 int type; 54 int type;
47 struct ceph_nfs_fh *fh = (void *)rawfh; 55 struct ceph_nfs_fh *fh = (void *)rawfh;
48 struct ceph_nfs_confh *cfh = (void *)rawfh; 56 struct ceph_nfs_confh *cfh = (void *)rawfh;
49 struct dentry *parent;
50 struct inode *inode = dentry->d_inode;
51 int connected_handle_length = sizeof(*cfh)/4; 57 int connected_handle_length = sizeof(*cfh)/4;
52 int handle_length = sizeof(*fh)/4; 58 int handle_length = sizeof(*fh)/4;
59 struct dentry *dentry = d_find_alias(inode);
60 struct dentry *parent;
53 61
54 /* don't re-export snaps */ 62 /* don't re-export snaps */
55 if (ceph_snap(inode) != CEPH_NOSNAP) 63 if (ceph_snap(inode) != CEPH_NOSNAP)
56 return -EINVAL; 64 return -EINVAL;
57 65
58 spin_lock(&dentry->d_lock); 66 /* if we found an alias, generate a connectable fh */
59 parent = dentry->d_parent; 67 if (*max_len >= connected_handle_length && dentry) {
60 if (*max_len >= connected_handle_length) {
61 dout("encode_fh %p connectable\n", dentry); 68 dout("encode_fh %p connectable\n", dentry);
62 cfh->ino = ceph_ino(dentry->d_inode); 69 spin_lock(&dentry->d_lock);
70 parent = dentry->d_parent;
71 cfh->ino = ceph_ino(inode);
63 cfh->parent_ino = ceph_ino(parent->d_inode); 72 cfh->parent_ino = ceph_ino(parent->d_inode);
64 cfh->parent_name_hash = ceph_dentry_hash(parent->d_inode, 73 cfh->parent_name_hash = ceph_dentry_hash(parent->d_inode,
65 dentry); 74 dentry);
66 *max_len = connected_handle_length; 75 *max_len = connected_handle_length;
67 type = 2; 76 type = 2;
77 spin_unlock(&dentry->d_lock);
68 } else if (*max_len >= handle_length) { 78 } else if (*max_len >= handle_length) {
69 if (connectable) { 79 if (parent_inode) {
80 /* nfsd wants connectable */
70 *max_len = connected_handle_length; 81 *max_len = connected_handle_length;
71 type = 255; 82 type = 255;
72 } else { 83 } else {
73 dout("encode_fh %p\n", dentry); 84 dout("encode_fh %p\n", dentry);
74 fh->ino = ceph_ino(dentry->d_inode); 85 fh->ino = ceph_ino(inode);
75 *max_len = handle_length; 86 *max_len = handle_length;
76 type = 1; 87 type = 1;
77 } 88 }
@@ -79,7 +90,6 @@ static int ceph_encode_fh(struct dentry *dentry, u32 *rawfh, int *max_len,
79 *max_len = handle_length; 90 *max_len = handle_length;
80 type = 255; 91 type = 255;
81 } 92 }
82 spin_unlock(&dentry->d_lock);
83 return type; 93 return type;
84} 94}
85 95
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index f04c0961f993..e5206fc76562 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -331,7 +331,7 @@ static int build_snap_context(struct ceph_snap_realm *realm)
331 331
332 /* alloc new snap context */ 332 /* alloc new snap context */
333 err = -ENOMEM; 333 err = -ENOMEM;
334 if (num > (ULONG_MAX - sizeof(*snapc)) / sizeof(u64)) 334 if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
335 goto fail; 335 goto fail;
336 snapc = kzalloc(sizeof(*snapc) + num*sizeof(u64), GFP_NOFS); 336 snapc = kzalloc(sizeof(*snapc) + num*sizeof(u64), GFP_NOFS);
337 if (!snapc) 337 if (!snapc)
diff --git a/fs/compat.c b/fs/compat.c
index 0781e619a62a..6161255fac45 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -532,7 +532,7 @@ out:
532ssize_t compat_rw_copy_check_uvector(int type, 532ssize_t compat_rw_copy_check_uvector(int type,
533 const struct compat_iovec __user *uvector, unsigned long nr_segs, 533 const struct compat_iovec __user *uvector, unsigned long nr_segs,
534 unsigned long fast_segs, struct iovec *fast_pointer, 534 unsigned long fast_segs, struct iovec *fast_pointer,
535 struct iovec **ret_pointer, int check_access) 535 struct iovec **ret_pointer)
536{ 536{
537 compat_ssize_t tot_len; 537 compat_ssize_t tot_len;
538 struct iovec *iov = *ret_pointer = fast_pointer; 538 struct iovec *iov = *ret_pointer = fast_pointer;
@@ -579,7 +579,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
579 } 579 }
580 if (len < 0) /* size_t not fitting in compat_ssize_t .. */ 580 if (len < 0) /* size_t not fitting in compat_ssize_t .. */
581 goto out; 581 goto out;
582 if (check_access && 582 if (type >= 0 &&
583 !access_ok(vrfy_dir(type), compat_ptr(buf), len)) { 583 !access_ok(vrfy_dir(type), compat_ptr(buf), len)) {
584 ret = -EFAULT; 584 ret = -EFAULT;
585 goto out; 585 goto out;
@@ -871,12 +871,12 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
871{ 871{
872 int error; 872 int error;
873 struct file *file; 873 struct file *file;
874 int fput_needed;
874 struct compat_readdir_callback buf; 875 struct compat_readdir_callback buf;
875 876
876 error = -EBADF; 877 file = fget_light(fd, &fput_needed);
877 file = fget(fd);
878 if (!file) 878 if (!file)
879 goto out; 879 return -EBADF;
880 880
881 buf.result = 0; 881 buf.result = 0;
882 buf.dirent = dirent; 882 buf.dirent = dirent;
@@ -885,8 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
885 if (buf.result) 885 if (buf.result)
886 error = buf.result; 886 error = buf.result;
887 887
888 fput(file); 888 fput_light(file, fput_needed);
889out:
890 return error; 889 return error;
891} 890}
892 891
@@ -953,16 +952,15 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
953 struct file * file; 952 struct file * file;
954 struct compat_linux_dirent __user * lastdirent; 953 struct compat_linux_dirent __user * lastdirent;
955 struct compat_getdents_callback buf; 954 struct compat_getdents_callback buf;
955 int fput_needed;
956 int error; 956 int error;
957 957
958 error = -EFAULT;
959 if (!access_ok(VERIFY_WRITE, dirent, count)) 958 if (!access_ok(VERIFY_WRITE, dirent, count))
960 goto out; 959 return -EFAULT;
961 960
962 error = -EBADF; 961 file = fget_light(fd, &fput_needed);
963 file = fget(fd);
964 if (!file) 962 if (!file)
965 goto out; 963 return -EBADF;
966 964
967 buf.current_dir = dirent; 965 buf.current_dir = dirent;
968 buf.previous = NULL; 966 buf.previous = NULL;
@@ -979,8 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
979 else 977 else
980 error = count - buf.count; 978 error = count - buf.count;
981 } 979 }
982 fput(file); 980 fput_light(file, fput_needed);
983out:
984 return error; 981 return error;
985} 982}
986 983
@@ -1041,16 +1038,15 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
1041 struct file * file; 1038 struct file * file;
1042 struct linux_dirent64 __user * lastdirent; 1039 struct linux_dirent64 __user * lastdirent;
1043 struct compat_getdents_callback64 buf; 1040 struct compat_getdents_callback64 buf;
1041 int fput_needed;
1044 int error; 1042 int error;
1045 1043
1046 error = -EFAULT;
1047 if (!access_ok(VERIFY_WRITE, dirent, count)) 1044 if (!access_ok(VERIFY_WRITE, dirent, count))
1048 goto out; 1045 return -EFAULT;
1049 1046
1050 error = -EBADF; 1047 file = fget_light(fd, &fput_needed);
1051 file = fget(fd);
1052 if (!file) 1048 if (!file)
1053 goto out; 1049 return -EBADF;
1054 1050
1055 buf.current_dir = dirent; 1051 buf.current_dir = dirent;
1056 buf.previous = NULL; 1052 buf.previous = NULL;
@@ -1068,8 +1064,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
1068 else 1064 else
1069 error = count - buf.count; 1065 error = count - buf.count;
1070 } 1066 }
1071 fput(file); 1067 fput_light(file, fput_needed);
1072out:
1073 return error; 1068 return error;
1074} 1069}
1075#endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */ 1070#endif /* ! __ARCH_OMIT_COMPAT_SYS_GETDENTS64 */
@@ -1094,7 +1089,7 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
1094 goto out; 1089 goto out;
1095 1090
1096 tot_len = compat_rw_copy_check_uvector(type, uvector, nr_segs, 1091 tot_len = compat_rw_copy_check_uvector(type, uvector, nr_segs,
1097 UIO_FASTIOV, iovstack, &iov, 1); 1092 UIO_FASTIOV, iovstack, &iov);
1098 if (tot_len == 0) { 1093 if (tot_len == 0) {
1099 ret = 0; 1094 ret = 0;
1100 goto out; 1095 goto out;
@@ -1547,7 +1542,6 @@ asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg)
1547 compat_ptr(a.exp), compat_ptr(a.tvp)); 1542 compat_ptr(a.exp), compat_ptr(a.tvp));
1548} 1543}
1549 1544
1550#ifdef HAVE_SET_RESTORE_SIGMASK
1551static long do_compat_pselect(int n, compat_ulong_t __user *inp, 1545static long do_compat_pselect(int n, compat_ulong_t __user *inp,
1552 compat_ulong_t __user *outp, compat_ulong_t __user *exp, 1546 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
1553 struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask, 1547 struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask,
@@ -1670,11 +1664,9 @@ asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds,
1670 1664
1671 return ret; 1665 return ret;
1672} 1666}
1673#endif /* HAVE_SET_RESTORE_SIGMASK */
1674 1667
1675#ifdef CONFIG_EPOLL 1668#ifdef CONFIG_EPOLL
1676 1669
1677#ifdef HAVE_SET_RESTORE_SIGMASK
1678asmlinkage long compat_sys_epoll_pwait(int epfd, 1670asmlinkage long compat_sys_epoll_pwait(int epfd,
1679 struct compat_epoll_event __user *events, 1671 struct compat_epoll_event __user *events,
1680 int maxevents, int timeout, 1672 int maxevents, int timeout,
@@ -1718,7 +1710,6 @@ asmlinkage long compat_sys_epoll_pwait(int epfd,
1718 1710
1719 return err; 1711 return err;
1720} 1712}
1721#endif /* HAVE_SET_RESTORE_SIGMASK */
1722 1713
1723#endif /* CONFIG_EPOLL */ 1714#endif /* CONFIG_EPOLL */
1724 1715
diff --git a/fs/dcache.c b/fs/dcache.c
index 4435d8b32904..85c9e2bff8e6 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -683,8 +683,6 @@ EXPORT_SYMBOL(dget_parent);
683/** 683/**
684 * d_find_alias - grab a hashed alias of inode 684 * d_find_alias - grab a hashed alias of inode
685 * @inode: inode in question 685 * @inode: inode in question
686 * @want_discon: flag, used by d_splice_alias, to request
687 * that only a DISCONNECTED alias be returned.
688 * 686 *
689 * If inode has a hashed alias, or is a directory and has any alias, 687 * If inode has a hashed alias, or is a directory and has any alias,
690 * acquire the reference to alias and return it. Otherwise return NULL. 688 * acquire the reference to alias and return it. Otherwise return NULL.
@@ -693,10 +691,9 @@ EXPORT_SYMBOL(dget_parent);
693 * of a filesystem. 691 * of a filesystem.
694 * 692 *
695 * If the inode has an IS_ROOT, DCACHE_DISCONNECTED alias, then prefer 693 * If the inode has an IS_ROOT, DCACHE_DISCONNECTED alias, then prefer
696 * any other hashed alias over that one unless @want_discon is set, 694 * any other hashed alias over that.
697 * in which case only return an IS_ROOT, DCACHE_DISCONNECTED alias.
698 */ 695 */
699static struct dentry *__d_find_alias(struct inode *inode, int want_discon) 696static struct dentry *__d_find_alias(struct inode *inode)
700{ 697{
701 struct dentry *alias, *discon_alias; 698 struct dentry *alias, *discon_alias;
702 699
@@ -708,7 +705,7 @@ again:
708 if (IS_ROOT(alias) && 705 if (IS_ROOT(alias) &&
709 (alias->d_flags & DCACHE_DISCONNECTED)) { 706 (alias->d_flags & DCACHE_DISCONNECTED)) {
710 discon_alias = alias; 707 discon_alias = alias;
711 } else if (!want_discon) { 708 } else {
712 __dget_dlock(alias); 709 __dget_dlock(alias);
713 spin_unlock(&alias->d_lock); 710 spin_unlock(&alias->d_lock);
714 return alias; 711 return alias;
@@ -739,7 +736,7 @@ struct dentry *d_find_alias(struct inode *inode)
739 736
740 if (!list_empty(&inode->i_dentry)) { 737 if (!list_empty(&inode->i_dentry)) {
741 spin_lock(&inode->i_lock); 738 spin_lock(&inode->i_lock);
742 de = __d_find_alias(inode, 0); 739 de = __d_find_alias(inode);
743 spin_unlock(&inode->i_lock); 740 spin_unlock(&inode->i_lock);
744 } 741 }
745 return de; 742 return de;
@@ -1650,9 +1647,8 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
1650 1647
1651 if (inode && S_ISDIR(inode->i_mode)) { 1648 if (inode && S_ISDIR(inode->i_mode)) {
1652 spin_lock(&inode->i_lock); 1649 spin_lock(&inode->i_lock);
1653 new = __d_find_alias(inode, 1); 1650 new = __d_find_any_alias(inode);
1654 if (new) { 1651 if (new) {
1655 BUG_ON(!(new->d_flags & DCACHE_DISCONNECTED));
1656 spin_unlock(&inode->i_lock); 1652 spin_unlock(&inode->i_lock);
1657 security_d_instantiate(new, inode); 1653 security_d_instantiate(new, inode);
1658 d_move(new, dentry); 1654 d_move(new, dentry);
@@ -2482,7 +2478,7 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode)
2482 struct dentry *alias; 2478 struct dentry *alias;
2483 2479
2484 /* Does an aliased dentry already exist? */ 2480 /* Does an aliased dentry already exist? */
2485 alias = __d_find_alias(inode, 0); 2481 alias = __d_find_alias(inode);
2486 if (alias) { 2482 if (alias) {
2487 actual = alias; 2483 actual = alias;
2488 write_seqlock(&rename_lock); 2484 write_seqlock(&rename_lock);
@@ -2575,7 +2571,7 @@ static int prepend_path(const struct path *path,
2575 bool slash = false; 2571 bool slash = false;
2576 int error = 0; 2572 int error = 0;
2577 2573
2578 br_read_lock(vfsmount_lock); 2574 br_read_lock(&vfsmount_lock);
2579 while (dentry != root->dentry || vfsmnt != root->mnt) { 2575 while (dentry != root->dentry || vfsmnt != root->mnt) {
2580 struct dentry * parent; 2576 struct dentry * parent;
2581 2577
@@ -2606,7 +2602,7 @@ static int prepend_path(const struct path *path,
2606 error = prepend(buffer, buflen, "/", 1); 2602 error = prepend(buffer, buflen, "/", 1);
2607 2603
2608out: 2604out:
2609 br_read_unlock(vfsmount_lock); 2605 br_read_unlock(&vfsmount_lock);
2610 return error; 2606 return error;
2611 2607
2612global_root: 2608global_root:
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index ab35b113003b..a07441a0a878 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -660,11 +660,10 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
660{ 660{
661 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); 661 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
662 char *lower_buf; 662 char *lower_buf;
663 size_t lower_bufsiz = PATH_MAX;
664 mm_segment_t old_fs; 663 mm_segment_t old_fs;
665 int rc; 664 int rc;
666 665
667 lower_buf = kmalloc(lower_bufsiz, GFP_KERNEL); 666 lower_buf = kmalloc(PATH_MAX, GFP_KERNEL);
668 if (!lower_buf) { 667 if (!lower_buf) {
669 rc = -ENOMEM; 668 rc = -ENOMEM;
670 goto out; 669 goto out;
@@ -673,58 +672,29 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
673 set_fs(get_ds()); 672 set_fs(get_ds());
674 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry, 673 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
675 (char __user *)lower_buf, 674 (char __user *)lower_buf,
676 lower_bufsiz); 675 PATH_MAX);
677 set_fs(old_fs); 676 set_fs(old_fs);
678 if (rc < 0) 677 if (rc < 0)
679 goto out; 678 goto out;
680 lower_bufsiz = rc;
681 rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry, 679 rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry,
682 lower_buf, lower_bufsiz); 680 lower_buf, rc);
683out: 681out:
684 kfree(lower_buf); 682 kfree(lower_buf);
685 return rc; 683 return rc;
686} 684}
687 685
688static int 686static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
689ecryptfs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
690{ 687{
691 char *kbuf; 688 char *buf;
692 size_t kbufsiz, copied; 689 size_t len = PATH_MAX;
693 int rc; 690 int rc;
694 691
695 rc = ecryptfs_readlink_lower(dentry, &kbuf, &kbufsiz); 692 rc = ecryptfs_readlink_lower(dentry, &buf, &len);
696 if (rc) 693 if (rc)
697 goto out; 694 goto out;
698 copied = min_t(size_t, bufsiz, kbufsiz);
699 rc = copy_to_user(buf, kbuf, copied) ? -EFAULT : copied;
700 kfree(kbuf);
701 fsstack_copy_attr_atime(dentry->d_inode, 695 fsstack_copy_attr_atime(dentry->d_inode,
702 ecryptfs_dentry_to_lower(dentry)->d_inode); 696 ecryptfs_dentry_to_lower(dentry)->d_inode);
703out: 697 buf[len] = '\0';
704 return rc;
705}
706
707static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
708{
709 char *buf;
710 int len = PAGE_SIZE, rc;
711 mm_segment_t old_fs;
712
713 /* Released in ecryptfs_put_link(); only release here on error */
714 buf = kmalloc(len, GFP_KERNEL);
715 if (!buf) {
716 buf = ERR_PTR(-ENOMEM);
717 goto out;
718 }
719 old_fs = get_fs();
720 set_fs(get_ds());
721 rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
722 set_fs(old_fs);
723 if (rc < 0) {
724 kfree(buf);
725 buf = ERR_PTR(rc);
726 } else
727 buf[rc] = '\0';
728out: 698out:
729 nd_set_link(nd, buf); 699 nd_set_link(nd, buf);
730 return NULL; 700 return NULL;
@@ -1153,7 +1123,7 @@ out:
1153} 1123}
1154 1124
1155const struct inode_operations ecryptfs_symlink_iops = { 1125const struct inode_operations ecryptfs_symlink_iops = {
1156 .readlink = ecryptfs_readlink, 1126 .readlink = generic_readlink,
1157 .follow_link = ecryptfs_follow_link, 1127 .follow_link = ecryptfs_follow_link,
1158 .put_link = ecryptfs_put_link, 1128 .put_link = ecryptfs_put_link,
1159 .permission = ecryptfs_permission, 1129 .permission = ecryptfs_permission,
diff --git a/fs/eventfd.c b/fs/eventfd.c
index dba15fecf23e..d81b9f654086 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -46,20 +46,16 @@ struct eventfd_ctx {
46 * value, and we signal this as overflow condition by returining a POLLERR 46 * value, and we signal this as overflow condition by returining a POLLERR
47 * to poll(2). 47 * to poll(2).
48 * 48 *
49 * Returns @n in case of success, a non-negative number lower than @n in case 49 * Returns the amount by which the counter was incrememnted. This will be less
50 * of overflow, or the following error codes: 50 * than @n if the counter has overflowed.
51 *
52 * -EINVAL : The value of @n is negative.
53 */ 51 */
54int eventfd_signal(struct eventfd_ctx *ctx, int n) 52__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n)
55{ 53{
56 unsigned long flags; 54 unsigned long flags;
57 55
58 if (n < 0)
59 return -EINVAL;
60 spin_lock_irqsave(&ctx->wqh.lock, flags); 56 spin_lock_irqsave(&ctx->wqh.lock, flags);
61 if (ULLONG_MAX - ctx->count < n) 57 if (ULLONG_MAX - ctx->count < n)
62 n = (int) (ULLONG_MAX - ctx->count); 58 n = ULLONG_MAX - ctx->count;
63 ctx->count += n; 59 ctx->count += n;
64 if (waitqueue_active(&ctx->wqh)) 60 if (waitqueue_active(&ctx->wqh))
65 wake_up_locked_poll(&ctx->wqh, POLLIN); 61 wake_up_locked_poll(&ctx->wqh, POLLIN);
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 079d1be65ba9..74598f67efeb 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1853,8 +1853,6 @@ error_return:
1853 return error; 1853 return error;
1854} 1854}
1855 1855
1856#ifdef HAVE_SET_RESTORE_SIGMASK
1857
1858/* 1856/*
1859 * Implement the event wait interface for the eventpoll file. It is the kernel 1857 * Implement the event wait interface for the eventpoll file. It is the kernel
1860 * part of the user space epoll_pwait(2). 1858 * part of the user space epoll_pwait(2).
@@ -1899,8 +1897,6 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,
1899 return error; 1897 return error;
1900} 1898}
1901 1899
1902#endif /* HAVE_SET_RESTORE_SIGMASK */
1903
1904static int __init eventpoll_init(void) 1900static int __init eventpoll_init(void)
1905{ 1901{
1906 struct sysinfo si; 1902 struct sysinfo si;
diff --git a/fs/exec.c b/fs/exec.c
index 52c9e2ff6e6b..a79786a8d2c8 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -280,10 +280,6 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
280 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); 280 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
281 INIT_LIST_HEAD(&vma->anon_vma_chain); 281 INIT_LIST_HEAD(&vma->anon_vma_chain);
282 282
283 err = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
284 if (err)
285 goto err;
286
287 err = insert_vm_struct(mm, vma); 283 err = insert_vm_struct(mm, vma);
288 if (err) 284 if (err)
289 goto err; 285 goto err;
diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c
index b05acb796135..b0201ca6e9c6 100644
--- a/fs/exportfs/expfs.c
+++ b/fs/exportfs/expfs.c
@@ -304,24 +304,23 @@ out:
304 304
305/** 305/**
306 * export_encode_fh - default export_operations->encode_fh function 306 * export_encode_fh - default export_operations->encode_fh function
307 * @dentry: the dentry to encode 307 * @inode: the object to encode
308 * @fh: where to store the file handle fragment 308 * @fh: where to store the file handle fragment
309 * @max_len: maximum length to store there 309 * @max_len: maximum length to store there
310 * @connectable: whether to store parent information 310 * @parent: parent directory inode, if wanted
311 * 311 *
312 * This default encode_fh function assumes that the 32 inode number 312 * This default encode_fh function assumes that the 32 inode number
313 * is suitable for locating an inode, and that the generation number 313 * is suitable for locating an inode, and that the generation number
314 * can be used to check that it is still valid. It places them in the 314 * can be used to check that it is still valid. It places them in the
315 * filehandle fragment where export_decode_fh expects to find them. 315 * filehandle fragment where export_decode_fh expects to find them.
316 */ 316 */
317static int export_encode_fh(struct dentry *dentry, struct fid *fid, 317static int export_encode_fh(struct inode *inode, struct fid *fid,
318 int *max_len, int connectable) 318 int *max_len, struct inode *parent)
319{ 319{
320 struct inode * inode = dentry->d_inode;
321 int len = *max_len; 320 int len = *max_len;
322 int type = FILEID_INO32_GEN; 321 int type = FILEID_INO32_GEN;
323 322
324 if (connectable && (len < 4)) { 323 if (parent && (len < 4)) {
325 *max_len = 4; 324 *max_len = 4;
326 return 255; 325 return 255;
327 } else if (len < 2) { 326 } else if (len < 2) {
@@ -332,14 +331,9 @@ static int export_encode_fh(struct dentry *dentry, struct fid *fid,
332 len = 2; 331 len = 2;
333 fid->i32.ino = inode->i_ino; 332 fid->i32.ino = inode->i_ino;
334 fid->i32.gen = inode->i_generation; 333 fid->i32.gen = inode->i_generation;
335 if (connectable && !S_ISDIR(inode->i_mode)) { 334 if (parent) {
336 struct inode *parent;
337
338 spin_lock(&dentry->d_lock);
339 parent = dentry->d_parent->d_inode;
340 fid->i32.parent_ino = parent->i_ino; 335 fid->i32.parent_ino = parent->i_ino;
341 fid->i32.parent_gen = parent->i_generation; 336 fid->i32.parent_gen = parent->i_generation;
342 spin_unlock(&dentry->d_lock);
343 len = 4; 337 len = 4;
344 type = FILEID_INO32_GEN_PARENT; 338 type = FILEID_INO32_GEN_PARENT;
345 } 339 }
@@ -352,11 +346,22 @@ int exportfs_encode_fh(struct dentry *dentry, struct fid *fid, int *max_len,
352{ 346{
353 const struct export_operations *nop = dentry->d_sb->s_export_op; 347 const struct export_operations *nop = dentry->d_sb->s_export_op;
354 int error; 348 int error;
349 struct dentry *p = NULL;
350 struct inode *inode = dentry->d_inode, *parent = NULL;
355 351
352 if (connectable && !S_ISDIR(inode->i_mode)) {
353 p = dget_parent(dentry);
354 /*
355 * note that while p might've ceased to be our parent already,
356 * it's still pinned by and still positive.
357 */
358 parent = p->d_inode;
359 }
356 if (nop->encode_fh) 360 if (nop->encode_fh)
357 error = nop->encode_fh(dentry, fid->raw, max_len, connectable); 361 error = nop->encode_fh(inode, fid->raw, max_len, parent);
358 else 362 else
359 error = export_encode_fh(dentry, fid, max_len, connectable); 363 error = export_encode_fh(inode, fid, max_len, parent);
364 dput(p);
360 365
361 return error; 366 return error;
362} 367}
diff --git a/fs/ext4/Kconfig b/fs/ext4/Kconfig
index 9ed1bb1f319f..c22f17021b6e 100644
--- a/fs/ext4/Kconfig
+++ b/fs/ext4/Kconfig
@@ -2,6 +2,8 @@ config EXT4_FS
2 tristate "The Extended 4 (ext4) filesystem" 2 tristate "The Extended 4 (ext4) filesystem"
3 select JBD2 3 select JBD2
4 select CRC16 4 select CRC16
5 select CRYPTO
6 select CRYPTO_CRC32C
5 help 7 help
6 This is the next generation of the ext3 filesystem. 8 This is the next generation of the ext3 filesystem.
7 9
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index c45c41129a35..99b6324290db 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -168,12 +168,14 @@ void ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
168 168
169 /* If checksum is bad mark all blocks used to prevent allocation 169 /* If checksum is bad mark all blocks used to prevent allocation
170 * essentially implementing a per-group read-only flag. */ 170 * essentially implementing a per-group read-only flag. */
171 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { 171 if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) {
172 ext4_error(sb, "Checksum bad for group %u", block_group); 172 ext4_error(sb, "Checksum bad for group %u", block_group);
173 ext4_free_group_clusters_set(sb, gdp, 0); 173 ext4_free_group_clusters_set(sb, gdp, 0);
174 ext4_free_inodes_set(sb, gdp, 0); 174 ext4_free_inodes_set(sb, gdp, 0);
175 ext4_itable_unused_set(sb, gdp, 0); 175 ext4_itable_unused_set(sb, gdp, 0);
176 memset(bh->b_data, 0xff, sb->s_blocksize); 176 memset(bh->b_data, 0xff, sb->s_blocksize);
177 ext4_block_bitmap_csum_set(sb, block_group, gdp, bh,
178 EXT4_BLOCKS_PER_GROUP(sb) / 8);
177 return; 179 return;
178 } 180 }
179 memset(bh->b_data, 0, sb->s_blocksize); 181 memset(bh->b_data, 0, sb->s_blocksize);
@@ -210,6 +212,9 @@ void ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
210 */ 212 */
211 ext4_mark_bitmap_end(num_clusters_in_group(sb, block_group), 213 ext4_mark_bitmap_end(num_clusters_in_group(sb, block_group),
212 sb->s_blocksize * 8, bh->b_data); 214 sb->s_blocksize * 8, bh->b_data);
215 ext4_block_bitmap_csum_set(sb, block_group, gdp, bh,
216 EXT4_BLOCKS_PER_GROUP(sb) / 8);
217 ext4_group_desc_csum_set(sb, block_group, gdp);
213} 218}
214 219
215/* Return the number of free blocks in a block group. It is used when 220/* Return the number of free blocks in a block group. It is used when
@@ -276,9 +281,9 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block *sb,
276} 281}
277 282
278static int ext4_valid_block_bitmap(struct super_block *sb, 283static int ext4_valid_block_bitmap(struct super_block *sb,
279 struct ext4_group_desc *desc, 284 struct ext4_group_desc *desc,
280 unsigned int block_group, 285 unsigned int block_group,
281 struct buffer_head *bh) 286 struct buffer_head *bh)
282{ 287{
283 ext4_grpblk_t offset; 288 ext4_grpblk_t offset;
284 ext4_grpblk_t next_zero_bit; 289 ext4_grpblk_t next_zero_bit;
@@ -325,6 +330,23 @@ err_out:
325 block_group, bitmap_blk); 330 block_group, bitmap_blk);
326 return 0; 331 return 0;
327} 332}
333
334void ext4_validate_block_bitmap(struct super_block *sb,
335 struct ext4_group_desc *desc,
336 unsigned int block_group,
337 struct buffer_head *bh)
338{
339 if (buffer_verified(bh))
340 return;
341
342 ext4_lock_group(sb, block_group);
343 if (ext4_valid_block_bitmap(sb, desc, block_group, bh) &&
344 ext4_block_bitmap_csum_verify(sb, block_group, desc, bh,
345 EXT4_BLOCKS_PER_GROUP(sb) / 8))
346 set_buffer_verified(bh);
347 ext4_unlock_group(sb, block_group);
348}
349
328/** 350/**
329 * ext4_read_block_bitmap() 351 * ext4_read_block_bitmap()
330 * @sb: super block 352 * @sb: super block
@@ -355,12 +377,12 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
355 } 377 }
356 378
357 if (bitmap_uptodate(bh)) 379 if (bitmap_uptodate(bh))
358 return bh; 380 goto verify;
359 381
360 lock_buffer(bh); 382 lock_buffer(bh);
361 if (bitmap_uptodate(bh)) { 383 if (bitmap_uptodate(bh)) {
362 unlock_buffer(bh); 384 unlock_buffer(bh);
363 return bh; 385 goto verify;
364 } 386 }
365 ext4_lock_group(sb, block_group); 387 ext4_lock_group(sb, block_group);
366 if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { 388 if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
@@ -379,7 +401,7 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
379 */ 401 */
380 set_bitmap_uptodate(bh); 402 set_bitmap_uptodate(bh);
381 unlock_buffer(bh); 403 unlock_buffer(bh);
382 return bh; 404 goto verify;
383 } 405 }
384 /* 406 /*
385 * submit the buffer_head for reading 407 * submit the buffer_head for reading
@@ -390,6 +412,9 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
390 get_bh(bh); 412 get_bh(bh);
391 submit_bh(READ, bh); 413 submit_bh(READ, bh);
392 return bh; 414 return bh;
415verify:
416 ext4_validate_block_bitmap(sb, desc, block_group, bh);
417 return bh;
393} 418}
394 419
395/* Returns 0 on success, 1 on error */ 420/* Returns 0 on success, 1 on error */
@@ -412,7 +437,7 @@ int ext4_wait_block_bitmap(struct super_block *sb, ext4_group_t block_group,
412 } 437 }
413 clear_buffer_new(bh); 438 clear_buffer_new(bh);
414 /* Panic or remount fs read-only if block bitmap is invalid */ 439 /* Panic or remount fs read-only if block bitmap is invalid */
415 ext4_valid_block_bitmap(sb, desc, block_group, bh); 440 ext4_validate_block_bitmap(sb, desc, block_group, bh);
416 return 0; 441 return 0;
417} 442}
418 443
diff --git a/fs/ext4/bitmap.c b/fs/ext4/bitmap.c
index fa3af81ac565..b319721da26a 100644
--- a/fs/ext4/bitmap.c
+++ b/fs/ext4/bitmap.c
@@ -29,3 +29,86 @@ unsigned int ext4_count_free(struct buffer_head *map, unsigned int numchars)
29 29
30#endif /* EXT4FS_DEBUG */ 30#endif /* EXT4FS_DEBUG */
31 31
32int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
33 struct ext4_group_desc *gdp,
34 struct buffer_head *bh, int sz)
35{
36 __u32 hi;
37 __u32 provided, calculated;
38 struct ext4_sb_info *sbi = EXT4_SB(sb);
39
40 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
41 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
42 return 1;
43
44 provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo);
45 calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
46 if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END) {
47 hi = le16_to_cpu(gdp->bg_inode_bitmap_csum_hi);
48 provided |= (hi << 16);
49 } else
50 calculated &= 0xFFFF;
51
52 return provided == calculated;
53}
54
55void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
56 struct ext4_group_desc *gdp,
57 struct buffer_head *bh, int sz)
58{
59 __u32 csum;
60 struct ext4_sb_info *sbi = EXT4_SB(sb);
61
62 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
63 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
64 return;
65
66 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
67 gdp->bg_inode_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
68 if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END)
69 gdp->bg_inode_bitmap_csum_hi = cpu_to_le16(csum >> 16);
70}
71
72int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
73 struct ext4_group_desc *gdp,
74 struct buffer_head *bh, int sz)
75{
76 __u32 hi;
77 __u32 provided, calculated;
78 struct ext4_sb_info *sbi = EXT4_SB(sb);
79
80 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
81 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
82 return 1;
83
84 provided = le16_to_cpu(gdp->bg_block_bitmap_csum_lo);
85 calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
86 if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END) {
87 hi = le16_to_cpu(gdp->bg_block_bitmap_csum_hi);
88 provided |= (hi << 16);
89 } else
90 calculated &= 0xFFFF;
91
92 if (provided == calculated)
93 return 1;
94
95 ext4_error(sb, "Bad block bitmap checksum: block_group = %u", group);
96 return 0;
97}
98
99void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
100 struct ext4_group_desc *gdp,
101 struct buffer_head *bh, int sz)
102{
103 __u32 csum;
104 struct ext4_sb_info *sbi = EXT4_SB(sb);
105
106 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
107 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
108 return;
109
110 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
111 gdp->bg_block_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
112 if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END)
113 gdp->bg_block_bitmap_csum_hi = cpu_to_le16(csum >> 16);
114}
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index b86786202643..aa39e600d159 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -179,6 +179,18 @@ static int ext4_readdir(struct file *filp,
179 continue; 179 continue;
180 } 180 }
181 181
182 /* Check the checksum */
183 if (!buffer_verified(bh) &&
184 !ext4_dirent_csum_verify(inode,
185 (struct ext4_dir_entry *)bh->b_data)) {
186 EXT4_ERROR_FILE(filp, 0, "directory fails checksum "
187 "at offset %llu",
188 (unsigned long long)filp->f_pos);
189 filp->f_pos += sb->s_blocksize - offset;
190 continue;
191 }
192 set_buffer_verified(bh);
193
182revalidate: 194revalidate:
183 /* If the dir block has changed since the last call to 195 /* If the dir block has changed since the last call to
184 * readdir(2), then we might be pointing to an invalid 196 * readdir(2), then we might be pointing to an invalid
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index c21b1de51afb..cfc4e01b3c83 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -29,6 +29,7 @@
29#include <linux/wait.h> 29#include <linux/wait.h>
30#include <linux/blockgroup_lock.h> 30#include <linux/blockgroup_lock.h>
31#include <linux/percpu_counter.h> 31#include <linux/percpu_counter.h>
32#include <crypto/hash.h>
32#ifdef __KERNEL__ 33#ifdef __KERNEL__
33#include <linux/compat.h> 34#include <linux/compat.h>
34#endif 35#endif
@@ -298,7 +299,9 @@ struct ext4_group_desc
298 __le16 bg_free_inodes_count_lo;/* Free inodes count */ 299 __le16 bg_free_inodes_count_lo;/* Free inodes count */
299 __le16 bg_used_dirs_count_lo; /* Directories count */ 300 __le16 bg_used_dirs_count_lo; /* Directories count */
300 __le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */ 301 __le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */
301 __u32 bg_reserved[2]; /* Likely block/inode bitmap checksum */ 302 __le32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */
303 __le16 bg_block_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bbitmap) LE */
304 __le16 bg_inode_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+ibitmap) LE */
302 __le16 bg_itable_unused_lo; /* Unused inodes count */ 305 __le16 bg_itable_unused_lo; /* Unused inodes count */
303 __le16 bg_checksum; /* crc16(sb_uuid+group+desc) */ 306 __le16 bg_checksum; /* crc16(sb_uuid+group+desc) */
304 __le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */ 307 __le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */
@@ -308,9 +311,19 @@ struct ext4_group_desc
308 __le16 bg_free_inodes_count_hi;/* Free inodes count MSB */ 311 __le16 bg_free_inodes_count_hi;/* Free inodes count MSB */
309 __le16 bg_used_dirs_count_hi; /* Directories count MSB */ 312 __le16 bg_used_dirs_count_hi; /* Directories count MSB */
310 __le16 bg_itable_unused_hi; /* Unused inodes count MSB */ 313 __le16 bg_itable_unused_hi; /* Unused inodes count MSB */
311 __u32 bg_reserved2[3]; 314 __le32 bg_exclude_bitmap_hi; /* Exclude bitmap block MSB */
315 __le16 bg_block_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+bbitmap) BE */
316 __le16 bg_inode_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+ibitmap) BE */
317 __u32 bg_reserved;
312}; 318};
313 319
320#define EXT4_BG_INODE_BITMAP_CSUM_HI_END \
321 (offsetof(struct ext4_group_desc, bg_inode_bitmap_csum_hi) + \
322 sizeof(__le16))
323#define EXT4_BG_BLOCK_BITMAP_CSUM_HI_END \
324 (offsetof(struct ext4_group_desc, bg_block_bitmap_csum_hi) + \
325 sizeof(__le16))
326
314/* 327/*
315 * Structure of a flex block group info 328 * Structure of a flex block group info
316 */ 329 */
@@ -650,7 +663,8 @@ struct ext4_inode {
650 __le16 l_i_file_acl_high; 663 __le16 l_i_file_acl_high;
651 __le16 l_i_uid_high; /* these 2 fields */ 664 __le16 l_i_uid_high; /* these 2 fields */
652 __le16 l_i_gid_high; /* were reserved2[0] */ 665 __le16 l_i_gid_high; /* were reserved2[0] */
653 __u32 l_i_reserved2; 666 __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
667 __le16 l_i_reserved;
654 } linux2; 668 } linux2;
655 struct { 669 struct {
656 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */ 670 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
@@ -666,7 +680,7 @@ struct ext4_inode {
666 } masix2; 680 } masix2;
667 } osd2; /* OS dependent 2 */ 681 } osd2; /* OS dependent 2 */
668 __le16 i_extra_isize; 682 __le16 i_extra_isize;
669 __le16 i_pad1; 683 __le16 i_checksum_hi; /* crc32c(uuid+inum+inode) BE */
670 __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */ 684 __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */
671 __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */ 685 __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */
672 __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ 686 __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */
@@ -768,7 +782,7 @@ do { \
768#define i_gid_low i_gid 782#define i_gid_low i_gid
769#define i_uid_high osd2.linux2.l_i_uid_high 783#define i_uid_high osd2.linux2.l_i_uid_high
770#define i_gid_high osd2.linux2.l_i_gid_high 784#define i_gid_high osd2.linux2.l_i_gid_high
771#define i_reserved2 osd2.linux2.l_i_reserved2 785#define i_checksum_lo osd2.linux2.l_i_checksum_lo
772 786
773#elif defined(__GNU__) 787#elif defined(__GNU__)
774 788
@@ -908,6 +922,9 @@ struct ext4_inode_info {
908 */ 922 */
909 tid_t i_sync_tid; 923 tid_t i_sync_tid;
910 tid_t i_datasync_tid; 924 tid_t i_datasync_tid;
925
926 /* Precomputed uuid+inum+igen checksum for seeding inode checksums */
927 __u32 i_csum_seed;
911}; 928};
912 929
913/* 930/*
@@ -1001,6 +1018,9 @@ extern void ext4_set_bits(void *bm, int cur, int len);
1001#define EXT4_ERRORS_PANIC 3 /* Panic */ 1018#define EXT4_ERRORS_PANIC 3 /* Panic */
1002#define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE 1019#define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE
1003 1020
1021/* Metadata checksum algorithm codes */
1022#define EXT4_CRC32C_CHKSUM 1
1023
1004/* 1024/*
1005 * Structure of the super block 1025 * Structure of the super block
1006 */ 1026 */
@@ -1087,7 +1107,7 @@ struct ext4_super_block {
1087 __le64 s_mmp_block; /* Block for multi-mount protection */ 1107 __le64 s_mmp_block; /* Block for multi-mount protection */
1088 __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ 1108 __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/
1089 __u8 s_log_groups_per_flex; /* FLEX_BG group size */ 1109 __u8 s_log_groups_per_flex; /* FLEX_BG group size */
1090 __u8 s_reserved_char_pad; 1110 __u8 s_checksum_type; /* metadata checksum algorithm used */
1091 __le16 s_reserved_pad; 1111 __le16 s_reserved_pad;
1092 __le64 s_kbytes_written; /* nr of lifetime kilobytes written */ 1112 __le64 s_kbytes_written; /* nr of lifetime kilobytes written */
1093 __le32 s_snapshot_inum; /* Inode number of active snapshot */ 1113 __le32 s_snapshot_inum; /* Inode number of active snapshot */
@@ -1113,7 +1133,8 @@ struct ext4_super_block {
1113 __le32 s_usr_quota_inum; /* inode for tracking user quota */ 1133 __le32 s_usr_quota_inum; /* inode for tracking user quota */
1114 __le32 s_grp_quota_inum; /* inode for tracking group quota */ 1134 __le32 s_grp_quota_inum; /* inode for tracking group quota */
1115 __le32 s_overhead_clusters; /* overhead blocks/clusters in fs */ 1135 __le32 s_overhead_clusters; /* overhead blocks/clusters in fs */
1116 __le32 s_reserved[109]; /* Padding to the end of the block */ 1136 __le32 s_reserved[108]; /* Padding to the end of the block */
1137 __le32 s_checksum; /* crc32c(superblock) */
1117}; 1138};
1118 1139
1119#define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START) 1140#define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START)
@@ -1176,6 +1197,7 @@ struct ext4_sb_info {
1176 struct proc_dir_entry *s_proc; 1197 struct proc_dir_entry *s_proc;
1177 struct kobject s_kobj; 1198 struct kobject s_kobj;
1178 struct completion s_kobj_unregister; 1199 struct completion s_kobj_unregister;
1200 struct super_block *s_sb;
1179 1201
1180 /* Journaling */ 1202 /* Journaling */
1181 struct journal_s *s_journal; 1203 struct journal_s *s_journal;
@@ -1266,6 +1288,12 @@ struct ext4_sb_info {
1266 1288
1267 /* record the last minlen when FITRIM is called. */ 1289 /* record the last minlen when FITRIM is called. */
1268 atomic_t s_last_trim_minblks; 1290 atomic_t s_last_trim_minblks;
1291
1292 /* Reference to checksum algorithm driver via cryptoapi */
1293 struct crypto_shash *s_chksum_driver;
1294
1295 /* Precomputed FS UUID checksum for seeding other checksums */
1296 __u32 s_csum_seed;
1269}; 1297};
1270 1298
1271static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb) 1299static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
@@ -1414,6 +1442,12 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
1414#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040 1442#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
1415#define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100 1443#define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100
1416#define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200 1444#define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200
1445/*
1446 * METADATA_CSUM also enables group descriptor checksums (GDT_CSUM). When
1447 * METADATA_CSUM is set, group descriptor checksums use the same algorithm as
1448 * all other data structures' checksums. However, the METADATA_CSUM and
1449 * GDT_CSUM bits are mutually exclusive.
1450 */
1417#define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400 1451#define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400
1418 1452
1419#define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001 1453#define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
@@ -1461,7 +1495,8 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
1461 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \ 1495 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \
1462 EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\ 1496 EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\
1463 EXT4_FEATURE_RO_COMPAT_HUGE_FILE |\ 1497 EXT4_FEATURE_RO_COMPAT_HUGE_FILE |\
1464 EXT4_FEATURE_RO_COMPAT_BIGALLOC) 1498 EXT4_FEATURE_RO_COMPAT_BIGALLOC |\
1499 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
1465 1500
1466/* 1501/*
1467 * Default values for user and/or group using reserved blocks 1502 * Default values for user and/or group using reserved blocks
@@ -1527,6 +1562,18 @@ struct ext4_dir_entry_2 {
1527}; 1562};
1528 1563
1529/* 1564/*
1565 * This is a bogus directory entry at the end of each leaf block that
1566 * records checksums.
1567 */
1568struct ext4_dir_entry_tail {
1569 __le32 det_reserved_zero1; /* Pretend to be unused */
1570 __le16 det_rec_len; /* 12 */
1571 __u8 det_reserved_zero2; /* Zero name length */
1572 __u8 det_reserved_ft; /* 0xDE, fake file type */
1573 __le32 det_checksum; /* crc32c(uuid+inum+dirblock) */
1574};
1575
1576/*
1530 * Ext4 directory file types. Only the low 3 bits are used. The 1577 * Ext4 directory file types. Only the low 3 bits are used. The
1531 * other bits are reserved for now. 1578 * other bits are reserved for now.
1532 */ 1579 */
@@ -1541,6 +1588,8 @@ struct ext4_dir_entry_2 {
1541 1588
1542#define EXT4_FT_MAX 8 1589#define EXT4_FT_MAX 8
1543 1590
1591#define EXT4_FT_DIR_CSUM 0xDE
1592
1544/* 1593/*
1545 * EXT4_DIR_PAD defines the directory entries boundaries 1594 * EXT4_DIR_PAD defines the directory entries boundaries
1546 * 1595 *
@@ -1609,6 +1658,25 @@ static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize)
1609#define DX_HASH_HALF_MD4_UNSIGNED 4 1658#define DX_HASH_HALF_MD4_UNSIGNED 4
1610#define DX_HASH_TEA_UNSIGNED 5 1659#define DX_HASH_TEA_UNSIGNED 5
1611 1660
1661static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc,
1662 const void *address, unsigned int length)
1663{
1664 struct {
1665 struct shash_desc shash;
1666 char ctx[crypto_shash_descsize(sbi->s_chksum_driver)];
1667 } desc;
1668 int err;
1669
1670 desc.shash.tfm = sbi->s_chksum_driver;
1671 desc.shash.flags = 0;
1672 *(u32 *)desc.ctx = crc;
1673
1674 err = crypto_shash_update(&desc.shash, address, length);
1675 BUG_ON(err);
1676
1677 return *(u32 *)desc.ctx;
1678}
1679
1612#ifdef __KERNEL__ 1680#ifdef __KERNEL__
1613 1681
1614/* hash info structure used by the directory hash */ 1682/* hash info structure used by the directory hash */
@@ -1741,7 +1809,8 @@ struct mmp_struct {
1741 __le16 mmp_check_interval; 1809 __le16 mmp_check_interval;
1742 1810
1743 __le16 mmp_pad1; 1811 __le16 mmp_pad1;
1744 __le32 mmp_pad2[227]; 1812 __le32 mmp_pad2[226];
1813 __le32 mmp_checksum; /* crc32c(uuid+mmp_block) */
1745}; 1814};
1746 1815
1747/* arguments passed to the mmp thread */ 1816/* arguments passed to the mmp thread */
@@ -1784,8 +1853,24 @@ struct mmpd_data {
1784 1853
1785/* bitmap.c */ 1854/* bitmap.c */
1786extern unsigned int ext4_count_free(struct buffer_head *, unsigned); 1855extern unsigned int ext4_count_free(struct buffer_head *, unsigned);
1856void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
1857 struct ext4_group_desc *gdp,
1858 struct buffer_head *bh, int sz);
1859int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
1860 struct ext4_group_desc *gdp,
1861 struct buffer_head *bh, int sz);
1862void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
1863 struct ext4_group_desc *gdp,
1864 struct buffer_head *bh, int sz);
1865int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
1866 struct ext4_group_desc *gdp,
1867 struct buffer_head *bh, int sz);
1787 1868
1788/* balloc.c */ 1869/* balloc.c */
1870extern void ext4_validate_block_bitmap(struct super_block *sb,
1871 struct ext4_group_desc *desc,
1872 unsigned int block_group,
1873 struct buffer_head *bh);
1789extern unsigned int ext4_block_group(struct super_block *sb, 1874extern unsigned int ext4_block_group(struct super_block *sb,
1790 ext4_fsblk_t blocknr); 1875 ext4_fsblk_t blocknr);
1791extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb, 1876extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb,
@@ -1864,7 +1949,7 @@ extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate);
1864/* mballoc.c */ 1949/* mballoc.c */
1865extern long ext4_mb_stats; 1950extern long ext4_mb_stats;
1866extern long ext4_mb_max_to_scan; 1951extern long ext4_mb_max_to_scan;
1867extern int ext4_mb_init(struct super_block *, int); 1952extern int ext4_mb_init(struct super_block *);
1868extern int ext4_mb_release(struct super_block *); 1953extern int ext4_mb_release(struct super_block *);
1869extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *, 1954extern ext4_fsblk_t ext4_mb_new_blocks(handle_t *,
1870 struct ext4_allocation_request *, int *); 1955 struct ext4_allocation_request *, int *);
@@ -1936,6 +2021,8 @@ extern long ext4_compat_ioctl(struct file *, unsigned int, unsigned long);
1936extern int ext4_ext_migrate(struct inode *); 2021extern int ext4_ext_migrate(struct inode *);
1937 2022
1938/* namei.c */ 2023/* namei.c */
2024extern int ext4_dirent_csum_verify(struct inode *inode,
2025 struct ext4_dir_entry *dirent);
1939extern int ext4_orphan_add(handle_t *, struct inode *); 2026extern int ext4_orphan_add(handle_t *, struct inode *);
1940extern int ext4_orphan_del(handle_t *, struct inode *); 2027extern int ext4_orphan_del(handle_t *, struct inode *);
1941extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash, 2028extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
@@ -1950,6 +2037,10 @@ extern int ext4_group_extend(struct super_block *sb,
1950extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count); 2037extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count);
1951 2038
1952/* super.c */ 2039/* super.c */
2040extern int ext4_superblock_csum_verify(struct super_block *sb,
2041 struct ext4_super_block *es);
2042extern void ext4_superblock_csum_set(struct super_block *sb,
2043 struct ext4_super_block *es);
1953extern void *ext4_kvmalloc(size_t size, gfp_t flags); 2044extern void *ext4_kvmalloc(size_t size, gfp_t flags);
1954extern void *ext4_kvzalloc(size_t size, gfp_t flags); 2045extern void *ext4_kvzalloc(size_t size, gfp_t flags);
1955extern void ext4_kvfree(void *ptr); 2046extern void ext4_kvfree(void *ptr);
@@ -2025,10 +2116,17 @@ extern void ext4_used_dirs_set(struct super_block *sb,
2025 struct ext4_group_desc *bg, __u32 count); 2116 struct ext4_group_desc *bg, __u32 count);
2026extern void ext4_itable_unused_set(struct super_block *sb, 2117extern void ext4_itable_unused_set(struct super_block *sb,
2027 struct ext4_group_desc *bg, __u32 count); 2118 struct ext4_group_desc *bg, __u32 count);
2028extern __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 group, 2119extern int ext4_group_desc_csum_verify(struct super_block *sb, __u32 group,
2029 struct ext4_group_desc *gdp);
2030extern int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 group,
2031 struct ext4_group_desc *gdp); 2120 struct ext4_group_desc *gdp);
2121extern void ext4_group_desc_csum_set(struct super_block *sb, __u32 group,
2122 struct ext4_group_desc *gdp);
2123
2124static inline int ext4_has_group_desc_csum(struct super_block *sb)
2125{
2126 return EXT4_HAS_RO_COMPAT_FEATURE(sb,
2127 EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
2128 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM);
2129}
2032 2130
2033static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es) 2131static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es)
2034{ 2132{
@@ -2225,6 +2323,9 @@ static inline void ext4_unlock_group(struct super_block *sb,
2225 2323
2226static inline void ext4_mark_super_dirty(struct super_block *sb) 2324static inline void ext4_mark_super_dirty(struct super_block *sb)
2227{ 2325{
2326 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
2327
2328 ext4_superblock_csum_set(sb, es);
2228 if (EXT4_SB(sb)->s_journal == NULL) 2329 if (EXT4_SB(sb)->s_journal == NULL)
2229 sb->s_dirt =1; 2330 sb->s_dirt =1;
2230} 2331}
@@ -2314,6 +2415,9 @@ extern int ext4_bio_write_page(struct ext4_io_submit *io,
2314 2415
2315/* mmp.c */ 2416/* mmp.c */
2316extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t); 2417extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t);
2418extern void ext4_mmp_csum_set(struct super_block *sb, struct mmp_struct *mmp);
2419extern int ext4_mmp_csum_verify(struct super_block *sb,
2420 struct mmp_struct *mmp);
2317 2421
2318/* BH_Uninit flag: blocks are allocated but uninitialized on disk */ 2422/* BH_Uninit flag: blocks are allocated but uninitialized on disk */
2319enum ext4_state_bits { 2423enum ext4_state_bits {
diff --git a/fs/ext4/ext4_extents.h b/fs/ext4/ext4_extents.h
index 0f58b86e3a02..cb1b2c919963 100644
--- a/fs/ext4/ext4_extents.h
+++ b/fs/ext4/ext4_extents.h
@@ -63,9 +63,22 @@
63 * ext4_inode has i_block array (60 bytes total). 63 * ext4_inode has i_block array (60 bytes total).
64 * The first 12 bytes store ext4_extent_header; 64 * The first 12 bytes store ext4_extent_header;
65 * the remainder stores an array of ext4_extent. 65 * the remainder stores an array of ext4_extent.
66 * For non-inode extent blocks, ext4_extent_tail
67 * follows the array.
66 */ 68 */
67 69
68/* 70/*
71 * This is the extent tail on-disk structure.
72 * All other extent structures are 12 bytes long. It turns out that
73 * block_size % 12 >= 4 for at least all powers of 2 greater than 512, which
74 * covers all valid ext4 block sizes. Therefore, this tail structure can be
75 * crammed into the end of the block without having to rebalance the tree.
76 */
77struct ext4_extent_tail {
78 __le32 et_checksum; /* crc32c(uuid+inum+extent_block) */
79};
80
81/*
69 * This is the extent on-disk structure. 82 * This is the extent on-disk structure.
70 * It's used at the bottom of the tree. 83 * It's used at the bottom of the tree.
71 */ 84 */
@@ -101,6 +114,17 @@ struct ext4_extent_header {
101 114
102#define EXT4_EXT_MAGIC cpu_to_le16(0xf30a) 115#define EXT4_EXT_MAGIC cpu_to_le16(0xf30a)
103 116
117#define EXT4_EXTENT_TAIL_OFFSET(hdr) \
118 (sizeof(struct ext4_extent_header) + \
119 (sizeof(struct ext4_extent) * le16_to_cpu((hdr)->eh_max)))
120
121static inline struct ext4_extent_tail *
122find_ext4_extent_tail(struct ext4_extent_header *eh)
123{
124 return (struct ext4_extent_tail *)(((void *)eh) +
125 EXT4_EXTENT_TAIL_OFFSET(eh));
126}
127
104/* 128/*
105 * Array of ext4_ext_path contains path to some extent. 129 * Array of ext4_ext_path contains path to some extent.
106 * Creation/lookup routines use it for traversal/splitting/etc. 130 * Creation/lookup routines use it for traversal/splitting/etc.
diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
index aca179017582..90f7c2e84db1 100644
--- a/fs/ext4/ext4_jbd2.c
+++ b/fs/ext4/ext4_jbd2.c
@@ -138,16 +138,23 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
138} 138}
139 139
140int __ext4_handle_dirty_super(const char *where, unsigned int line, 140int __ext4_handle_dirty_super(const char *where, unsigned int line,
141 handle_t *handle, struct super_block *sb) 141 handle_t *handle, struct super_block *sb,
142 int now)
142{ 143{
143 struct buffer_head *bh = EXT4_SB(sb)->s_sbh; 144 struct buffer_head *bh = EXT4_SB(sb)->s_sbh;
144 int err = 0; 145 int err = 0;
145 146
146 if (ext4_handle_valid(handle)) { 147 if (ext4_handle_valid(handle)) {
148 ext4_superblock_csum_set(sb,
149 (struct ext4_super_block *)bh->b_data);
147 err = jbd2_journal_dirty_metadata(handle, bh); 150 err = jbd2_journal_dirty_metadata(handle, bh);
148 if (err) 151 if (err)
149 ext4_journal_abort_handle(where, line, __func__, 152 ext4_journal_abort_handle(where, line, __func__,
150 bh, handle, err); 153 bh, handle, err);
154 } else if (now) {
155 ext4_superblock_csum_set(sb,
156 (struct ext4_super_block *)bh->b_data);
157 mark_buffer_dirty(bh);
151 } else 158 } else
152 sb->s_dirt = 1; 159 sb->s_dirt = 1;
153 return err; 160 return err;
diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h
index 83b20fcf9400..f440e8f1841f 100644
--- a/fs/ext4/ext4_jbd2.h
+++ b/fs/ext4/ext4_jbd2.h
@@ -213,7 +213,8 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
213 struct buffer_head *bh); 213 struct buffer_head *bh);
214 214
215int __ext4_handle_dirty_super(const char *where, unsigned int line, 215int __ext4_handle_dirty_super(const char *where, unsigned int line,
216 handle_t *handle, struct super_block *sb); 216 handle_t *handle, struct super_block *sb,
217 int now);
217 218
218#define ext4_journal_get_write_access(handle, bh) \ 219#define ext4_journal_get_write_access(handle, bh) \
219 __ext4_journal_get_write_access(__func__, __LINE__, (handle), (bh)) 220 __ext4_journal_get_write_access(__func__, __LINE__, (handle), (bh))
@@ -225,8 +226,10 @@ int __ext4_handle_dirty_super(const char *where, unsigned int line,
225#define ext4_handle_dirty_metadata(handle, inode, bh) \ 226#define ext4_handle_dirty_metadata(handle, inode, bh) \
226 __ext4_handle_dirty_metadata(__func__, __LINE__, (handle), (inode), \ 227 __ext4_handle_dirty_metadata(__func__, __LINE__, (handle), (inode), \
227 (bh)) 228 (bh))
229#define ext4_handle_dirty_super_now(handle, sb) \
230 __ext4_handle_dirty_super(__func__, __LINE__, (handle), (sb), 1)
228#define ext4_handle_dirty_super(handle, sb) \ 231#define ext4_handle_dirty_super(handle, sb) \
229 __ext4_handle_dirty_super(__func__, __LINE__, (handle), (sb)) 232 __ext4_handle_dirty_super(__func__, __LINE__, (handle), (sb), 0)
230 233
231handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks); 234handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks);
232int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle); 235int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle);
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index abcdeab67f52..91341ec6e06a 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -52,6 +52,46 @@
52#define EXT4_EXT_MARK_UNINIT1 0x2 /* mark first half uninitialized */ 52#define EXT4_EXT_MARK_UNINIT1 0x2 /* mark first half uninitialized */
53#define EXT4_EXT_MARK_UNINIT2 0x4 /* mark second half uninitialized */ 53#define EXT4_EXT_MARK_UNINIT2 0x4 /* mark second half uninitialized */
54 54
55static __le32 ext4_extent_block_csum(struct inode *inode,
56 struct ext4_extent_header *eh)
57{
58 struct ext4_inode_info *ei = EXT4_I(inode);
59 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
60 __u32 csum;
61
62 csum = ext4_chksum(sbi, ei->i_csum_seed, (__u8 *)eh,
63 EXT4_EXTENT_TAIL_OFFSET(eh));
64 return cpu_to_le32(csum);
65}
66
67static int ext4_extent_block_csum_verify(struct inode *inode,
68 struct ext4_extent_header *eh)
69{
70 struct ext4_extent_tail *et;
71
72 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
73 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
74 return 1;
75
76 et = find_ext4_extent_tail(eh);
77 if (et->et_checksum != ext4_extent_block_csum(inode, eh))
78 return 0;
79 return 1;
80}
81
82static void ext4_extent_block_csum_set(struct inode *inode,
83 struct ext4_extent_header *eh)
84{
85 struct ext4_extent_tail *et;
86
87 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
88 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
89 return;
90
91 et = find_ext4_extent_tail(eh);
92 et->et_checksum = ext4_extent_block_csum(inode, eh);
93}
94
55static int ext4_split_extent(handle_t *handle, 95static int ext4_split_extent(handle_t *handle,
56 struct inode *inode, 96 struct inode *inode,
57 struct ext4_ext_path *path, 97 struct ext4_ext_path *path,
@@ -117,6 +157,7 @@ static int __ext4_ext_dirty(const char *where, unsigned int line,
117{ 157{
118 int err; 158 int err;
119 if (path->p_bh) { 159 if (path->p_bh) {
160 ext4_extent_block_csum_set(inode, ext_block_hdr(path->p_bh));
120 /* path points to block */ 161 /* path points to block */
121 err = __ext4_handle_dirty_metadata(where, line, handle, 162 err = __ext4_handle_dirty_metadata(where, line, handle,
122 inode, path->p_bh); 163 inode, path->p_bh);
@@ -391,6 +432,12 @@ static int __ext4_ext_check(const char *function, unsigned int line,
391 error_msg = "invalid extent entries"; 432 error_msg = "invalid extent entries";
392 goto corrupted; 433 goto corrupted;
393 } 434 }
435 /* Verify checksum on non-root extent tree nodes */
436 if (ext_depth(inode) != depth &&
437 !ext4_extent_block_csum_verify(inode, eh)) {
438 error_msg = "extent tree corrupted";
439 goto corrupted;
440 }
394 return 0; 441 return 0;
395 442
396corrupted: 443corrupted:
@@ -412,6 +459,26 @@ int ext4_ext_check_inode(struct inode *inode)
412 return ext4_ext_check(inode, ext_inode_hdr(inode), ext_depth(inode)); 459 return ext4_ext_check(inode, ext_inode_hdr(inode), ext_depth(inode));
413} 460}
414 461
462static int __ext4_ext_check_block(const char *function, unsigned int line,
463 struct inode *inode,
464 struct ext4_extent_header *eh,
465 int depth,
466 struct buffer_head *bh)
467{
468 int ret;
469
470 if (buffer_verified(bh))
471 return 0;
472 ret = ext4_ext_check(inode, eh, depth);
473 if (ret)
474 return ret;
475 set_buffer_verified(bh);
476 return ret;
477}
478
479#define ext4_ext_check_block(inode, eh, depth, bh) \
480 __ext4_ext_check_block(__func__, __LINE__, inode, eh, depth, bh)
481
415#ifdef EXT_DEBUG 482#ifdef EXT_DEBUG
416static void ext4_ext_show_path(struct inode *inode, struct ext4_ext_path *path) 483static void ext4_ext_show_path(struct inode *inode, struct ext4_ext_path *path)
417{ 484{
@@ -536,7 +603,7 @@ ext4_ext_binsearch_idx(struct inode *inode,
536 } 603 }
537 604
538 path->p_idx = l - 1; 605 path->p_idx = l - 1;
539 ext_debug(" -> %d->%lld ", le32_to_cpu(path->p_idx->ei_block), 606 ext_debug(" -> %u->%lld ", le32_to_cpu(path->p_idx->ei_block),
540 ext4_idx_pblock(path->p_idx)); 607 ext4_idx_pblock(path->p_idx));
541 608
542#ifdef CHECK_BINSEARCH 609#ifdef CHECK_BINSEARCH
@@ -668,8 +735,6 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
668 i = depth; 735 i = depth;
669 /* walk through the tree */ 736 /* walk through the tree */
670 while (i) { 737 while (i) {
671 int need_to_validate = 0;
672
673 ext_debug("depth %d: num %d, max %d\n", 738 ext_debug("depth %d: num %d, max %d\n",
674 ppos, le16_to_cpu(eh->eh_entries), le16_to_cpu(eh->eh_max)); 739 ppos, le16_to_cpu(eh->eh_entries), le16_to_cpu(eh->eh_max));
675 740
@@ -688,8 +753,6 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
688 put_bh(bh); 753 put_bh(bh);
689 goto err; 754 goto err;
690 } 755 }
691 /* validate the extent entries */
692 need_to_validate = 1;
693 } 756 }
694 eh = ext_block_hdr(bh); 757 eh = ext_block_hdr(bh);
695 ppos++; 758 ppos++;
@@ -703,7 +766,7 @@ ext4_ext_find_extent(struct inode *inode, ext4_lblk_t block,
703 path[ppos].p_hdr = eh; 766 path[ppos].p_hdr = eh;
704 i--; 767 i--;
705 768
706 if (need_to_validate && ext4_ext_check(inode, eh, i)) 769 if (ext4_ext_check_block(inode, eh, i, bh))
707 goto err; 770 goto err;
708 } 771 }
709 772
@@ -914,6 +977,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
914 le16_add_cpu(&neh->eh_entries, m); 977 le16_add_cpu(&neh->eh_entries, m);
915 } 978 }
916 979
980 ext4_extent_block_csum_set(inode, neh);
917 set_buffer_uptodate(bh); 981 set_buffer_uptodate(bh);
918 unlock_buffer(bh); 982 unlock_buffer(bh);
919 983
@@ -992,6 +1056,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
992 sizeof(struct ext4_extent_idx) * m); 1056 sizeof(struct ext4_extent_idx) * m);
993 le16_add_cpu(&neh->eh_entries, m); 1057 le16_add_cpu(&neh->eh_entries, m);
994 } 1058 }
1059 ext4_extent_block_csum_set(inode, neh);
995 set_buffer_uptodate(bh); 1060 set_buffer_uptodate(bh);
996 unlock_buffer(bh); 1061 unlock_buffer(bh);
997 1062
@@ -1089,6 +1154,7 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
1089 else 1154 else
1090 neh->eh_max = cpu_to_le16(ext4_ext_space_block(inode, 0)); 1155 neh->eh_max = cpu_to_le16(ext4_ext_space_block(inode, 0));
1091 neh->eh_magic = EXT4_EXT_MAGIC; 1156 neh->eh_magic = EXT4_EXT_MAGIC;
1157 ext4_extent_block_csum_set(inode, neh);
1092 set_buffer_uptodate(bh); 1158 set_buffer_uptodate(bh);
1093 unlock_buffer(bh); 1159 unlock_buffer(bh);
1094 1160
@@ -1344,7 +1410,8 @@ got_index:
1344 return -EIO; 1410 return -EIO;
1345 eh = ext_block_hdr(bh); 1411 eh = ext_block_hdr(bh);
1346 /* subtract from p_depth to get proper eh_depth */ 1412 /* subtract from p_depth to get proper eh_depth */
1347 if (ext4_ext_check(inode, eh, path->p_depth - depth)) { 1413 if (ext4_ext_check_block(inode, eh,
1414 path->p_depth - depth, bh)) {
1348 put_bh(bh); 1415 put_bh(bh);
1349 return -EIO; 1416 return -EIO;
1350 } 1417 }
@@ -1357,7 +1424,7 @@ got_index:
1357 if (bh == NULL) 1424 if (bh == NULL)
1358 return -EIO; 1425 return -EIO;
1359 eh = ext_block_hdr(bh); 1426 eh = ext_block_hdr(bh);
1360 if (ext4_ext_check(inode, eh, path->p_depth - depth)) { 1427 if (ext4_ext_check_block(inode, eh, path->p_depth - depth, bh)) {
1361 put_bh(bh); 1428 put_bh(bh);
1362 return -EIO; 1429 return -EIO;
1363 } 1430 }
@@ -2644,8 +2711,8 @@ cont:
2644 err = -EIO; 2711 err = -EIO;
2645 break; 2712 break;
2646 } 2713 }
2647 if (ext4_ext_check(inode, ext_block_hdr(bh), 2714 if (ext4_ext_check_block(inode, ext_block_hdr(bh),
2648 depth - i - 1)) { 2715 depth - i - 1, bh)) {
2649 err = -EIO; 2716 err = -EIO;
2650 break; 2717 break;
2651 } 2718 }
@@ -4722,8 +4789,8 @@ int ext4_ext_punch_hole(struct file *file, loff_t offset, loff_t length)
4722 4789
4723 /* Now release the pages */ 4790 /* Now release the pages */
4724 if (last_page_offset > first_page_offset) { 4791 if (last_page_offset > first_page_offset) {
4725 truncate_inode_pages_range(mapping, first_page_offset, 4792 truncate_pagecache_range(inode, first_page_offset,
4726 last_page_offset-1); 4793 last_page_offset - 1);
4727 } 4794 }
4728 4795
4729 /* finish any pending end_io work */ 4796 /* finish any pending end_io work */
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index cb70f1812a70..8c7642a00054 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -95,7 +95,7 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
95{ 95{
96 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode; 96 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
97 int unaligned_aio = 0; 97 int unaligned_aio = 0;
98 int ret; 98 ssize_t ret;
99 99
100 /* 100 /*
101 * If we have encountered a bitmap-format file, the size limit 101 * If we have encountered a bitmap-format file, the size limit
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 9f9acac6c43f..d48e8b14928c 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -70,24 +70,27 @@ static unsigned ext4_init_inode_bitmap(struct super_block *sb,
70 ext4_group_t block_group, 70 ext4_group_t block_group,
71 struct ext4_group_desc *gdp) 71 struct ext4_group_desc *gdp)
72{ 72{
73 struct ext4_sb_info *sbi = EXT4_SB(sb);
74
75 J_ASSERT_BH(bh, buffer_locked(bh)); 73 J_ASSERT_BH(bh, buffer_locked(bh));
76 74
77 /* If checksum is bad mark all blocks and inodes use to prevent 75 /* If checksum is bad mark all blocks and inodes use to prevent
78 * allocation, essentially implementing a per-group read-only flag. */ 76 * allocation, essentially implementing a per-group read-only flag. */
79 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { 77 if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) {
80 ext4_error(sb, "Checksum bad for group %u", block_group); 78 ext4_error(sb, "Checksum bad for group %u", block_group);
81 ext4_free_group_clusters_set(sb, gdp, 0); 79 ext4_free_group_clusters_set(sb, gdp, 0);
82 ext4_free_inodes_set(sb, gdp, 0); 80 ext4_free_inodes_set(sb, gdp, 0);
83 ext4_itable_unused_set(sb, gdp, 0); 81 ext4_itable_unused_set(sb, gdp, 0);
84 memset(bh->b_data, 0xff, sb->s_blocksize); 82 memset(bh->b_data, 0xff, sb->s_blocksize);
83 ext4_inode_bitmap_csum_set(sb, block_group, gdp, bh,
84 EXT4_INODES_PER_GROUP(sb) / 8);
85 return 0; 85 return 0;
86 } 86 }
87 87
88 memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8); 88 memset(bh->b_data, 0, (EXT4_INODES_PER_GROUP(sb) + 7) / 8);
89 ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), sb->s_blocksize * 8, 89 ext4_mark_bitmap_end(EXT4_INODES_PER_GROUP(sb), sb->s_blocksize * 8,
90 bh->b_data); 90 bh->b_data);
91 ext4_inode_bitmap_csum_set(sb, block_group, gdp, bh,
92 EXT4_INODES_PER_GROUP(sb) / 8);
93 ext4_group_desc_csum_set(sb, block_group, gdp);
91 94
92 return EXT4_INODES_PER_GROUP(sb); 95 return EXT4_INODES_PER_GROUP(sb);
93} 96}
@@ -128,12 +131,12 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
128 return NULL; 131 return NULL;
129 } 132 }
130 if (bitmap_uptodate(bh)) 133 if (bitmap_uptodate(bh))
131 return bh; 134 goto verify;
132 135
133 lock_buffer(bh); 136 lock_buffer(bh);
134 if (bitmap_uptodate(bh)) { 137 if (bitmap_uptodate(bh)) {
135 unlock_buffer(bh); 138 unlock_buffer(bh);
136 return bh; 139 goto verify;
137 } 140 }
138 141
139 ext4_lock_group(sb, block_group); 142 ext4_lock_group(sb, block_group);
@@ -141,6 +144,7 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
141 ext4_init_inode_bitmap(sb, bh, block_group, desc); 144 ext4_init_inode_bitmap(sb, bh, block_group, desc);
142 set_bitmap_uptodate(bh); 145 set_bitmap_uptodate(bh);
143 set_buffer_uptodate(bh); 146 set_buffer_uptodate(bh);
147 set_buffer_verified(bh);
144 ext4_unlock_group(sb, block_group); 148 ext4_unlock_group(sb, block_group);
145 unlock_buffer(bh); 149 unlock_buffer(bh);
146 return bh; 150 return bh;
@@ -154,7 +158,7 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
154 */ 158 */
155 set_bitmap_uptodate(bh); 159 set_bitmap_uptodate(bh);
156 unlock_buffer(bh); 160 unlock_buffer(bh);
157 return bh; 161 goto verify;
158 } 162 }
159 /* 163 /*
160 * submit the buffer_head for reading 164 * submit the buffer_head for reading
@@ -171,6 +175,20 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
171 block_group, bitmap_blk); 175 block_group, bitmap_blk);
172 return NULL; 176 return NULL;
173 } 177 }
178
179verify:
180 ext4_lock_group(sb, block_group);
181 if (!buffer_verified(bh) &&
182 !ext4_inode_bitmap_csum_verify(sb, block_group, desc, bh,
183 EXT4_INODES_PER_GROUP(sb) / 8)) {
184 ext4_unlock_group(sb, block_group);
185 put_bh(bh);
186 ext4_error(sb, "Corrupt inode bitmap - block_group = %u, "
187 "inode_bitmap = %llu", block_group, bitmap_blk);
188 return NULL;
189 }
190 ext4_unlock_group(sb, block_group);
191 set_buffer_verified(bh);
174 return bh; 192 return bh;
175} 193}
176 194
@@ -276,7 +294,9 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
276 ext4_used_dirs_set(sb, gdp, count); 294 ext4_used_dirs_set(sb, gdp, count);
277 percpu_counter_dec(&sbi->s_dirs_counter); 295 percpu_counter_dec(&sbi->s_dirs_counter);
278 } 296 }
279 gdp->bg_checksum = ext4_group_desc_csum(sbi, block_group, gdp); 297 ext4_inode_bitmap_csum_set(sb, block_group, gdp, bitmap_bh,
298 EXT4_INODES_PER_GROUP(sb) / 8);
299 ext4_group_desc_csum_set(sb, block_group, gdp);
280 ext4_unlock_group(sb, block_group); 300 ext4_unlock_group(sb, block_group);
281 301
282 percpu_counter_inc(&sbi->s_freeinodes_counter); 302 percpu_counter_inc(&sbi->s_freeinodes_counter);
@@ -488,10 +508,12 @@ fallback_retry:
488 for (i = 0; i < ngroups; i++) { 508 for (i = 0; i < ngroups; i++) {
489 grp = (parent_group + i) % ngroups; 509 grp = (parent_group + i) % ngroups;
490 desc = ext4_get_group_desc(sb, grp, NULL); 510 desc = ext4_get_group_desc(sb, grp, NULL);
491 grp_free = ext4_free_inodes_count(sb, desc); 511 if (desc) {
492 if (desc && grp_free && grp_free >= avefreei) { 512 grp_free = ext4_free_inodes_count(sb, desc);
493 *group = grp; 513 if (grp_free && grp_free >= avefreei) {
494 return 0; 514 *group = grp;
515 return 0;
516 }
495 } 517 }
496 } 518 }
497 519
@@ -709,7 +731,7 @@ repeat_in_this_group:
709 731
710got: 732got:
711 /* We may have to initialize the block bitmap if it isn't already */ 733 /* We may have to initialize the block bitmap if it isn't already */
712 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM) && 734 if (ext4_has_group_desc_csum(sb) &&
713 gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { 735 gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
714 struct buffer_head *block_bitmap_bh; 736 struct buffer_head *block_bitmap_bh;
715 737
@@ -731,8 +753,11 @@ got:
731 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); 753 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);
732 ext4_free_group_clusters_set(sb, gdp, 754 ext4_free_group_clusters_set(sb, gdp,
733 ext4_free_clusters_after_init(sb, group, gdp)); 755 ext4_free_clusters_after_init(sb, group, gdp));
734 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, 756 ext4_block_bitmap_csum_set(sb, group, gdp,
735 gdp); 757 block_bitmap_bh,
758 EXT4_BLOCKS_PER_GROUP(sb) /
759 8);
760 ext4_group_desc_csum_set(sb, group, gdp);
736 } 761 }
737 ext4_unlock_group(sb, group); 762 ext4_unlock_group(sb, group);
738 763
@@ -751,7 +776,7 @@ got:
751 goto fail; 776 goto fail;
752 777
753 /* Update the relevant bg descriptor fields */ 778 /* Update the relevant bg descriptor fields */
754 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { 779 if (ext4_has_group_desc_csum(sb)) {
755 int free; 780 int free;
756 struct ext4_group_info *grp = ext4_get_group_info(sb, group); 781 struct ext4_group_info *grp = ext4_get_group_info(sb, group);
757 782
@@ -772,7 +797,10 @@ got:
772 ext4_itable_unused_set(sb, gdp, 797 ext4_itable_unused_set(sb, gdp,
773 (EXT4_INODES_PER_GROUP(sb) - ino)); 798 (EXT4_INODES_PER_GROUP(sb) - ino));
774 up_read(&grp->alloc_sem); 799 up_read(&grp->alloc_sem);
800 } else {
801 ext4_lock_group(sb, group);
775 } 802 }
803
776 ext4_free_inodes_set(sb, gdp, ext4_free_inodes_count(sb, gdp) - 1); 804 ext4_free_inodes_set(sb, gdp, ext4_free_inodes_count(sb, gdp) - 1);
777 if (S_ISDIR(mode)) { 805 if (S_ISDIR(mode)) {
778 ext4_used_dirs_set(sb, gdp, ext4_used_dirs_count(sb, gdp) + 1); 806 ext4_used_dirs_set(sb, gdp, ext4_used_dirs_count(sb, gdp) + 1);
@@ -782,10 +810,12 @@ got:
782 atomic_inc(&sbi->s_flex_groups[f].used_dirs); 810 atomic_inc(&sbi->s_flex_groups[f].used_dirs);
783 } 811 }
784 } 812 }
785 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { 813 if (ext4_has_group_desc_csum(sb)) {
786 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp); 814 ext4_inode_bitmap_csum_set(sb, group, gdp, inode_bitmap_bh,
787 ext4_unlock_group(sb, group); 815 EXT4_INODES_PER_GROUP(sb) / 8);
816 ext4_group_desc_csum_set(sb, group, gdp);
788 } 817 }
818 ext4_unlock_group(sb, group);
789 819
790 BUFFER_TRACE(inode_bitmap_bh, "call ext4_handle_dirty_metadata"); 820 BUFFER_TRACE(inode_bitmap_bh, "call ext4_handle_dirty_metadata");
791 err = ext4_handle_dirty_metadata(handle, NULL, inode_bitmap_bh); 821 err = ext4_handle_dirty_metadata(handle, NULL, inode_bitmap_bh);
@@ -850,6 +880,19 @@ got:
850 inode->i_generation = sbi->s_next_generation++; 880 inode->i_generation = sbi->s_next_generation++;
851 spin_unlock(&sbi->s_next_gen_lock); 881 spin_unlock(&sbi->s_next_gen_lock);
852 882
883 /* Precompute checksum seed for inode metadata */
884 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
885 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
886 __u32 csum;
887 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
888 __le32 inum = cpu_to_le32(inode->i_ino);
889 __le32 gen = cpu_to_le32(inode->i_generation);
890 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&inum,
891 sizeof(inum));
892 ei->i_csum_seed = ext4_chksum(sbi, csum, (__u8 *)&gen,
893 sizeof(gen));
894 }
895
853 ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */ 896 ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
854 ext4_set_inode_state(inode, EXT4_STATE_NEW); 897 ext4_set_inode_state(inode, EXT4_STATE_NEW);
855 898
@@ -1140,7 +1183,7 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group,
1140skip_zeroout: 1183skip_zeroout:
1141 ext4_lock_group(sb, group); 1184 ext4_lock_group(sb, group);
1142 gdp->bg_flags |= cpu_to_le16(EXT4_BG_INODE_ZEROED); 1185 gdp->bg_flags |= cpu_to_le16(EXT4_BG_INODE_ZEROED);
1143 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp); 1186 ext4_group_desc_csum_set(sb, group, gdp);
1144 ext4_unlock_group(sb, group); 1187 ext4_unlock_group(sb, group);
1145 1188
1146 BUFFER_TRACE(group_desc_bh, 1189 BUFFER_TRACE(group_desc_bh,
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 07eaf565fdcb..02bc8cbe7281 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -47,6 +47,73 @@
47 47
48#define MPAGE_DA_EXTENT_TAIL 0x01 48#define MPAGE_DA_EXTENT_TAIL 0x01
49 49
50static __u32 ext4_inode_csum(struct inode *inode, struct ext4_inode *raw,
51 struct ext4_inode_info *ei)
52{
53 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
54 __u16 csum_lo;
55 __u16 csum_hi = 0;
56 __u32 csum;
57
58 csum_lo = raw->i_checksum_lo;
59 raw->i_checksum_lo = 0;
60 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE &&
61 EXT4_FITS_IN_INODE(raw, ei, i_checksum_hi)) {
62 csum_hi = raw->i_checksum_hi;
63 raw->i_checksum_hi = 0;
64 }
65
66 csum = ext4_chksum(sbi, ei->i_csum_seed, (__u8 *)raw,
67 EXT4_INODE_SIZE(inode->i_sb));
68
69 raw->i_checksum_lo = csum_lo;
70 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE &&
71 EXT4_FITS_IN_INODE(raw, ei, i_checksum_hi))
72 raw->i_checksum_hi = csum_hi;
73
74 return csum;
75}
76
77static int ext4_inode_csum_verify(struct inode *inode, struct ext4_inode *raw,
78 struct ext4_inode_info *ei)
79{
80 __u32 provided, calculated;
81
82 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os !=
83 cpu_to_le32(EXT4_OS_LINUX) ||
84 !EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
85 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
86 return 1;
87
88 provided = le16_to_cpu(raw->i_checksum_lo);
89 calculated = ext4_inode_csum(inode, raw, ei);
90 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE &&
91 EXT4_FITS_IN_INODE(raw, ei, i_checksum_hi))
92 provided |= ((__u32)le16_to_cpu(raw->i_checksum_hi)) << 16;
93 else
94 calculated &= 0xFFFF;
95
96 return provided == calculated;
97}
98
99static void ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw,
100 struct ext4_inode_info *ei)
101{
102 __u32 csum;
103
104 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os !=
105 cpu_to_le32(EXT4_OS_LINUX) ||
106 !EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
107 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
108 return;
109
110 csum = ext4_inode_csum(inode, raw, ei);
111 raw->i_checksum_lo = cpu_to_le16(csum & 0xFFFF);
112 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE &&
113 EXT4_FITS_IN_INODE(raw, ei, i_checksum_hi))
114 raw->i_checksum_hi = cpu_to_le16(csum >> 16);
115}
116
50static inline int ext4_begin_ordered_truncate(struct inode *inode, 117static inline int ext4_begin_ordered_truncate(struct inode *inode,
51 loff_t new_size) 118 loff_t new_size)
52{ 119{
@@ -3517,8 +3584,7 @@ make_io:
3517 b = table; 3584 b = table;
3518 end = b + EXT4_SB(sb)->s_inode_readahead_blks; 3585 end = b + EXT4_SB(sb)->s_inode_readahead_blks;
3519 num = EXT4_INODES_PER_GROUP(sb); 3586 num = EXT4_INODES_PER_GROUP(sb);
3520 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 3587 if (ext4_has_group_desc_csum(sb))
3521 EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
3522 num -= ext4_itable_unused_count(sb, gdp); 3588 num -= ext4_itable_unused_count(sb, gdp);
3523 table += num / inodes_per_block; 3589 table += num / inodes_per_block;
3524 if (end > table) 3590 if (end > table)
@@ -3646,6 +3712,39 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
3646 if (ret < 0) 3712 if (ret < 0)
3647 goto bad_inode; 3713 goto bad_inode;
3648 raw_inode = ext4_raw_inode(&iloc); 3714 raw_inode = ext4_raw_inode(&iloc);
3715
3716 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
3717 ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize);
3718 if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
3719 EXT4_INODE_SIZE(inode->i_sb)) {
3720 EXT4_ERROR_INODE(inode, "bad extra_isize (%u != %u)",
3721 EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize,
3722 EXT4_INODE_SIZE(inode->i_sb));
3723 ret = -EIO;
3724 goto bad_inode;
3725 }
3726 } else
3727 ei->i_extra_isize = 0;
3728
3729 /* Precompute checksum seed for inode metadata */
3730 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
3731 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
3732 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
3733 __u32 csum;
3734 __le32 inum = cpu_to_le32(inode->i_ino);
3735 __le32 gen = raw_inode->i_generation;
3736 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&inum,
3737 sizeof(inum));
3738 ei->i_csum_seed = ext4_chksum(sbi, csum, (__u8 *)&gen,
3739 sizeof(gen));
3740 }
3741
3742 if (!ext4_inode_csum_verify(inode, raw_inode, ei)) {
3743 EXT4_ERROR_INODE(inode, "checksum invalid");
3744 ret = -EIO;
3745 goto bad_inode;
3746 }
3747
3649 inode->i_mode = le16_to_cpu(raw_inode->i_mode); 3748 inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3650 i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low); 3749 i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3651 i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low); 3750 i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
@@ -3725,12 +3824,6 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
3725 } 3824 }
3726 3825
3727 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { 3826 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) {
3728 ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize);
3729 if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize >
3730 EXT4_INODE_SIZE(inode->i_sb)) {
3731 ret = -EIO;
3732 goto bad_inode;
3733 }
3734 if (ei->i_extra_isize == 0) { 3827 if (ei->i_extra_isize == 0) {
3735 /* The extra space is currently unused. Use it. */ 3828 /* The extra space is currently unused. Use it. */
3736 ei->i_extra_isize = sizeof(struct ext4_inode) - 3829 ei->i_extra_isize = sizeof(struct ext4_inode) -
@@ -3742,8 +3835,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
3742 if (*magic == cpu_to_le32(EXT4_XATTR_MAGIC)) 3835 if (*magic == cpu_to_le32(EXT4_XATTR_MAGIC))
3743 ext4_set_inode_state(inode, EXT4_STATE_XATTR); 3836 ext4_set_inode_state(inode, EXT4_STATE_XATTR);
3744 } 3837 }
3745 } else 3838 }
3746 ei->i_extra_isize = 0;
3747 3839
3748 EXT4_INODE_GET_XTIME(i_ctime, inode, raw_inode); 3840 EXT4_INODE_GET_XTIME(i_ctime, inode, raw_inode);
3749 EXT4_INODE_GET_XTIME(i_mtime, inode, raw_inode); 3841 EXT4_INODE_GET_XTIME(i_mtime, inode, raw_inode);
@@ -3942,7 +4034,7 @@ static int ext4_do_update_inode(handle_t *handle,
3942 EXT4_SET_RO_COMPAT_FEATURE(sb, 4034 EXT4_SET_RO_COMPAT_FEATURE(sb,
3943 EXT4_FEATURE_RO_COMPAT_LARGE_FILE); 4035 EXT4_FEATURE_RO_COMPAT_LARGE_FILE);
3944 ext4_handle_sync(handle); 4036 ext4_handle_sync(handle);
3945 err = ext4_handle_dirty_super(handle, sb); 4037 err = ext4_handle_dirty_super_now(handle, sb);
3946 } 4038 }
3947 } 4039 }
3948 raw_inode->i_generation = cpu_to_le32(inode->i_generation); 4040 raw_inode->i_generation = cpu_to_le32(inode->i_generation);
@@ -3969,6 +4061,8 @@ static int ext4_do_update_inode(handle_t *handle,
3969 raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize); 4061 raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize);
3970 } 4062 }
3971 4063
4064 ext4_inode_csum_set(inode, raw_inode, ei);
4065
3972 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); 4066 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
3973 rc = ext4_handle_dirty_metadata(handle, NULL, bh); 4067 rc = ext4_handle_dirty_metadata(handle, NULL, bh);
3974 if (!err) 4068 if (!err)
@@ -4213,7 +4307,8 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
4213 * will return the blocks that include the delayed allocation 4307 * will return the blocks that include the delayed allocation
4214 * blocks for this file. 4308 * blocks for this file.
4215 */ 4309 */
4216 delalloc_blocks = EXT4_I(inode)->i_reserved_data_blocks; 4310 delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb),
4311 EXT4_I(inode)->i_reserved_data_blocks);
4217 4312
4218 stat->blocks += (delalloc_blocks << inode->i_sb->s_blocksize_bits)>>9; 4313 stat->blocks += (delalloc_blocks << inode->i_sb->s_blocksize_bits)>>9;
4219 return 0; 4314 return 0;
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 6eee25591b81..8ad112ae0ade 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -38,7 +38,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38 handle_t *handle = NULL; 38 handle_t *handle = NULL;
39 int err, migrate = 0; 39 int err, migrate = 0;
40 struct ext4_iloc iloc; 40 struct ext4_iloc iloc;
41 unsigned int oldflags; 41 unsigned int oldflags, mask, i;
42 unsigned int jflag; 42 unsigned int jflag;
43 43
44 if (!inode_owner_or_capable(inode)) 44 if (!inode_owner_or_capable(inode))
@@ -115,8 +115,14 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
115 if (err) 115 if (err)
116 goto flags_err; 116 goto flags_err;
117 117
118 flags = flags & EXT4_FL_USER_MODIFIABLE; 118 for (i = 0, mask = 1; i < 32; i++, mask <<= 1) {
119 flags |= oldflags & ~EXT4_FL_USER_MODIFIABLE; 119 if (!(mask & EXT4_FL_USER_MODIFIABLE))
120 continue;
121 if (mask & flags)
122 ext4_set_inode_flag(inode, i);
123 else
124 ext4_clear_inode_flag(inode, i);
125 }
120 ei->i_flags = flags; 126 ei->i_flags = flags;
121 127
122 ext4_set_inode_flags(inode); 128 ext4_set_inode_flags(inode);
@@ -152,6 +158,13 @@ flags_out:
152 if (!inode_owner_or_capable(inode)) 158 if (!inode_owner_or_capable(inode))
153 return -EPERM; 159 return -EPERM;
154 160
161 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
162 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
163 ext4_warning(sb, "Setting inode version is not "
164 "supported with metadata_csum enabled.");
165 return -ENOTTY;
166 }
167
155 err = mnt_want_write_file(filp); 168 err = mnt_want_write_file(filp);
156 if (err) 169 if (err)
157 return err; 170 return err;
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 99ab428bcfa0..1cd6994fc446 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -788,7 +788,7 @@ static int ext4_mb_init_cache(struct page *page, char *incore)
788 int first_block; 788 int first_block;
789 struct super_block *sb; 789 struct super_block *sb;
790 struct buffer_head *bhs; 790 struct buffer_head *bhs;
791 struct buffer_head **bh; 791 struct buffer_head **bh = NULL;
792 struct inode *inode; 792 struct inode *inode;
793 char *data; 793 char *data;
794 char *bitmap; 794 char *bitmap;
@@ -2375,7 +2375,7 @@ static int ext4_groupinfo_create_slab(size_t size)
2375 return 0; 2375 return 0;
2376} 2376}
2377 2377
2378int ext4_mb_init(struct super_block *sb, int needs_recovery) 2378int ext4_mb_init(struct super_block *sb)
2379{ 2379{
2380 struct ext4_sb_info *sbi = EXT4_SB(sb); 2380 struct ext4_sb_info *sbi = EXT4_SB(sb);
2381 unsigned i, j; 2381 unsigned i, j;
@@ -2517,6 +2517,9 @@ int ext4_mb_release(struct super_block *sb)
2517 struct ext4_sb_info *sbi = EXT4_SB(sb); 2517 struct ext4_sb_info *sbi = EXT4_SB(sb);
2518 struct kmem_cache *cachep = get_groupinfo_cache(sb->s_blocksize_bits); 2518 struct kmem_cache *cachep = get_groupinfo_cache(sb->s_blocksize_bits);
2519 2519
2520 if (sbi->s_proc)
2521 remove_proc_entry("mb_groups", sbi->s_proc);
2522
2520 if (sbi->s_group_info) { 2523 if (sbi->s_group_info) {
2521 for (i = 0; i < ngroups; i++) { 2524 for (i = 0; i < ngroups; i++) {
2522 grinfo = ext4_get_group_info(sb, i); 2525 grinfo = ext4_get_group_info(sb, i);
@@ -2564,8 +2567,6 @@ int ext4_mb_release(struct super_block *sb)
2564 } 2567 }
2565 2568
2566 free_percpu(sbi->s_locality_groups); 2569 free_percpu(sbi->s_locality_groups);
2567 if (sbi->s_proc)
2568 remove_proc_entry("mb_groups", sbi->s_proc);
2569 2570
2570 return 0; 2571 return 0;
2571} 2572}
@@ -2797,7 +2798,9 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
2797 } 2798 }
2798 len = ext4_free_group_clusters(sb, gdp) - ac->ac_b_ex.fe_len; 2799 len = ext4_free_group_clusters(sb, gdp) - ac->ac_b_ex.fe_len;
2799 ext4_free_group_clusters_set(sb, gdp, len); 2800 ext4_free_group_clusters_set(sb, gdp, len);
2800 gdp->bg_checksum = ext4_group_desc_csum(sbi, ac->ac_b_ex.fe_group, gdp); 2801 ext4_block_bitmap_csum_set(sb, ac->ac_b_ex.fe_group, gdp, bitmap_bh,
2802 EXT4_BLOCKS_PER_GROUP(sb) / 8);
2803 ext4_group_desc_csum_set(sb, ac->ac_b_ex.fe_group, gdp);
2801 2804
2802 ext4_unlock_group(sb, ac->ac_b_ex.fe_group); 2805 ext4_unlock_group(sb, ac->ac_b_ex.fe_group);
2803 percpu_counter_sub(&sbi->s_freeclusters_counter, ac->ac_b_ex.fe_len); 2806 percpu_counter_sub(&sbi->s_freeclusters_counter, ac->ac_b_ex.fe_len);
@@ -3071,13 +3074,9 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
3071static void ext4_discard_allocated_blocks(struct ext4_allocation_context *ac) 3074static void ext4_discard_allocated_blocks(struct ext4_allocation_context *ac)
3072{ 3075{
3073 struct ext4_prealloc_space *pa = ac->ac_pa; 3076 struct ext4_prealloc_space *pa = ac->ac_pa;
3074 int len;
3075
3076 if (pa && pa->pa_type == MB_INODE_PA) {
3077 len = ac->ac_b_ex.fe_len;
3078 pa->pa_free += len;
3079 }
3080 3077
3078 if (pa && pa->pa_type == MB_INODE_PA)
3079 pa->pa_free += ac->ac_b_ex.fe_len;
3081} 3080}
3082 3081
3083/* 3082/*
@@ -4636,6 +4635,7 @@ do_more:
4636 */ 4635 */
4637 new_entry = kmem_cache_alloc(ext4_free_data_cachep, GFP_NOFS); 4636 new_entry = kmem_cache_alloc(ext4_free_data_cachep, GFP_NOFS);
4638 if (!new_entry) { 4637 if (!new_entry) {
4638 ext4_mb_unload_buddy(&e4b);
4639 err = -ENOMEM; 4639 err = -ENOMEM;
4640 goto error_return; 4640 goto error_return;
4641 } 4641 }
@@ -4659,7 +4659,9 @@ do_more:
4659 4659
4660 ret = ext4_free_group_clusters(sb, gdp) + count_clusters; 4660 ret = ext4_free_group_clusters(sb, gdp) + count_clusters;
4661 ext4_free_group_clusters_set(sb, gdp, ret); 4661 ext4_free_group_clusters_set(sb, gdp, ret);
4662 gdp->bg_checksum = ext4_group_desc_csum(sbi, block_group, gdp); 4662 ext4_block_bitmap_csum_set(sb, block_group, gdp, bitmap_bh,
4663 EXT4_BLOCKS_PER_GROUP(sb) / 8);
4664 ext4_group_desc_csum_set(sb, block_group, gdp);
4663 ext4_unlock_group(sb, block_group); 4665 ext4_unlock_group(sb, block_group);
4664 percpu_counter_add(&sbi->s_freeclusters_counter, count_clusters); 4666 percpu_counter_add(&sbi->s_freeclusters_counter, count_clusters);
4665 4667
@@ -4803,7 +4805,9 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
4803 mb_free_blocks(NULL, &e4b, bit, count); 4805 mb_free_blocks(NULL, &e4b, bit, count);
4804 blk_free_count = blocks_freed + ext4_free_group_clusters(sb, desc); 4806 blk_free_count = blocks_freed + ext4_free_group_clusters(sb, desc);
4805 ext4_free_group_clusters_set(sb, desc, blk_free_count); 4807 ext4_free_group_clusters_set(sb, desc, blk_free_count);
4806 desc->bg_checksum = ext4_group_desc_csum(sbi, block_group, desc); 4808 ext4_block_bitmap_csum_set(sb, block_group, desc, bitmap_bh,
4809 EXT4_BLOCKS_PER_GROUP(sb) / 8);
4810 ext4_group_desc_csum_set(sb, block_group, desc);
4807 ext4_unlock_group(sb, block_group); 4811 ext4_unlock_group(sb, block_group);
4808 percpu_counter_add(&sbi->s_freeclusters_counter, 4812 percpu_counter_add(&sbi->s_freeclusters_counter,
4809 EXT4_B2C(sbi, blocks_freed)); 4813 EXT4_B2C(sbi, blocks_freed));
diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
index ed6548d89165..f99a1311e847 100644
--- a/fs/ext4/mmp.c
+++ b/fs/ext4/mmp.c
@@ -6,12 +6,45 @@
6 6
7#include "ext4.h" 7#include "ext4.h"
8 8
9/* Checksumming functions */
10static __u32 ext4_mmp_csum(struct super_block *sb, struct mmp_struct *mmp)
11{
12 struct ext4_sb_info *sbi = EXT4_SB(sb);
13 int offset = offsetof(struct mmp_struct, mmp_checksum);
14 __u32 csum;
15
16 csum = ext4_chksum(sbi, sbi->s_csum_seed, (char *)mmp, offset);
17
18 return cpu_to_le32(csum);
19}
20
21int ext4_mmp_csum_verify(struct super_block *sb, struct mmp_struct *mmp)
22{
23 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
24 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
25 return 1;
26
27 return mmp->mmp_checksum == ext4_mmp_csum(sb, mmp);
28}
29
30void ext4_mmp_csum_set(struct super_block *sb, struct mmp_struct *mmp)
31{
32 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
33 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
34 return;
35
36 mmp->mmp_checksum = ext4_mmp_csum(sb, mmp);
37}
38
9/* 39/*
10 * Write the MMP block using WRITE_SYNC to try to get the block on-disk 40 * Write the MMP block using WRITE_SYNC to try to get the block on-disk
11 * faster. 41 * faster.
12 */ 42 */
13static int write_mmp_block(struct buffer_head *bh) 43static int write_mmp_block(struct super_block *sb, struct buffer_head *bh)
14{ 44{
45 struct mmp_struct *mmp = (struct mmp_struct *)(bh->b_data);
46
47 ext4_mmp_csum_set(sb, mmp);
15 mark_buffer_dirty(bh); 48 mark_buffer_dirty(bh);
16 lock_buffer(bh); 49 lock_buffer(bh);
17 bh->b_end_io = end_buffer_write_sync; 50 bh->b_end_io = end_buffer_write_sync;
@@ -59,7 +92,8 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59 } 92 }
60 93
61 mmp = (struct mmp_struct *)((*bh)->b_data); 94 mmp = (struct mmp_struct *)((*bh)->b_data);
62 if (le32_to_cpu(mmp->mmp_magic) != EXT4_MMP_MAGIC) 95 if (le32_to_cpu(mmp->mmp_magic) != EXT4_MMP_MAGIC ||
96 !ext4_mmp_csum_verify(sb, mmp))
63 return -EINVAL; 97 return -EINVAL;
64 98
65 return 0; 99 return 0;
@@ -120,7 +154,7 @@ static int kmmpd(void *data)
120 mmp->mmp_time = cpu_to_le64(get_seconds()); 154 mmp->mmp_time = cpu_to_le64(get_seconds());
121 last_update_time = jiffies; 155 last_update_time = jiffies;
122 156
123 retval = write_mmp_block(bh); 157 retval = write_mmp_block(sb, bh);
124 /* 158 /*
125 * Don't spew too many error messages. Print one every 159 * Don't spew too many error messages. Print one every
126 * (s_mmp_update_interval * 60) seconds. 160 * (s_mmp_update_interval * 60) seconds.
@@ -200,7 +234,7 @@ static int kmmpd(void *data)
200 mmp->mmp_seq = cpu_to_le32(EXT4_MMP_SEQ_CLEAN); 234 mmp->mmp_seq = cpu_to_le32(EXT4_MMP_SEQ_CLEAN);
201 mmp->mmp_time = cpu_to_le64(get_seconds()); 235 mmp->mmp_time = cpu_to_le64(get_seconds());
202 236
203 retval = write_mmp_block(bh); 237 retval = write_mmp_block(sb, bh);
204 238
205failed: 239failed:
206 kfree(data); 240 kfree(data);
@@ -299,7 +333,7 @@ skip:
299 seq = mmp_new_seq(); 333 seq = mmp_new_seq();
300 mmp->mmp_seq = cpu_to_le32(seq); 334 mmp->mmp_seq = cpu_to_le32(seq);
301 335
302 retval = write_mmp_block(bh); 336 retval = write_mmp_block(sb, bh);
303 if (retval) 337 if (retval)
304 goto failed; 338 goto failed;
305 339
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index e2a3f4b0ff78..5845cd97bf8b 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -145,6 +145,14 @@ struct dx_map_entry
145 u16 size; 145 u16 size;
146}; 146};
147 147
148/*
149 * This goes at the end of each htree block.
150 */
151struct dx_tail {
152 u32 dt_reserved;
153 __le32 dt_checksum; /* crc32c(uuid+inum+dirblock) */
154};
155
148static inline ext4_lblk_t dx_get_block(struct dx_entry *entry); 156static inline ext4_lblk_t dx_get_block(struct dx_entry *entry);
149static void dx_set_block(struct dx_entry *entry, ext4_lblk_t value); 157static void dx_set_block(struct dx_entry *entry, ext4_lblk_t value);
150static inline unsigned dx_get_hash(struct dx_entry *entry); 158static inline unsigned dx_get_hash(struct dx_entry *entry);
@@ -180,6 +188,230 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir,
180static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry, 188static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
181 struct inode *inode); 189 struct inode *inode);
182 190
191/* checksumming functions */
192#define EXT4_DIRENT_TAIL(block, blocksize) \
193 ((struct ext4_dir_entry_tail *)(((void *)(block)) + \
194 ((blocksize) - \
195 sizeof(struct ext4_dir_entry_tail))))
196
197static void initialize_dirent_tail(struct ext4_dir_entry_tail *t,
198 unsigned int blocksize)
199{
200 memset(t, 0, sizeof(struct ext4_dir_entry_tail));
201 t->det_rec_len = ext4_rec_len_to_disk(
202 sizeof(struct ext4_dir_entry_tail), blocksize);
203 t->det_reserved_ft = EXT4_FT_DIR_CSUM;
204}
205
206/* Walk through a dirent block to find a checksum "dirent" at the tail */
207static struct ext4_dir_entry_tail *get_dirent_tail(struct inode *inode,
208 struct ext4_dir_entry *de)
209{
210 struct ext4_dir_entry_tail *t;
211
212#ifdef PARANOID
213 struct ext4_dir_entry *d, *top;
214
215 d = de;
216 top = (struct ext4_dir_entry *)(((void *)de) +
217 (EXT4_BLOCK_SIZE(inode->i_sb) -
218 sizeof(struct ext4_dir_entry_tail)));
219 while (d < top && d->rec_len)
220 d = (struct ext4_dir_entry *)(((void *)d) +
221 le16_to_cpu(d->rec_len));
222
223 if (d != top)
224 return NULL;
225
226 t = (struct ext4_dir_entry_tail *)d;
227#else
228 t = EXT4_DIRENT_TAIL(de, EXT4_BLOCK_SIZE(inode->i_sb));
229#endif
230
231 if (t->det_reserved_zero1 ||
232 le16_to_cpu(t->det_rec_len) != sizeof(struct ext4_dir_entry_tail) ||
233 t->det_reserved_zero2 ||
234 t->det_reserved_ft != EXT4_FT_DIR_CSUM)
235 return NULL;
236
237 return t;
238}
239
240static __le32 ext4_dirent_csum(struct inode *inode,
241 struct ext4_dir_entry *dirent, int size)
242{
243 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
244 struct ext4_inode_info *ei = EXT4_I(inode);
245 __u32 csum;
246
247 csum = ext4_chksum(sbi, ei->i_csum_seed, (__u8 *)dirent, size);
248 return cpu_to_le32(csum);
249}
250
251int ext4_dirent_csum_verify(struct inode *inode, struct ext4_dir_entry *dirent)
252{
253 struct ext4_dir_entry_tail *t;
254
255 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
256 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
257 return 1;
258
259 t = get_dirent_tail(inode, dirent);
260 if (!t) {
261 EXT4_ERROR_INODE(inode, "metadata_csum set but no space in dir "
262 "leaf for checksum. Please run e2fsck -D.");
263 return 0;
264 }
265
266 if (t->det_checksum != ext4_dirent_csum(inode, dirent,
267 (void *)t - (void *)dirent))
268 return 0;
269
270 return 1;
271}
272
273static void ext4_dirent_csum_set(struct inode *inode,
274 struct ext4_dir_entry *dirent)
275{
276 struct ext4_dir_entry_tail *t;
277
278 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
279 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
280 return;
281
282 t = get_dirent_tail(inode, dirent);
283 if (!t) {
284 EXT4_ERROR_INODE(inode, "metadata_csum set but no space in dir "
285 "leaf for checksum. Please run e2fsck -D.");
286 return;
287 }
288
289 t->det_checksum = ext4_dirent_csum(inode, dirent,
290 (void *)t - (void *)dirent);
291}
292
293static inline int ext4_handle_dirty_dirent_node(handle_t *handle,
294 struct inode *inode,
295 struct buffer_head *bh)
296{
297 ext4_dirent_csum_set(inode, (struct ext4_dir_entry *)bh->b_data);
298 return ext4_handle_dirty_metadata(handle, inode, bh);
299}
300
301static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
302 struct ext4_dir_entry *dirent,
303 int *offset)
304{
305 struct ext4_dir_entry *dp;
306 struct dx_root_info *root;
307 int count_offset;
308
309 if (le16_to_cpu(dirent->rec_len) == EXT4_BLOCK_SIZE(inode->i_sb))
310 count_offset = 8;
311 else if (le16_to_cpu(dirent->rec_len) == 12) {
312 dp = (struct ext4_dir_entry *)(((void *)dirent) + 12);
313 if (le16_to_cpu(dp->rec_len) !=
314 EXT4_BLOCK_SIZE(inode->i_sb) - 12)
315 return NULL;
316 root = (struct dx_root_info *)(((void *)dp + 12));
317 if (root->reserved_zero ||
318 root->info_length != sizeof(struct dx_root_info))
319 return NULL;
320 count_offset = 32;
321 } else
322 return NULL;
323
324 if (offset)
325 *offset = count_offset;
326 return (struct dx_countlimit *)(((void *)dirent) + count_offset);
327}
328
329static __le32 ext4_dx_csum(struct inode *inode, struct ext4_dir_entry *dirent,
330 int count_offset, int count, struct dx_tail *t)
331{
332 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
333 struct ext4_inode_info *ei = EXT4_I(inode);
334 __u32 csum, old_csum;
335 int size;
336
337 size = count_offset + (count * sizeof(struct dx_entry));
338 old_csum = t->dt_checksum;
339 t->dt_checksum = 0;
340 csum = ext4_chksum(sbi, ei->i_csum_seed, (__u8 *)dirent, size);
341 csum = ext4_chksum(sbi, csum, (__u8 *)t, sizeof(struct dx_tail));
342 t->dt_checksum = old_csum;
343
344 return cpu_to_le32(csum);
345}
346
347static int ext4_dx_csum_verify(struct inode *inode,
348 struct ext4_dir_entry *dirent)
349{
350 struct dx_countlimit *c;
351 struct dx_tail *t;
352 int count_offset, limit, count;
353
354 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
355 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
356 return 1;
357
358 c = get_dx_countlimit(inode, dirent, &count_offset);
359 if (!c) {
360 EXT4_ERROR_INODE(inode, "dir seems corrupt? Run e2fsck -D.");
361 return 1;
362 }
363 limit = le16_to_cpu(c->limit);
364 count = le16_to_cpu(c->count);
365 if (count_offset + (limit * sizeof(struct dx_entry)) >
366 EXT4_BLOCK_SIZE(inode->i_sb) - sizeof(struct dx_tail)) {
367 EXT4_ERROR_INODE(inode, "metadata_csum set but no space for "
368 "tree checksum found. Run e2fsck -D.");
369 return 1;
370 }
371 t = (struct dx_tail *)(((struct dx_entry *)c) + limit);
372
373 if (t->dt_checksum != ext4_dx_csum(inode, dirent, count_offset,
374 count, t))
375 return 0;
376 return 1;
377}
378
379static void ext4_dx_csum_set(struct inode *inode, struct ext4_dir_entry *dirent)
380{
381 struct dx_countlimit *c;
382 struct dx_tail *t;
383 int count_offset, limit, count;
384
385 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
386 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
387 return;
388
389 c = get_dx_countlimit(inode, dirent, &count_offset);
390 if (!c) {
391 EXT4_ERROR_INODE(inode, "dir seems corrupt? Run e2fsck -D.");
392 return;
393 }
394 limit = le16_to_cpu(c->limit);
395 count = le16_to_cpu(c->count);
396 if (count_offset + (limit * sizeof(struct dx_entry)) >
397 EXT4_BLOCK_SIZE(inode->i_sb) - sizeof(struct dx_tail)) {
398 EXT4_ERROR_INODE(inode, "metadata_csum set but no space for "
399 "tree checksum. Run e2fsck -D.");
400 return;
401 }
402 t = (struct dx_tail *)(((struct dx_entry *)c) + limit);
403
404 t->dt_checksum = ext4_dx_csum(inode, dirent, count_offset, count, t);
405}
406
407static inline int ext4_handle_dirty_dx_node(handle_t *handle,
408 struct inode *inode,
409 struct buffer_head *bh)
410{
411 ext4_dx_csum_set(inode, (struct ext4_dir_entry *)bh->b_data);
412 return ext4_handle_dirty_metadata(handle, inode, bh);
413}
414
183/* 415/*
184 * p is at least 6 bytes before the end of page 416 * p is at least 6 bytes before the end of page
185 */ 417 */
@@ -239,12 +471,20 @@ static inline unsigned dx_root_limit(struct inode *dir, unsigned infosize)
239{ 471{
240 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) - 472 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) -
241 EXT4_DIR_REC_LEN(2) - infosize; 473 EXT4_DIR_REC_LEN(2) - infosize;
474
475 if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb,
476 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
477 entry_space -= sizeof(struct dx_tail);
242 return entry_space / sizeof(struct dx_entry); 478 return entry_space / sizeof(struct dx_entry);
243} 479}
244 480
245static inline unsigned dx_node_limit(struct inode *dir) 481static inline unsigned dx_node_limit(struct inode *dir)
246{ 482{
247 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0); 483 unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0);
484
485 if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb,
486 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
487 entry_space -= sizeof(struct dx_tail);
248 return entry_space / sizeof(struct dx_entry); 488 return entry_space / sizeof(struct dx_entry);
249} 489}
250 490
@@ -390,6 +630,15 @@ dx_probe(const struct qstr *d_name, struct inode *dir,
390 goto fail; 630 goto fail;
391 } 631 }
392 632
633 if (!buffer_verified(bh) &&
634 !ext4_dx_csum_verify(dir, (struct ext4_dir_entry *)bh->b_data)) {
635 ext4_warning(dir->i_sb, "Root failed checksum");
636 brelse(bh);
637 *err = ERR_BAD_DX_DIR;
638 goto fail;
639 }
640 set_buffer_verified(bh);
641
393 entries = (struct dx_entry *) (((char *)&root->info) + 642 entries = (struct dx_entry *) (((char *)&root->info) +
394 root->info.info_length); 643 root->info.info_length);
395 644
@@ -450,6 +699,17 @@ dx_probe(const struct qstr *d_name, struct inode *dir,
450 if (!(bh = ext4_bread (NULL,dir, dx_get_block(at), 0, err))) 699 if (!(bh = ext4_bread (NULL,dir, dx_get_block(at), 0, err)))
451 goto fail2; 700 goto fail2;
452 at = entries = ((struct dx_node *) bh->b_data)->entries; 701 at = entries = ((struct dx_node *) bh->b_data)->entries;
702
703 if (!buffer_verified(bh) &&
704 !ext4_dx_csum_verify(dir,
705 (struct ext4_dir_entry *)bh->b_data)) {
706 ext4_warning(dir->i_sb, "Node failed checksum");
707 brelse(bh);
708 *err = ERR_BAD_DX_DIR;
709 goto fail;
710 }
711 set_buffer_verified(bh);
712
453 if (dx_get_limit(entries) != dx_node_limit (dir)) { 713 if (dx_get_limit(entries) != dx_node_limit (dir)) {
454 ext4_warning(dir->i_sb, 714 ext4_warning(dir->i_sb,
455 "dx entry: limit != node limit"); 715 "dx entry: limit != node limit");
@@ -549,6 +809,15 @@ static int ext4_htree_next_block(struct inode *dir, __u32 hash,
549 if (!(bh = ext4_bread(NULL, dir, dx_get_block(p->at), 809 if (!(bh = ext4_bread(NULL, dir, dx_get_block(p->at),
550 0, &err))) 810 0, &err)))
551 return err; /* Failure */ 811 return err; /* Failure */
812
813 if (!buffer_verified(bh) &&
814 !ext4_dx_csum_verify(dir,
815 (struct ext4_dir_entry *)bh->b_data)) {
816 ext4_warning(dir->i_sb, "Node failed checksum");
817 return -EIO;
818 }
819 set_buffer_verified(bh);
820
552 p++; 821 p++;
553 brelse(p->bh); 822 brelse(p->bh);
554 p->bh = bh; 823 p->bh = bh;
@@ -577,6 +846,11 @@ static int htree_dirblock_to_tree(struct file *dir_file,
577 if (!(bh = ext4_bread (NULL, dir, block, 0, &err))) 846 if (!(bh = ext4_bread (NULL, dir, block, 0, &err)))
578 return err; 847 return err;
579 848
849 if (!buffer_verified(bh) &&
850 !ext4_dirent_csum_verify(dir, (struct ext4_dir_entry *)bh->b_data))
851 return -EIO;
852 set_buffer_verified(bh);
853
580 de = (struct ext4_dir_entry_2 *) bh->b_data; 854 de = (struct ext4_dir_entry_2 *) bh->b_data;
581 top = (struct ext4_dir_entry_2 *) ((char *) de + 855 top = (struct ext4_dir_entry_2 *) ((char *) de +
582 dir->i_sb->s_blocksize - 856 dir->i_sb->s_blocksize -
@@ -936,6 +1210,15 @@ restart:
936 brelse(bh); 1210 brelse(bh);
937 goto next; 1211 goto next;
938 } 1212 }
1213 if (!buffer_verified(bh) &&
1214 !ext4_dirent_csum_verify(dir,
1215 (struct ext4_dir_entry *)bh->b_data)) {
1216 EXT4_ERROR_INODE(dir, "checksumming directory "
1217 "block %lu", (unsigned long)block);
1218 brelse(bh);
1219 goto next;
1220 }
1221 set_buffer_verified(bh);
939 i = search_dirblock(bh, dir, d_name, 1222 i = search_dirblock(bh, dir, d_name,
940 block << EXT4_BLOCK_SIZE_BITS(sb), res_dir); 1223 block << EXT4_BLOCK_SIZE_BITS(sb), res_dir);
941 if (i == 1) { 1224 if (i == 1) {
@@ -987,6 +1270,16 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir, const struct q
987 if (!(bh = ext4_bread(NULL, dir, block, 0, err))) 1270 if (!(bh = ext4_bread(NULL, dir, block, 0, err)))
988 goto errout; 1271 goto errout;
989 1272
1273 if (!buffer_verified(bh) &&
1274 !ext4_dirent_csum_verify(dir,
1275 (struct ext4_dir_entry *)bh->b_data)) {
1276 EXT4_ERROR_INODE(dir, "checksumming directory "
1277 "block %lu", (unsigned long)block);
1278 brelse(bh);
1279 *err = -EIO;
1280 goto errout;
1281 }
1282 set_buffer_verified(bh);
990 retval = search_dirblock(bh, dir, d_name, 1283 retval = search_dirblock(bh, dir, d_name,
991 block << EXT4_BLOCK_SIZE_BITS(sb), 1284 block << EXT4_BLOCK_SIZE_BITS(sb),
992 res_dir); 1285 res_dir);
@@ -1037,6 +1330,12 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, stru
1037 EXT4_ERROR_INODE(dir, "bad inode number: %u", ino); 1330 EXT4_ERROR_INODE(dir, "bad inode number: %u", ino);
1038 return ERR_PTR(-EIO); 1331 return ERR_PTR(-EIO);
1039 } 1332 }
1333 if (unlikely(ino == dir->i_ino)) {
1334 EXT4_ERROR_INODE(dir, "'%.*s' linked to parent dir",
1335 dentry->d_name.len,
1336 dentry->d_name.name);
1337 return ERR_PTR(-EIO);
1338 }
1040 inode = ext4_iget(dir->i_sb, ino); 1339 inode = ext4_iget(dir->i_sb, ino);
1041 if (inode == ERR_PTR(-ESTALE)) { 1340 if (inode == ERR_PTR(-ESTALE)) {
1042 EXT4_ERROR_INODE(dir, 1341 EXT4_ERROR_INODE(dir,
@@ -1156,8 +1455,14 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1156 char *data1 = (*bh)->b_data, *data2; 1455 char *data1 = (*bh)->b_data, *data2;
1157 unsigned split, move, size; 1456 unsigned split, move, size;
1158 struct ext4_dir_entry_2 *de = NULL, *de2; 1457 struct ext4_dir_entry_2 *de = NULL, *de2;
1458 struct ext4_dir_entry_tail *t;
1459 int csum_size = 0;
1159 int err = 0, i; 1460 int err = 0, i;
1160 1461
1462 if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb,
1463 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
1464 csum_size = sizeof(struct ext4_dir_entry_tail);
1465
1161 bh2 = ext4_append (handle, dir, &newblock, &err); 1466 bh2 = ext4_append (handle, dir, &newblock, &err);
1162 if (!(bh2)) { 1467 if (!(bh2)) {
1163 brelse(*bh); 1468 brelse(*bh);
@@ -1204,10 +1509,20 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1204 /* Fancy dance to stay within two buffers */ 1509 /* Fancy dance to stay within two buffers */
1205 de2 = dx_move_dirents(data1, data2, map + split, count - split, blocksize); 1510 de2 = dx_move_dirents(data1, data2, map + split, count - split, blocksize);
1206 de = dx_pack_dirents(data1, blocksize); 1511 de = dx_pack_dirents(data1, blocksize);
1207 de->rec_len = ext4_rec_len_to_disk(data1 + blocksize - (char *) de, 1512 de->rec_len = ext4_rec_len_to_disk(data1 + (blocksize - csum_size) -
1513 (char *) de,
1208 blocksize); 1514 blocksize);
1209 de2->rec_len = ext4_rec_len_to_disk(data2 + blocksize - (char *) de2, 1515 de2->rec_len = ext4_rec_len_to_disk(data2 + (blocksize - csum_size) -
1516 (char *) de2,
1210 blocksize); 1517 blocksize);
1518 if (csum_size) {
1519 t = EXT4_DIRENT_TAIL(data2, blocksize);
1520 initialize_dirent_tail(t, blocksize);
1521
1522 t = EXT4_DIRENT_TAIL(data1, blocksize);
1523 initialize_dirent_tail(t, blocksize);
1524 }
1525
1211 dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data1, blocksize, 1)); 1526 dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data1, blocksize, 1));
1212 dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data2, blocksize, 1)); 1527 dxtrace(dx_show_leaf (hinfo, (struct ext4_dir_entry_2 *) data2, blocksize, 1));
1213 1528
@@ -1218,10 +1533,10 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1218 de = de2; 1533 de = de2;
1219 } 1534 }
1220 dx_insert_block(frame, hash2 + continued, newblock); 1535 dx_insert_block(frame, hash2 + continued, newblock);
1221 err = ext4_handle_dirty_metadata(handle, dir, bh2); 1536 err = ext4_handle_dirty_dirent_node(handle, dir, bh2);
1222 if (err) 1537 if (err)
1223 goto journal_error; 1538 goto journal_error;
1224 err = ext4_handle_dirty_metadata(handle, dir, frame->bh); 1539 err = ext4_handle_dirty_dx_node(handle, dir, frame->bh);
1225 if (err) 1540 if (err)
1226 goto journal_error; 1541 goto journal_error;
1227 brelse(bh2); 1542 brelse(bh2);
@@ -1258,11 +1573,16 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1258 unsigned short reclen; 1573 unsigned short reclen;
1259 int nlen, rlen, err; 1574 int nlen, rlen, err;
1260 char *top; 1575 char *top;
1576 int csum_size = 0;
1577
1578 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
1579 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
1580 csum_size = sizeof(struct ext4_dir_entry_tail);
1261 1581
1262 reclen = EXT4_DIR_REC_LEN(namelen); 1582 reclen = EXT4_DIR_REC_LEN(namelen);
1263 if (!de) { 1583 if (!de) {
1264 de = (struct ext4_dir_entry_2 *)bh->b_data; 1584 de = (struct ext4_dir_entry_2 *)bh->b_data;
1265 top = bh->b_data + blocksize - reclen; 1585 top = bh->b_data + (blocksize - csum_size) - reclen;
1266 while ((char *) de <= top) { 1586 while ((char *) de <= top) {
1267 if (ext4_check_dir_entry(dir, NULL, de, bh, offset)) 1587 if (ext4_check_dir_entry(dir, NULL, de, bh, offset))
1268 return -EIO; 1588 return -EIO;
@@ -1295,11 +1615,8 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1295 de = de1; 1615 de = de1;
1296 } 1616 }
1297 de->file_type = EXT4_FT_UNKNOWN; 1617 de->file_type = EXT4_FT_UNKNOWN;
1298 if (inode) { 1618 de->inode = cpu_to_le32(inode->i_ino);
1299 de->inode = cpu_to_le32(inode->i_ino); 1619 ext4_set_de_type(dir->i_sb, de, inode->i_mode);
1300 ext4_set_de_type(dir->i_sb, de, inode->i_mode);
1301 } else
1302 de->inode = 0;
1303 de->name_len = namelen; 1620 de->name_len = namelen;
1304 memcpy(de->name, name, namelen); 1621 memcpy(de->name, name, namelen);
1305 /* 1622 /*
@@ -1318,7 +1635,7 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1318 dir->i_version++; 1635 dir->i_version++;
1319 ext4_mark_inode_dirty(handle, dir); 1636 ext4_mark_inode_dirty(handle, dir);
1320 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); 1637 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
1321 err = ext4_handle_dirty_metadata(handle, dir, bh); 1638 err = ext4_handle_dirty_dirent_node(handle, dir, bh);
1322 if (err) 1639 if (err)
1323 ext4_std_error(dir->i_sb, err); 1640 ext4_std_error(dir->i_sb, err);
1324 return 0; 1641 return 0;
@@ -1339,6 +1656,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1339 struct dx_frame frames[2], *frame; 1656 struct dx_frame frames[2], *frame;
1340 struct dx_entry *entries; 1657 struct dx_entry *entries;
1341 struct ext4_dir_entry_2 *de, *de2; 1658 struct ext4_dir_entry_2 *de, *de2;
1659 struct ext4_dir_entry_tail *t;
1342 char *data1, *top; 1660 char *data1, *top;
1343 unsigned len; 1661 unsigned len;
1344 int retval; 1662 int retval;
@@ -1346,6 +1664,11 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1346 struct dx_hash_info hinfo; 1664 struct dx_hash_info hinfo;
1347 ext4_lblk_t block; 1665 ext4_lblk_t block;
1348 struct fake_dirent *fde; 1666 struct fake_dirent *fde;
1667 int csum_size = 0;
1668
1669 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
1670 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
1671 csum_size = sizeof(struct ext4_dir_entry_tail);
1349 1672
1350 blocksize = dir->i_sb->s_blocksize; 1673 blocksize = dir->i_sb->s_blocksize;
1351 dxtrace(printk(KERN_DEBUG "Creating index: inode %lu\n", dir->i_ino)); 1674 dxtrace(printk(KERN_DEBUG "Creating index: inode %lu\n", dir->i_ino));
@@ -1366,7 +1689,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1366 brelse(bh); 1689 brelse(bh);
1367 return -EIO; 1690 return -EIO;
1368 } 1691 }
1369 len = ((char *) root) + blocksize - (char *) de; 1692 len = ((char *) root) + (blocksize - csum_size) - (char *) de;
1370 1693
1371 /* Allocate new block for the 0th block's dirents */ 1694 /* Allocate new block for the 0th block's dirents */
1372 bh2 = ext4_append(handle, dir, &block, &retval); 1695 bh2 = ext4_append(handle, dir, &block, &retval);
@@ -1382,8 +1705,15 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1382 top = data1 + len; 1705 top = data1 + len;
1383 while ((char *)(de2 = ext4_next_entry(de, blocksize)) < top) 1706 while ((char *)(de2 = ext4_next_entry(de, blocksize)) < top)
1384 de = de2; 1707 de = de2;
1385 de->rec_len = ext4_rec_len_to_disk(data1 + blocksize - (char *) de, 1708 de->rec_len = ext4_rec_len_to_disk(data1 + (blocksize - csum_size) -
1709 (char *) de,
1386 blocksize); 1710 blocksize);
1711
1712 if (csum_size) {
1713 t = EXT4_DIRENT_TAIL(data1, blocksize);
1714 initialize_dirent_tail(t, blocksize);
1715 }
1716
1387 /* Initialize the root; the dot dirents already exist */ 1717 /* Initialize the root; the dot dirents already exist */
1388 de = (struct ext4_dir_entry_2 *) (&root->dotdot); 1718 de = (struct ext4_dir_entry_2 *) (&root->dotdot);
1389 de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(2), 1719 de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(2),
@@ -1408,8 +1738,8 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1408 frame->bh = bh; 1738 frame->bh = bh;
1409 bh = bh2; 1739 bh = bh2;
1410 1740
1411 ext4_handle_dirty_metadata(handle, dir, frame->bh); 1741 ext4_handle_dirty_dx_node(handle, dir, frame->bh);
1412 ext4_handle_dirty_metadata(handle, dir, bh); 1742 ext4_handle_dirty_dirent_node(handle, dir, bh);
1413 1743
1414 de = do_split(handle,dir, &bh, frame, &hinfo, &retval); 1744 de = do_split(handle,dir, &bh, frame, &hinfo, &retval);
1415 if (!de) { 1745 if (!de) {
@@ -1445,11 +1775,17 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
1445 struct inode *dir = dentry->d_parent->d_inode; 1775 struct inode *dir = dentry->d_parent->d_inode;
1446 struct buffer_head *bh; 1776 struct buffer_head *bh;
1447 struct ext4_dir_entry_2 *de; 1777 struct ext4_dir_entry_2 *de;
1778 struct ext4_dir_entry_tail *t;
1448 struct super_block *sb; 1779 struct super_block *sb;
1449 int retval; 1780 int retval;
1450 int dx_fallback=0; 1781 int dx_fallback=0;
1451 unsigned blocksize; 1782 unsigned blocksize;
1452 ext4_lblk_t block, blocks; 1783 ext4_lblk_t block, blocks;
1784 int csum_size = 0;
1785
1786 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
1787 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
1788 csum_size = sizeof(struct ext4_dir_entry_tail);
1453 1789
1454 sb = dir->i_sb; 1790 sb = dir->i_sb;
1455 blocksize = sb->s_blocksize; 1791 blocksize = sb->s_blocksize;
@@ -1468,6 +1804,11 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
1468 bh = ext4_bread(handle, dir, block, 0, &retval); 1804 bh = ext4_bread(handle, dir, block, 0, &retval);
1469 if(!bh) 1805 if(!bh)
1470 return retval; 1806 return retval;
1807 if (!buffer_verified(bh) &&
1808 !ext4_dirent_csum_verify(dir,
1809 (struct ext4_dir_entry *)bh->b_data))
1810 return -EIO;
1811 set_buffer_verified(bh);
1471 retval = add_dirent_to_buf(handle, dentry, inode, NULL, bh); 1812 retval = add_dirent_to_buf(handle, dentry, inode, NULL, bh);
1472 if (retval != -ENOSPC) { 1813 if (retval != -ENOSPC) {
1473 brelse(bh); 1814 brelse(bh);
@@ -1484,7 +1825,13 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
1484 return retval; 1825 return retval;
1485 de = (struct ext4_dir_entry_2 *) bh->b_data; 1826 de = (struct ext4_dir_entry_2 *) bh->b_data;
1486 de->inode = 0; 1827 de->inode = 0;
1487 de->rec_len = ext4_rec_len_to_disk(blocksize, blocksize); 1828 de->rec_len = ext4_rec_len_to_disk(blocksize - csum_size, blocksize);
1829
1830 if (csum_size) {
1831 t = EXT4_DIRENT_TAIL(bh->b_data, blocksize);
1832 initialize_dirent_tail(t, blocksize);
1833 }
1834
1488 retval = add_dirent_to_buf(handle, dentry, inode, de, bh); 1835 retval = add_dirent_to_buf(handle, dentry, inode, de, bh);
1489 brelse(bh); 1836 brelse(bh);
1490 if (retval == 0) 1837 if (retval == 0)
@@ -1516,6 +1863,11 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
1516 if (!(bh = ext4_bread(handle,dir, dx_get_block(frame->at), 0, &err))) 1863 if (!(bh = ext4_bread(handle,dir, dx_get_block(frame->at), 0, &err)))
1517 goto cleanup; 1864 goto cleanup;
1518 1865
1866 if (!buffer_verified(bh) &&
1867 !ext4_dirent_csum_verify(dir, (struct ext4_dir_entry *)bh->b_data))
1868 goto journal_error;
1869 set_buffer_verified(bh);
1870
1519 BUFFER_TRACE(bh, "get_write_access"); 1871 BUFFER_TRACE(bh, "get_write_access");
1520 err = ext4_journal_get_write_access(handle, bh); 1872 err = ext4_journal_get_write_access(handle, bh);
1521 if (err) 1873 if (err)
@@ -1583,7 +1935,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
1583 dxtrace(dx_show_index("node", frames[1].entries)); 1935 dxtrace(dx_show_index("node", frames[1].entries));
1584 dxtrace(dx_show_index("node", 1936 dxtrace(dx_show_index("node",
1585 ((struct dx_node *) bh2->b_data)->entries)); 1937 ((struct dx_node *) bh2->b_data)->entries));
1586 err = ext4_handle_dirty_metadata(handle, dir, bh2); 1938 err = ext4_handle_dirty_dx_node(handle, dir, bh2);
1587 if (err) 1939 if (err)
1588 goto journal_error; 1940 goto journal_error;
1589 brelse (bh2); 1941 brelse (bh2);
@@ -1609,7 +1961,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
1609 if (err) 1961 if (err)
1610 goto journal_error; 1962 goto journal_error;
1611 } 1963 }
1612 err = ext4_handle_dirty_metadata(handle, dir, frames[0].bh); 1964 err = ext4_handle_dirty_dx_node(handle, dir, frames[0].bh);
1613 if (err) { 1965 if (err) {
1614 ext4_std_error(inode->i_sb, err); 1966 ext4_std_error(inode->i_sb, err);
1615 goto cleanup; 1967 goto cleanup;
@@ -1641,12 +1993,17 @@ static int ext4_delete_entry(handle_t *handle,
1641{ 1993{
1642 struct ext4_dir_entry_2 *de, *pde; 1994 struct ext4_dir_entry_2 *de, *pde;
1643 unsigned int blocksize = dir->i_sb->s_blocksize; 1995 unsigned int blocksize = dir->i_sb->s_blocksize;
1996 int csum_size = 0;
1644 int i, err; 1997 int i, err;
1645 1998
1999 if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb,
2000 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
2001 csum_size = sizeof(struct ext4_dir_entry_tail);
2002
1646 i = 0; 2003 i = 0;
1647 pde = NULL; 2004 pde = NULL;
1648 de = (struct ext4_dir_entry_2 *) bh->b_data; 2005 de = (struct ext4_dir_entry_2 *) bh->b_data;
1649 while (i < bh->b_size) { 2006 while (i < bh->b_size - csum_size) {
1650 if (ext4_check_dir_entry(dir, NULL, de, bh, i)) 2007 if (ext4_check_dir_entry(dir, NULL, de, bh, i))
1651 return -EIO; 2008 return -EIO;
1652 if (de == de_del) { 2009 if (de == de_del) {
@@ -1667,7 +2024,7 @@ static int ext4_delete_entry(handle_t *handle,
1667 de->inode = 0; 2024 de->inode = 0;
1668 dir->i_version++; 2025 dir->i_version++;
1669 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); 2026 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
1670 err = ext4_handle_dirty_metadata(handle, dir, bh); 2027 err = ext4_handle_dirty_dirent_node(handle, dir, bh);
1671 if (unlikely(err)) { 2028 if (unlikely(err)) {
1672 ext4_std_error(dir->i_sb, err); 2029 ext4_std_error(dir->i_sb, err);
1673 return err; 2030 return err;
@@ -1809,9 +2166,15 @@ static int ext4_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
1809 struct inode *inode; 2166 struct inode *inode;
1810 struct buffer_head *dir_block = NULL; 2167 struct buffer_head *dir_block = NULL;
1811 struct ext4_dir_entry_2 *de; 2168 struct ext4_dir_entry_2 *de;
2169 struct ext4_dir_entry_tail *t;
1812 unsigned int blocksize = dir->i_sb->s_blocksize; 2170 unsigned int blocksize = dir->i_sb->s_blocksize;
2171 int csum_size = 0;
1813 int err, retries = 0; 2172 int err, retries = 0;
1814 2173
2174 if (EXT4_HAS_RO_COMPAT_FEATURE(dir->i_sb,
2175 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
2176 csum_size = sizeof(struct ext4_dir_entry_tail);
2177
1815 if (EXT4_DIR_LINK_MAX(dir)) 2178 if (EXT4_DIR_LINK_MAX(dir))
1816 return -EMLINK; 2179 return -EMLINK;
1817 2180
@@ -1852,16 +2215,24 @@ retry:
1852 ext4_set_de_type(dir->i_sb, de, S_IFDIR); 2215 ext4_set_de_type(dir->i_sb, de, S_IFDIR);
1853 de = ext4_next_entry(de, blocksize); 2216 de = ext4_next_entry(de, blocksize);
1854 de->inode = cpu_to_le32(dir->i_ino); 2217 de->inode = cpu_to_le32(dir->i_ino);
1855 de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(1), 2218 de->rec_len = ext4_rec_len_to_disk(blocksize -
2219 (csum_size + EXT4_DIR_REC_LEN(1)),
1856 blocksize); 2220 blocksize);
1857 de->name_len = 2; 2221 de->name_len = 2;
1858 strcpy(de->name, ".."); 2222 strcpy(de->name, "..");
1859 ext4_set_de_type(dir->i_sb, de, S_IFDIR); 2223 ext4_set_de_type(dir->i_sb, de, S_IFDIR);
1860 set_nlink(inode, 2); 2224 set_nlink(inode, 2);
2225
2226 if (csum_size) {
2227 t = EXT4_DIRENT_TAIL(dir_block->b_data, blocksize);
2228 initialize_dirent_tail(t, blocksize);
2229 }
2230
1861 BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata"); 2231 BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
1862 err = ext4_handle_dirty_metadata(handle, inode, dir_block); 2232 err = ext4_handle_dirty_dirent_node(handle, inode, dir_block);
1863 if (err) 2233 if (err)
1864 goto out_clear_inode; 2234 goto out_clear_inode;
2235 set_buffer_verified(dir_block);
1865 err = ext4_mark_inode_dirty(handle, inode); 2236 err = ext4_mark_inode_dirty(handle, inode);
1866 if (!err) 2237 if (!err)
1867 err = ext4_add_entry(handle, dentry, inode); 2238 err = ext4_add_entry(handle, dentry, inode);
@@ -1911,6 +2282,14 @@ static int empty_dir(struct inode *inode)
1911 inode->i_ino); 2282 inode->i_ino);
1912 return 1; 2283 return 1;
1913 } 2284 }
2285 if (!buffer_verified(bh) &&
2286 !ext4_dirent_csum_verify(inode,
2287 (struct ext4_dir_entry *)bh->b_data)) {
2288 EXT4_ERROR_INODE(inode, "checksum error reading directory "
2289 "lblock 0");
2290 return -EIO;
2291 }
2292 set_buffer_verified(bh);
1914 de = (struct ext4_dir_entry_2 *) bh->b_data; 2293 de = (struct ext4_dir_entry_2 *) bh->b_data;
1915 de1 = ext4_next_entry(de, sb->s_blocksize); 2294 de1 = ext4_next_entry(de, sb->s_blocksize);
1916 if (le32_to_cpu(de->inode) != inode->i_ino || 2295 if (le32_to_cpu(de->inode) != inode->i_ino ||
@@ -1942,6 +2321,14 @@ static int empty_dir(struct inode *inode)
1942 offset += sb->s_blocksize; 2321 offset += sb->s_blocksize;
1943 continue; 2322 continue;
1944 } 2323 }
2324 if (!buffer_verified(bh) &&
2325 !ext4_dirent_csum_verify(inode,
2326 (struct ext4_dir_entry *)bh->b_data)) {
2327 EXT4_ERROR_INODE(inode, "checksum error "
2328 "reading directory lblock 0");
2329 return -EIO;
2330 }
2331 set_buffer_verified(bh);
1945 de = (struct ext4_dir_entry_2 *) bh->b_data; 2332 de = (struct ext4_dir_entry_2 *) bh->b_data;
1946 } 2333 }
1947 if (ext4_check_dir_entry(inode, NULL, de, bh, offset)) { 2334 if (ext4_check_dir_entry(inode, NULL, de, bh, offset)) {
@@ -2010,7 +2397,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
2010 /* Insert this inode at the head of the on-disk orphan list... */ 2397 /* Insert this inode at the head of the on-disk orphan list... */
2011 NEXT_ORPHAN(inode) = le32_to_cpu(EXT4_SB(sb)->s_es->s_last_orphan); 2398 NEXT_ORPHAN(inode) = le32_to_cpu(EXT4_SB(sb)->s_es->s_last_orphan);
2012 EXT4_SB(sb)->s_es->s_last_orphan = cpu_to_le32(inode->i_ino); 2399 EXT4_SB(sb)->s_es->s_last_orphan = cpu_to_le32(inode->i_ino);
2013 err = ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh); 2400 err = ext4_handle_dirty_super_now(handle, sb);
2014 rc = ext4_mark_iloc_dirty(handle, inode, &iloc); 2401 rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
2015 if (!err) 2402 if (!err)
2016 err = rc; 2403 err = rc;
@@ -2083,7 +2470,7 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)
2083 if (err) 2470 if (err)
2084 goto out_brelse; 2471 goto out_brelse;
2085 sbi->s_es->s_last_orphan = cpu_to_le32(ino_next); 2472 sbi->s_es->s_last_orphan = cpu_to_le32(ino_next);
2086 err = ext4_handle_dirty_metadata(handle, NULL, sbi->s_sbh); 2473 err = ext4_handle_dirty_super_now(handle, inode->i_sb);
2087 } else { 2474 } else {
2088 struct ext4_iloc iloc2; 2475 struct ext4_iloc iloc2;
2089 struct inode *i_prev = 2476 struct inode *i_prev =
@@ -2442,6 +2829,11 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
2442 dir_bh = ext4_bread(handle, old_inode, 0, 0, &retval); 2829 dir_bh = ext4_bread(handle, old_inode, 0, 0, &retval);
2443 if (!dir_bh) 2830 if (!dir_bh)
2444 goto end_rename; 2831 goto end_rename;
2832 if (!buffer_verified(dir_bh) &&
2833 !ext4_dirent_csum_verify(old_inode,
2834 (struct ext4_dir_entry *)dir_bh->b_data))
2835 goto end_rename;
2836 set_buffer_verified(dir_bh);
2445 if (le32_to_cpu(PARENT_INO(dir_bh->b_data, 2837 if (le32_to_cpu(PARENT_INO(dir_bh->b_data,
2446 old_dir->i_sb->s_blocksize)) != old_dir->i_ino) 2838 old_dir->i_sb->s_blocksize)) != old_dir->i_ino)
2447 goto end_rename; 2839 goto end_rename;
@@ -2472,7 +2864,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
2472 ext4_current_time(new_dir); 2864 ext4_current_time(new_dir);
2473 ext4_mark_inode_dirty(handle, new_dir); 2865 ext4_mark_inode_dirty(handle, new_dir);
2474 BUFFER_TRACE(new_bh, "call ext4_handle_dirty_metadata"); 2866 BUFFER_TRACE(new_bh, "call ext4_handle_dirty_metadata");
2475 retval = ext4_handle_dirty_metadata(handle, new_dir, new_bh); 2867 retval = ext4_handle_dirty_dirent_node(handle, new_dir, new_bh);
2476 if (unlikely(retval)) { 2868 if (unlikely(retval)) {
2477 ext4_std_error(new_dir->i_sb, retval); 2869 ext4_std_error(new_dir->i_sb, retval);
2478 goto end_rename; 2870 goto end_rename;
@@ -2526,7 +2918,8 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
2526 PARENT_INO(dir_bh->b_data, new_dir->i_sb->s_blocksize) = 2918 PARENT_INO(dir_bh->b_data, new_dir->i_sb->s_blocksize) =
2527 cpu_to_le32(new_dir->i_ino); 2919 cpu_to_le32(new_dir->i_ino);
2528 BUFFER_TRACE(dir_bh, "call ext4_handle_dirty_metadata"); 2920 BUFFER_TRACE(dir_bh, "call ext4_handle_dirty_metadata");
2529 retval = ext4_handle_dirty_metadata(handle, old_inode, dir_bh); 2921 retval = ext4_handle_dirty_dirent_node(handle, old_inode,
2922 dir_bh);
2530 if (retval) { 2923 if (retval) {
2531 ext4_std_error(old_dir->i_sb, retval); 2924 ext4_std_error(old_dir->i_sb, retval);
2532 goto end_rename; 2925 goto end_rename;
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 59fa0be27251..7ea6cbb44121 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -161,6 +161,8 @@ static struct ext4_new_flex_group_data *alloc_flex_gd(unsigned long flexbg_size)
161 if (flex_gd == NULL) 161 if (flex_gd == NULL)
162 goto out3; 162 goto out3;
163 163
164 if (flexbg_size >= UINT_MAX / sizeof(struct ext4_new_flex_group_data))
165 goto out2;
164 flex_gd->count = flexbg_size; 166 flex_gd->count = flexbg_size;
165 167
166 flex_gd->groups = kmalloc(sizeof(struct ext4_new_group_data) * 168 flex_gd->groups = kmalloc(sizeof(struct ext4_new_group_data) *
@@ -796,7 +798,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
796 ext4_kvfree(o_group_desc); 798 ext4_kvfree(o_group_desc);
797 799
798 le16_add_cpu(&es->s_reserved_gdt_blocks, -1); 800 le16_add_cpu(&es->s_reserved_gdt_blocks, -1);
799 err = ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh); 801 err = ext4_handle_dirty_super_now(handle, sb);
800 if (err) 802 if (err)
801 ext4_std_error(sb, err); 803 ext4_std_error(sb, err);
802 804
@@ -968,6 +970,8 @@ static void update_backups(struct super_block *sb,
968 goto exit_err; 970 goto exit_err;
969 } 971 }
970 972
973 ext4_superblock_csum_set(sb, (struct ext4_super_block *)data);
974
971 while ((group = ext4_list_backups(sb, &three, &five, &seven)) < last) { 975 while ((group = ext4_list_backups(sb, &three, &five, &seven)) < last) {
972 struct buffer_head *bh; 976 struct buffer_head *bh;
973 977
@@ -1067,6 +1071,54 @@ static int ext4_add_new_descs(handle_t *handle, struct super_block *sb,
1067 return err; 1071 return err;
1068} 1072}
1069 1073
1074static struct buffer_head *ext4_get_bitmap(struct super_block *sb, __u64 block)
1075{
1076 struct buffer_head *bh = sb_getblk(sb, block);
1077 if (!bh)
1078 return NULL;
1079
1080 if (bitmap_uptodate(bh))
1081 return bh;
1082
1083 lock_buffer(bh);
1084 if (bh_submit_read(bh) < 0) {
1085 unlock_buffer(bh);
1086 brelse(bh);
1087 return NULL;
1088 }
1089 unlock_buffer(bh);
1090
1091 return bh;
1092}
1093
1094static int ext4_set_bitmap_checksums(struct super_block *sb,
1095 ext4_group_t group,
1096 struct ext4_group_desc *gdp,
1097 struct ext4_new_group_data *group_data)
1098{
1099 struct buffer_head *bh;
1100
1101 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
1102 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
1103 return 0;
1104
1105 bh = ext4_get_bitmap(sb, group_data->inode_bitmap);
1106 if (!bh)
1107 return -EIO;
1108 ext4_inode_bitmap_csum_set(sb, group, gdp, bh,
1109 EXT4_INODES_PER_GROUP(sb) / 8);
1110 brelse(bh);
1111
1112 bh = ext4_get_bitmap(sb, group_data->block_bitmap);
1113 if (!bh)
1114 return -EIO;
1115 ext4_block_bitmap_csum_set(sb, group, gdp, bh,
1116 EXT4_BLOCKS_PER_GROUP(sb) / 8);
1117 brelse(bh);
1118
1119 return 0;
1120}
1121
1070/* 1122/*
1071 * ext4_setup_new_descs() will set up the group descriptor descriptors of a flex bg 1123 * ext4_setup_new_descs() will set up the group descriptor descriptors of a flex bg
1072 */ 1124 */
@@ -1093,18 +1145,24 @@ static int ext4_setup_new_descs(handle_t *handle, struct super_block *sb,
1093 */ 1145 */
1094 gdb_bh = sbi->s_group_desc[gdb_num]; 1146 gdb_bh = sbi->s_group_desc[gdb_num];
1095 /* Update group descriptor block for new group */ 1147 /* Update group descriptor block for new group */
1096 gdp = (struct ext4_group_desc *)((char *)gdb_bh->b_data + 1148 gdp = (struct ext4_group_desc *)(gdb_bh->b_data +
1097 gdb_off * EXT4_DESC_SIZE(sb)); 1149 gdb_off * EXT4_DESC_SIZE(sb));
1098 1150
1099 memset(gdp, 0, EXT4_DESC_SIZE(sb)); 1151 memset(gdp, 0, EXT4_DESC_SIZE(sb));
1100 ext4_block_bitmap_set(sb, gdp, group_data->block_bitmap); 1152 ext4_block_bitmap_set(sb, gdp, group_data->block_bitmap);
1101 ext4_inode_bitmap_set(sb, gdp, group_data->inode_bitmap); 1153 ext4_inode_bitmap_set(sb, gdp, group_data->inode_bitmap);
1154 err = ext4_set_bitmap_checksums(sb, group, gdp, group_data);
1155 if (err) {
1156 ext4_std_error(sb, err);
1157 break;
1158 }
1159
1102 ext4_inode_table_set(sb, gdp, group_data->inode_table); 1160 ext4_inode_table_set(sb, gdp, group_data->inode_table);
1103 ext4_free_group_clusters_set(sb, gdp, 1161 ext4_free_group_clusters_set(sb, gdp,
1104 EXT4_B2C(sbi, group_data->free_blocks_count)); 1162 EXT4_B2C(sbi, group_data->free_blocks_count));
1105 ext4_free_inodes_set(sb, gdp, EXT4_INODES_PER_GROUP(sb)); 1163 ext4_free_inodes_set(sb, gdp, EXT4_INODES_PER_GROUP(sb));
1106 gdp->bg_flags = cpu_to_le16(*bg_flags); 1164 gdp->bg_flags = cpu_to_le16(*bg_flags);
1107 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp); 1165 ext4_group_desc_csum_set(sb, group, gdp);
1108 1166
1109 err = ext4_handle_dirty_metadata(handle, NULL, gdb_bh); 1167 err = ext4_handle_dirty_metadata(handle, NULL, gdb_bh);
1110 if (unlikely(err)) { 1168 if (unlikely(err)) {
@@ -1343,17 +1401,14 @@ static int ext4_setup_next_flex_gd(struct super_block *sb,
1343 (1 + ext4_bg_num_gdb(sb, group + i) + 1401 (1 + ext4_bg_num_gdb(sb, group + i) +
1344 le16_to_cpu(es->s_reserved_gdt_blocks)) : 0; 1402 le16_to_cpu(es->s_reserved_gdt_blocks)) : 0;
1345 group_data[i].free_blocks_count = blocks_per_group - overhead; 1403 group_data[i].free_blocks_count = blocks_per_group - overhead;
1346 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, 1404 if (ext4_has_group_desc_csum(sb))
1347 EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
1348 flex_gd->bg_flags[i] = EXT4_BG_BLOCK_UNINIT | 1405 flex_gd->bg_flags[i] = EXT4_BG_BLOCK_UNINIT |
1349 EXT4_BG_INODE_UNINIT; 1406 EXT4_BG_INODE_UNINIT;
1350 else 1407 else
1351 flex_gd->bg_flags[i] = EXT4_BG_INODE_ZEROED; 1408 flex_gd->bg_flags[i] = EXT4_BG_INODE_ZEROED;
1352 } 1409 }
1353 1410
1354 if (last_group == n_group && 1411 if (last_group == n_group && ext4_has_group_desc_csum(sb))
1355 EXT4_HAS_RO_COMPAT_FEATURE(sb,
1356 EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
1357 /* We need to initialize block bitmap of last group. */ 1412 /* We need to initialize block bitmap of last group. */
1358 flex_gd->bg_flags[i - 1] &= ~EXT4_BG_BLOCK_UNINIT; 1413 flex_gd->bg_flags[i - 1] &= ~EXT4_BG_BLOCK_UNINIT;
1359 1414
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 35b5954489ee..eb7aa3e4ef05 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -112,6 +112,48 @@ static struct file_system_type ext3_fs_type = {
112#define IS_EXT3_SB(sb) (0) 112#define IS_EXT3_SB(sb) (0)
113#endif 113#endif
114 114
115static int ext4_verify_csum_type(struct super_block *sb,
116 struct ext4_super_block *es)
117{
118 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
119 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
120 return 1;
121
122 return es->s_checksum_type == EXT4_CRC32C_CHKSUM;
123}
124
125static __le32 ext4_superblock_csum(struct super_block *sb,
126 struct ext4_super_block *es)
127{
128 struct ext4_sb_info *sbi = EXT4_SB(sb);
129 int offset = offsetof(struct ext4_super_block, s_checksum);
130 __u32 csum;
131
132 csum = ext4_chksum(sbi, ~0, (char *)es, offset);
133
134 return cpu_to_le32(csum);
135}
136
137int ext4_superblock_csum_verify(struct super_block *sb,
138 struct ext4_super_block *es)
139{
140 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
141 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
142 return 1;
143
144 return es->s_checksum == ext4_superblock_csum(sb, es);
145}
146
147void ext4_superblock_csum_set(struct super_block *sb,
148 struct ext4_super_block *es)
149{
150 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
151 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
152 return;
153
154 es->s_checksum = ext4_superblock_csum(sb, es);
155}
156
115void *ext4_kvmalloc(size_t size, gfp_t flags) 157void *ext4_kvmalloc(size_t size, gfp_t flags)
116{ 158{
117 void *ret; 159 void *ret;
@@ -497,6 +539,7 @@ void __ext4_error(struct super_block *sb, const char *function,
497 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: comm %s: %pV\n", 539 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: comm %s: %pV\n",
498 sb->s_id, function, line, current->comm, &vaf); 540 sb->s_id, function, line, current->comm, &vaf);
499 va_end(args); 541 va_end(args);
542 save_error_info(sb, function, line);
500 543
501 ext4_handle_error(sb); 544 ext4_handle_error(sb);
502} 545}
@@ -905,6 +948,8 @@ static void ext4_put_super(struct super_block *sb)
905 unlock_super(sb); 948 unlock_super(sb);
906 kobject_put(&sbi->s_kobj); 949 kobject_put(&sbi->s_kobj);
907 wait_for_completion(&sbi->s_kobj_unregister); 950 wait_for_completion(&sbi->s_kobj_unregister);
951 if (sbi->s_chksum_driver)
952 crypto_free_shash(sbi->s_chksum_driver);
908 kfree(sbi->s_blockgroup_lock); 953 kfree(sbi->s_blockgroup_lock);
909 kfree(sbi); 954 kfree(sbi);
910} 955}
@@ -1922,43 +1967,69 @@ failed:
1922 return 0; 1967 return 0;
1923} 1968}
1924 1969
1925__le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group, 1970static __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group,
1926 struct ext4_group_desc *gdp) 1971 struct ext4_group_desc *gdp)
1927{ 1972{
1973 int offset;
1928 __u16 crc = 0; 1974 __u16 crc = 0;
1975 __le32 le_group = cpu_to_le32(block_group);
1929 1976
1930 if (sbi->s_es->s_feature_ro_compat & 1977 if ((sbi->s_es->s_feature_ro_compat &
1931 cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) { 1978 cpu_to_le32(EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))) {
1932 int offset = offsetof(struct ext4_group_desc, bg_checksum); 1979 /* Use new metadata_csum algorithm */
1933 __le32 le_group = cpu_to_le32(block_group); 1980 __u16 old_csum;
1934 1981 __u32 csum32;
1935 crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid)); 1982
1936 crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group)); 1983 old_csum = gdp->bg_checksum;
1937 crc = crc16(crc, (__u8 *)gdp, offset); 1984 gdp->bg_checksum = 0;
1938 offset += sizeof(gdp->bg_checksum); /* skip checksum */ 1985 csum32 = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&le_group,
1939 /* for checksum of struct ext4_group_desc do the rest...*/ 1986 sizeof(le_group));
1940 if ((sbi->s_es->s_feature_incompat & 1987 csum32 = ext4_chksum(sbi, csum32, (__u8 *)gdp,
1941 cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) && 1988 sbi->s_desc_size);
1942 offset < le16_to_cpu(sbi->s_es->s_desc_size)) 1989 gdp->bg_checksum = old_csum;
1943 crc = crc16(crc, (__u8 *)gdp + offset, 1990
1944 le16_to_cpu(sbi->s_es->s_desc_size) - 1991 crc = csum32 & 0xFFFF;
1945 offset); 1992 goto out;
1946 } 1993 }
1947 1994
1995 /* old crc16 code */
1996 offset = offsetof(struct ext4_group_desc, bg_checksum);
1997
1998 crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));
1999 crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group));
2000 crc = crc16(crc, (__u8 *)gdp, offset);
2001 offset += sizeof(gdp->bg_checksum); /* skip checksum */
2002 /* for checksum of struct ext4_group_desc do the rest...*/
2003 if ((sbi->s_es->s_feature_incompat &
2004 cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) &&
2005 offset < le16_to_cpu(sbi->s_es->s_desc_size))
2006 crc = crc16(crc, (__u8 *)gdp + offset,
2007 le16_to_cpu(sbi->s_es->s_desc_size) -
2008 offset);
2009
2010out:
1948 return cpu_to_le16(crc); 2011 return cpu_to_le16(crc);
1949} 2012}
1950 2013
1951int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group, 2014int ext4_group_desc_csum_verify(struct super_block *sb, __u32 block_group,
1952 struct ext4_group_desc *gdp) 2015 struct ext4_group_desc *gdp)
1953{ 2016{
1954 if ((sbi->s_es->s_feature_ro_compat & 2017 if (ext4_has_group_desc_csum(sb) &&
1955 cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) && 2018 (gdp->bg_checksum != ext4_group_desc_csum(EXT4_SB(sb),
1956 (gdp->bg_checksum != ext4_group_desc_csum(sbi, block_group, gdp))) 2019 block_group, gdp)))
1957 return 0; 2020 return 0;
1958 2021
1959 return 1; 2022 return 1;
1960} 2023}
1961 2024
2025void ext4_group_desc_csum_set(struct super_block *sb, __u32 block_group,
2026 struct ext4_group_desc *gdp)
2027{
2028 if (!ext4_has_group_desc_csum(sb))
2029 return;
2030 gdp->bg_checksum = ext4_group_desc_csum(EXT4_SB(sb), block_group, gdp);
2031}
2032
1962/* Called at mount-time, super-block is locked */ 2033/* Called at mount-time, super-block is locked */
1963static int ext4_check_descriptors(struct super_block *sb, 2034static int ext4_check_descriptors(struct super_block *sb,
1964 ext4_group_t *first_not_zeroed) 2035 ext4_group_t *first_not_zeroed)
@@ -2013,7 +2084,7 @@ static int ext4_check_descriptors(struct super_block *sb,
2013 return 0; 2084 return 0;
2014 } 2085 }
2015 ext4_lock_group(sb, i); 2086 ext4_lock_group(sb, i);
2016 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { 2087 if (!ext4_group_desc_csum_verify(sb, i, gdp)) {
2017 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: " 2088 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
2018 "Checksum for group %u failed (%u!=%u)", 2089 "Checksum for group %u failed (%u!=%u)",
2019 i, le16_to_cpu(ext4_group_desc_csum(sbi, i, 2090 i, le16_to_cpu(ext4_group_desc_csum(sbi, i,
@@ -2417,6 +2488,23 @@ static ssize_t sbi_ui_store(struct ext4_attr *a,
2417 return count; 2488 return count;
2418} 2489}
2419 2490
2491static ssize_t trigger_test_error(struct ext4_attr *a,
2492 struct ext4_sb_info *sbi,
2493 const char *buf, size_t count)
2494{
2495 int len = count;
2496
2497 if (!capable(CAP_SYS_ADMIN))
2498 return -EPERM;
2499
2500 if (len && buf[len-1] == '\n')
2501 len--;
2502
2503 if (len)
2504 ext4_error(sbi->s_sb, "%.*s", len, buf);
2505 return count;
2506}
2507
2420#define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \ 2508#define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \
2421static struct ext4_attr ext4_attr_##_name = { \ 2509static struct ext4_attr ext4_attr_##_name = { \
2422 .attr = {.name = __stringify(_name), .mode = _mode }, \ 2510 .attr = {.name = __stringify(_name), .mode = _mode }, \
@@ -2447,6 +2535,7 @@ EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
2447EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request); 2535EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
2448EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc); 2536EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
2449EXT4_RW_ATTR_SBI_UI(max_writeback_mb_bump, s_max_writeback_mb_bump); 2537EXT4_RW_ATTR_SBI_UI(max_writeback_mb_bump, s_max_writeback_mb_bump);
2538EXT4_ATTR(trigger_fs_error, 0200, NULL, trigger_test_error);
2450 2539
2451static struct attribute *ext4_attrs[] = { 2540static struct attribute *ext4_attrs[] = {
2452 ATTR_LIST(delayed_allocation_blocks), 2541 ATTR_LIST(delayed_allocation_blocks),
@@ -2461,6 +2550,7 @@ static struct attribute *ext4_attrs[] = {
2461 ATTR_LIST(mb_stream_req), 2550 ATTR_LIST(mb_stream_req),
2462 ATTR_LIST(mb_group_prealloc), 2551 ATTR_LIST(mb_group_prealloc),
2463 ATTR_LIST(max_writeback_mb_bump), 2552 ATTR_LIST(max_writeback_mb_bump),
2553 ATTR_LIST(trigger_fs_error),
2464 NULL, 2554 NULL,
2465}; 2555};
2466 2556
@@ -2957,6 +3047,44 @@ static void ext4_destroy_lazyinit_thread(void)
2957 kthread_stop(ext4_lazyinit_task); 3047 kthread_stop(ext4_lazyinit_task);
2958} 3048}
2959 3049
3050static int set_journal_csum_feature_set(struct super_block *sb)
3051{
3052 int ret = 1;
3053 int compat, incompat;
3054 struct ext4_sb_info *sbi = EXT4_SB(sb);
3055
3056 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
3057 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
3058 /* journal checksum v2 */
3059 compat = 0;
3060 incompat = JBD2_FEATURE_INCOMPAT_CSUM_V2;
3061 } else {
3062 /* journal checksum v1 */
3063 compat = JBD2_FEATURE_COMPAT_CHECKSUM;
3064 incompat = 0;
3065 }
3066
3067 if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
3068 ret = jbd2_journal_set_features(sbi->s_journal,
3069 compat, 0,
3070 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT |
3071 incompat);
3072 } else if (test_opt(sb, JOURNAL_CHECKSUM)) {
3073 ret = jbd2_journal_set_features(sbi->s_journal,
3074 compat, 0,
3075 incompat);
3076 jbd2_journal_clear_features(sbi->s_journal, 0, 0,
3077 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
3078 } else {
3079 jbd2_journal_clear_features(sbi->s_journal,
3080 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
3081 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT |
3082 JBD2_FEATURE_INCOMPAT_CSUM_V2);
3083 }
3084
3085 return ret;
3086}
3087
2960static int ext4_fill_super(struct super_block *sb, void *data, int silent) 3088static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2961{ 3089{
2962 char *orig_data = kstrdup(data, GFP_KERNEL); 3090 char *orig_data = kstrdup(data, GFP_KERNEL);
@@ -2993,6 +3121,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2993 goto out_free_orig; 3121 goto out_free_orig;
2994 } 3122 }
2995 sb->s_fs_info = sbi; 3123 sb->s_fs_info = sbi;
3124 sbi->s_sb = sb;
2996 sbi->s_mount_opt = 0; 3125 sbi->s_mount_opt = 0;
2997 sbi->s_resuid = make_kuid(&init_user_ns, EXT4_DEF_RESUID); 3126 sbi->s_resuid = make_kuid(&init_user_ns, EXT4_DEF_RESUID);
2998 sbi->s_resgid = make_kgid(&init_user_ns, EXT4_DEF_RESGID); 3127 sbi->s_resgid = make_kgid(&init_user_ns, EXT4_DEF_RESGID);
@@ -3032,13 +3161,54 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3032 * Note: s_es must be initialized as soon as possible because 3161 * Note: s_es must be initialized as soon as possible because
3033 * some ext4 macro-instructions depend on its value 3162 * some ext4 macro-instructions depend on its value
3034 */ 3163 */
3035 es = (struct ext4_super_block *) (((char *)bh->b_data) + offset); 3164 es = (struct ext4_super_block *) (bh->b_data + offset);
3036 sbi->s_es = es; 3165 sbi->s_es = es;
3037 sb->s_magic = le16_to_cpu(es->s_magic); 3166 sb->s_magic = le16_to_cpu(es->s_magic);
3038 if (sb->s_magic != EXT4_SUPER_MAGIC) 3167 if (sb->s_magic != EXT4_SUPER_MAGIC)
3039 goto cantfind_ext4; 3168 goto cantfind_ext4;
3040 sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written); 3169 sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written);
3041 3170
3171 /* Warn if metadata_csum and gdt_csum are both set. */
3172 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
3173 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
3174 EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
3175 ext4_warning(sb, KERN_INFO "metadata_csum and uninit_bg are "
3176 "redundant flags; please run fsck.");
3177
3178 /* Check for a known checksum algorithm */
3179 if (!ext4_verify_csum_type(sb, es)) {
3180 ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
3181 "unknown checksum algorithm.");
3182 silent = 1;
3183 goto cantfind_ext4;
3184 }
3185
3186 /* Load the checksum driver */
3187 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
3188 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
3189 sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
3190 if (IS_ERR(sbi->s_chksum_driver)) {
3191 ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
3192 ret = PTR_ERR(sbi->s_chksum_driver);
3193 sbi->s_chksum_driver = NULL;
3194 goto failed_mount;
3195 }
3196 }
3197
3198 /* Check superblock checksum */
3199 if (!ext4_superblock_csum_verify(sb, es)) {
3200 ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
3201 "invalid superblock checksum. Run e2fsck?");
3202 silent = 1;
3203 goto cantfind_ext4;
3204 }
3205
3206 /* Precompute checksum seed for all metadata */
3207 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
3208 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
3209 sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid,
3210 sizeof(es->s_uuid));
3211
3042 /* Set defaults before we parse the mount options */ 3212 /* Set defaults before we parse the mount options */
3043 def_mount_opts = le32_to_cpu(es->s_default_mount_opts); 3213 def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
3044 set_opt(sb, INIT_INODE_TABLE); 3214 set_opt(sb, INIT_INODE_TABLE);
@@ -3200,7 +3370,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3200 "Can't read superblock on 2nd try"); 3370 "Can't read superblock on 2nd try");
3201 goto failed_mount; 3371 goto failed_mount;
3202 } 3372 }
3203 es = (struct ext4_super_block *)(((char *)bh->b_data) + offset); 3373 es = (struct ext4_super_block *)(bh->b_data + offset);
3204 sbi->s_es = es; 3374 sbi->s_es = es;
3205 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) { 3375 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
3206 ext4_msg(sb, KERN_ERR, 3376 ext4_msg(sb, KERN_ERR,
@@ -3392,6 +3562,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3392 GFP_KERNEL); 3562 GFP_KERNEL);
3393 if (sbi->s_group_desc == NULL) { 3563 if (sbi->s_group_desc == NULL) {
3394 ext4_msg(sb, KERN_ERR, "not enough memory"); 3564 ext4_msg(sb, KERN_ERR, "not enough memory");
3565 ret = -ENOMEM;
3395 goto failed_mount; 3566 goto failed_mount;
3396 } 3567 }
3397 3568
@@ -3449,6 +3620,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3449 } 3620 }
3450 if (err) { 3621 if (err) {
3451 ext4_msg(sb, KERN_ERR, "insufficient memory"); 3622 ext4_msg(sb, KERN_ERR, "insufficient memory");
3623 ret = err;
3452 goto failed_mount3; 3624 goto failed_mount3;
3453 } 3625 }
3454 3626
@@ -3506,26 +3678,17 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3506 goto no_journal; 3678 goto no_journal;
3507 } 3679 }
3508 3680
3509 if (ext4_blocks_count(es) > 0xffffffffULL && 3681 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT) &&
3510 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0, 3682 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
3511 JBD2_FEATURE_INCOMPAT_64BIT)) { 3683 JBD2_FEATURE_INCOMPAT_64BIT)) {
3512 ext4_msg(sb, KERN_ERR, "Failed to set 64-bit journal feature"); 3684 ext4_msg(sb, KERN_ERR, "Failed to set 64-bit journal feature");
3513 goto failed_mount_wq; 3685 goto failed_mount_wq;
3514 } 3686 }
3515 3687
3516 if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) { 3688 if (!set_journal_csum_feature_set(sb)) {
3517 jbd2_journal_set_features(sbi->s_journal, 3689 ext4_msg(sb, KERN_ERR, "Failed to set journal checksum "
3518 JBD2_FEATURE_COMPAT_CHECKSUM, 0, 3690 "feature set");
3519 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT); 3691 goto failed_mount_wq;
3520 } else if (test_opt(sb, JOURNAL_CHECKSUM)) {
3521 jbd2_journal_set_features(sbi->s_journal,
3522 JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0);
3523 jbd2_journal_clear_features(sbi->s_journal, 0, 0,
3524 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
3525 } else {
3526 jbd2_journal_clear_features(sbi->s_journal,
3527 JBD2_FEATURE_COMPAT_CHECKSUM, 0,
3528 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
3529 } 3692 }
3530 3693
3531 /* We have now updated the journal if required, so we can 3694 /* We have now updated the journal if required, so we can
@@ -3606,7 +3769,8 @@ no_journal:
3606 goto failed_mount4; 3769 goto failed_mount4;
3607 } 3770 }
3608 3771
3609 ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY); 3772 if (ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY))
3773 sb->s_flags |= MS_RDONLY;
3610 3774
3611 /* determine the minimum size of new large inodes, if present */ 3775 /* determine the minimum size of new large inodes, if present */
3612 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) { 3776 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
@@ -3641,7 +3805,7 @@ no_journal:
3641 } 3805 }
3642 3806
3643 ext4_ext_init(sb); 3807 ext4_ext_init(sb);
3644 err = ext4_mb_init(sb, needs_recovery); 3808 err = ext4_mb_init(sb);
3645 if (err) { 3809 if (err) {
3646 ext4_msg(sb, KERN_ERR, "failed to initialize mballoc (%d)", 3810 ext4_msg(sb, KERN_ERR, "failed to initialize mballoc (%d)",
3647 err); 3811 err);
@@ -3724,6 +3888,8 @@ failed_mount2:
3724 brelse(sbi->s_group_desc[i]); 3888 brelse(sbi->s_group_desc[i]);
3725 ext4_kvfree(sbi->s_group_desc); 3889 ext4_kvfree(sbi->s_group_desc);
3726failed_mount: 3890failed_mount:
3891 if (sbi->s_chksum_driver)
3892 crypto_free_shash(sbi->s_chksum_driver);
3727 if (sbi->s_proc) { 3893 if (sbi->s_proc) {
3728 remove_proc_entry("options", sbi->s_proc); 3894 remove_proc_entry("options", sbi->s_proc);
3729 remove_proc_entry(sb->s_id, ext4_proc_root); 3895 remove_proc_entry(sb->s_id, ext4_proc_root);
@@ -3847,7 +4013,7 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
3847 goto out_bdev; 4013 goto out_bdev;
3848 } 4014 }
3849 4015
3850 es = (struct ext4_super_block *) (((char *)bh->b_data) + offset); 4016 es = (struct ext4_super_block *) (bh->b_data + offset);
3851 if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) || 4017 if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) ||
3852 !(le32_to_cpu(es->s_feature_incompat) & 4018 !(le32_to_cpu(es->s_feature_incompat) &
3853 EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) { 4019 EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
@@ -4039,6 +4205,7 @@ static int ext4_commit_super(struct super_block *sb, int sync)
4039 &EXT4_SB(sb)->s_freeinodes_counter)); 4205 &EXT4_SB(sb)->s_freeinodes_counter));
4040 sb->s_dirt = 0; 4206 sb->s_dirt = 0;
4041 BUFFER_TRACE(sbh, "marking dirty"); 4207 BUFFER_TRACE(sbh, "marking dirty");
4208 ext4_superblock_csum_set(sb, es);
4042 mark_buffer_dirty(sbh); 4209 mark_buffer_dirty(sbh);
4043 if (sync) { 4210 if (sync) {
4044 error = sync_dirty_buffer(sbh); 4211 error = sync_dirty_buffer(sbh);
@@ -4333,7 +4500,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
4333 struct ext4_group_desc *gdp = 4500 struct ext4_group_desc *gdp =
4334 ext4_get_group_desc(sb, g, NULL); 4501 ext4_get_group_desc(sb, g, NULL);
4335 4502
4336 if (!ext4_group_desc_csum_verify(sbi, g, gdp)) { 4503 if (!ext4_group_desc_csum_verify(sb, g, gdp)) {
4337 ext4_msg(sb, KERN_ERR, 4504 ext4_msg(sb, KERN_ERR,
4338 "ext4_remount: Checksum for group %u failed (%u!=%u)", 4505 "ext4_remount: Checksum for group %u failed (%u!=%u)",
4339 g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)), 4506 g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)),
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index e88748e55c0f..e56c9ed7d6e3 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -122,6 +122,58 @@ const struct xattr_handler *ext4_xattr_handlers[] = {
122 NULL 122 NULL
123}; 123};
124 124
125static __le32 ext4_xattr_block_csum(struct inode *inode,
126 sector_t block_nr,
127 struct ext4_xattr_header *hdr)
128{
129 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
130 struct ext4_inode_info *ei = EXT4_I(inode);
131 __u32 csum, old;
132
133 old = hdr->h_checksum;
134 hdr->h_checksum = 0;
135 if (le32_to_cpu(hdr->h_refcount) != 1) {
136 block_nr = cpu_to_le64(block_nr);
137 csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&block_nr,
138 sizeof(block_nr));
139 } else
140 csum = ei->i_csum_seed;
141 csum = ext4_chksum(sbi, csum, (__u8 *)hdr,
142 EXT4_BLOCK_SIZE(inode->i_sb));
143 hdr->h_checksum = old;
144 return cpu_to_le32(csum);
145}
146
147static int ext4_xattr_block_csum_verify(struct inode *inode,
148 sector_t block_nr,
149 struct ext4_xattr_header *hdr)
150{
151 if (EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
152 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
153 (hdr->h_checksum != ext4_xattr_block_csum(inode, block_nr, hdr)))
154 return 0;
155 return 1;
156}
157
158static void ext4_xattr_block_csum_set(struct inode *inode,
159 sector_t block_nr,
160 struct ext4_xattr_header *hdr)
161{
162 if (!EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb,
163 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
164 return;
165
166 hdr->h_checksum = ext4_xattr_block_csum(inode, block_nr, hdr);
167}
168
169static inline int ext4_handle_dirty_xattr_block(handle_t *handle,
170 struct inode *inode,
171 struct buffer_head *bh)
172{
173 ext4_xattr_block_csum_set(inode, bh->b_blocknr, BHDR(bh));
174 return ext4_handle_dirty_metadata(handle, inode, bh);
175}
176
125static inline const struct xattr_handler * 177static inline const struct xattr_handler *
126ext4_xattr_handler(int name_index) 178ext4_xattr_handler(int name_index)
127{ 179{
@@ -156,12 +208,22 @@ ext4_xattr_check_names(struct ext4_xattr_entry *entry, void *end)
156} 208}
157 209
158static inline int 210static inline int
159ext4_xattr_check_block(struct buffer_head *bh) 211ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh)
160{ 212{
213 int error;
214
215 if (buffer_verified(bh))
216 return 0;
217
161 if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) || 218 if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
162 BHDR(bh)->h_blocks != cpu_to_le32(1)) 219 BHDR(bh)->h_blocks != cpu_to_le32(1))
163 return -EIO; 220 return -EIO;
164 return ext4_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size); 221 if (!ext4_xattr_block_csum_verify(inode, bh->b_blocknr, BHDR(bh)))
222 return -EIO;
223 error = ext4_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size);
224 if (!error)
225 set_buffer_verified(bh);
226 return error;
165} 227}
166 228
167static inline int 229static inline int
@@ -224,7 +286,7 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
224 goto cleanup; 286 goto cleanup;
225 ea_bdebug(bh, "b_count=%d, refcount=%d", 287 ea_bdebug(bh, "b_count=%d, refcount=%d",
226 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); 288 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
227 if (ext4_xattr_check_block(bh)) { 289 if (ext4_xattr_check_block(inode, bh)) {
228bad_block: 290bad_block:
229 EXT4_ERROR_INODE(inode, "bad block %llu", 291 EXT4_ERROR_INODE(inode, "bad block %llu",
230 EXT4_I(inode)->i_file_acl); 292 EXT4_I(inode)->i_file_acl);
@@ -369,7 +431,7 @@ ext4_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size)
369 goto cleanup; 431 goto cleanup;
370 ea_bdebug(bh, "b_count=%d, refcount=%d", 432 ea_bdebug(bh, "b_count=%d, refcount=%d",
371 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); 433 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
372 if (ext4_xattr_check_block(bh)) { 434 if (ext4_xattr_check_block(inode, bh)) {
373 EXT4_ERROR_INODE(inode, "bad block %llu", 435 EXT4_ERROR_INODE(inode, "bad block %llu",
374 EXT4_I(inode)->i_file_acl); 436 EXT4_I(inode)->i_file_acl);
375 error = -EIO; 437 error = -EIO;
@@ -492,7 +554,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,
492 if (ce) 554 if (ce)
493 mb_cache_entry_release(ce); 555 mb_cache_entry_release(ce);
494 unlock_buffer(bh); 556 unlock_buffer(bh);
495 error = ext4_handle_dirty_metadata(handle, inode, bh); 557 error = ext4_handle_dirty_xattr_block(handle, inode, bh);
496 if (IS_SYNC(inode)) 558 if (IS_SYNC(inode))
497 ext4_handle_sync(handle); 559 ext4_handle_sync(handle);
498 dquot_free_block(inode, 1); 560 dquot_free_block(inode, 1);
@@ -662,7 +724,7 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
662 ea_bdebug(bs->bh, "b_count=%d, refcount=%d", 724 ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
663 atomic_read(&(bs->bh->b_count)), 725 atomic_read(&(bs->bh->b_count)),
664 le32_to_cpu(BHDR(bs->bh)->h_refcount)); 726 le32_to_cpu(BHDR(bs->bh)->h_refcount));
665 if (ext4_xattr_check_block(bs->bh)) { 727 if (ext4_xattr_check_block(inode, bs->bh)) {
666 EXT4_ERROR_INODE(inode, "bad block %llu", 728 EXT4_ERROR_INODE(inode, "bad block %llu",
667 EXT4_I(inode)->i_file_acl); 729 EXT4_I(inode)->i_file_acl);
668 error = -EIO; 730 error = -EIO;
@@ -725,9 +787,9 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
725 if (error == -EIO) 787 if (error == -EIO)
726 goto bad_block; 788 goto bad_block;
727 if (!error) 789 if (!error)
728 error = ext4_handle_dirty_metadata(handle, 790 error = ext4_handle_dirty_xattr_block(handle,
729 inode, 791 inode,
730 bs->bh); 792 bs->bh);
731 if (error) 793 if (error)
732 goto cleanup; 794 goto cleanup;
733 goto inserted; 795 goto inserted;
@@ -796,9 +858,9 @@ inserted:
796 ea_bdebug(new_bh, "reusing; refcount now=%d", 858 ea_bdebug(new_bh, "reusing; refcount now=%d",
797 le32_to_cpu(BHDR(new_bh)->h_refcount)); 859 le32_to_cpu(BHDR(new_bh)->h_refcount));
798 unlock_buffer(new_bh); 860 unlock_buffer(new_bh);
799 error = ext4_handle_dirty_metadata(handle, 861 error = ext4_handle_dirty_xattr_block(handle,
800 inode, 862 inode,
801 new_bh); 863 new_bh);
802 if (error) 864 if (error)
803 goto cleanup_dquot; 865 goto cleanup_dquot;
804 } 866 }
@@ -855,8 +917,8 @@ getblk_failed:
855 set_buffer_uptodate(new_bh); 917 set_buffer_uptodate(new_bh);
856 unlock_buffer(new_bh); 918 unlock_buffer(new_bh);
857 ext4_xattr_cache_insert(new_bh); 919 ext4_xattr_cache_insert(new_bh);
858 error = ext4_handle_dirty_metadata(handle, 920 error = ext4_handle_dirty_xattr_block(handle,
859 inode, new_bh); 921 inode, new_bh);
860 if (error) 922 if (error)
861 goto cleanup; 923 goto cleanup;
862 } 924 }
@@ -1193,7 +1255,7 @@ retry:
1193 error = -EIO; 1255 error = -EIO;
1194 if (!bh) 1256 if (!bh)
1195 goto cleanup; 1257 goto cleanup;
1196 if (ext4_xattr_check_block(bh)) { 1258 if (ext4_xattr_check_block(inode, bh)) {
1197 EXT4_ERROR_INODE(inode, "bad block %llu", 1259 EXT4_ERROR_INODE(inode, "bad block %llu",
1198 EXT4_I(inode)->i_file_acl); 1260 EXT4_I(inode)->i_file_acl);
1199 error = -EIO; 1261 error = -EIO;
diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h
index 25b7387ff183..91f31ca7d9af 100644
--- a/fs/ext4/xattr.h
+++ b/fs/ext4/xattr.h
@@ -27,7 +27,9 @@ struct ext4_xattr_header {
27 __le32 h_refcount; /* reference count */ 27 __le32 h_refcount; /* reference count */
28 __le32 h_blocks; /* number of disk blocks used */ 28 __le32 h_blocks; /* number of disk blocks used */
29 __le32 h_hash; /* hash value of all attributes */ 29 __le32 h_hash; /* hash value of all attributes */
30 __u32 h_reserved[4]; /* zero right now */ 30 __le32 h_checksum; /* crc32c(uuid+id+xattrblock) */
31 /* id = inum if refcount=1, blknum otherwise */
32 __u32 h_reserved[3]; /* zero right now */
31}; 33};
32 34
33struct ext4_xattr_ibody_header { 35struct ext4_xattr_ibody_header {
diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index aca191bd5f8f..6eaa28c98ad1 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -98,8 +98,8 @@ next:
98 98
99 *bh = sb_bread(sb, phys); 99 *bh = sb_bread(sb, phys);
100 if (*bh == NULL) { 100 if (*bh == NULL) {
101 fat_msg(sb, KERN_ERR, "Directory bread(block %llu) failed", 101 fat_msg_ratelimit(sb, KERN_ERR,
102 (llu)phys); 102 "Directory bread(block %llu) failed", (llu)phys);
103 /* skip this block */ 103 /* skip this block */
104 *pos = (iblock + 1) << sb->s_blocksize_bits; 104 *pos = (iblock + 1) << sb->s_blocksize_bits;
105 goto next; 105 goto next;
diff --git a/fs/fat/fat.h b/fs/fat/fat.h
index 66994f316e18..fc35c5c69136 100644
--- a/fs/fat/fat.h
+++ b/fs/fat/fat.h
@@ -82,6 +82,7 @@ struct msdos_sb_info {
82 int fatent_shift; 82 int fatent_shift;
83 struct fatent_operations *fatent_ops; 83 struct fatent_operations *fatent_ops;
84 struct inode *fat_inode; 84 struct inode *fat_inode;
85 struct inode *fsinfo_inode;
85 86
86 struct ratelimit_state ratelimit; 87 struct ratelimit_state ratelimit;
87 88
@@ -334,6 +335,11 @@ void __fat_fs_error(struct super_block *sb, int report, const char *fmt, ...);
334 __fat_fs_error(sb, __ratelimit(&MSDOS_SB(sb)->ratelimit), fmt , ## args) 335 __fat_fs_error(sb, __ratelimit(&MSDOS_SB(sb)->ratelimit), fmt , ## args)
335__printf(3, 4) __cold 336__printf(3, 4) __cold
336void fat_msg(struct super_block *sb, const char *level, const char *fmt, ...); 337void fat_msg(struct super_block *sb, const char *level, const char *fmt, ...);
338#define fat_msg_ratelimit(sb, level, fmt, args...) \
339 do { \
340 if (__ratelimit(&MSDOS_SB(sb)->ratelimit)) \
341 fat_msg(sb, level, fmt, ## args); \
342 } while (0)
337extern int fat_clusters_flush(struct super_block *sb); 343extern int fat_clusters_flush(struct super_block *sb);
338extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster); 344extern int fat_chain_add(struct inode *inode, int new_dclus, int nr_cluster);
339extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts, 345extern void fat_time_fat2unix(struct msdos_sb_info *sbi, struct timespec *ts,
diff --git a/fs/fat/fatent.c b/fs/fat/fatent.c
index 2e81ac0df7e2..31f08ab62c56 100644
--- a/fs/fat/fatent.c
+++ b/fs/fat/fatent.c
@@ -308,6 +308,16 @@ void fat_ent_access_init(struct super_block *sb)
308 } 308 }
309} 309}
310 310
311static void mark_fsinfo_dirty(struct super_block *sb)
312{
313 struct msdos_sb_info *sbi = MSDOS_SB(sb);
314
315 if (sb->s_flags & MS_RDONLY || sbi->fat_bits != 32)
316 return;
317
318 __mark_inode_dirty(sbi->fsinfo_inode, I_DIRTY_SYNC);
319}
320
311static inline int fat_ent_update_ptr(struct super_block *sb, 321static inline int fat_ent_update_ptr(struct super_block *sb,
312 struct fat_entry *fatent, 322 struct fat_entry *fatent,
313 int offset, sector_t blocknr) 323 int offset, sector_t blocknr)
@@ -498,7 +508,6 @@ int fat_alloc_clusters(struct inode *inode, int *cluster, int nr_cluster)
498 sbi->prev_free = entry; 508 sbi->prev_free = entry;
499 if (sbi->free_clusters != -1) 509 if (sbi->free_clusters != -1)
500 sbi->free_clusters--; 510 sbi->free_clusters--;
501 sb->s_dirt = 1;
502 511
503 cluster[idx_clus] = entry; 512 cluster[idx_clus] = entry;
504 idx_clus++; 513 idx_clus++;
@@ -520,11 +529,11 @@ int fat_alloc_clusters(struct inode *inode, int *cluster, int nr_cluster)
520 /* Couldn't allocate the free entries */ 529 /* Couldn't allocate the free entries */
521 sbi->free_clusters = 0; 530 sbi->free_clusters = 0;
522 sbi->free_clus_valid = 1; 531 sbi->free_clus_valid = 1;
523 sb->s_dirt = 1;
524 err = -ENOSPC; 532 err = -ENOSPC;
525 533
526out: 534out:
527 unlock_fat(sbi); 535 unlock_fat(sbi);
536 mark_fsinfo_dirty(sb);
528 fatent_brelse(&fatent); 537 fatent_brelse(&fatent);
529 if (!err) { 538 if (!err) {
530 if (inode_needs_sync(inode)) 539 if (inode_needs_sync(inode))
@@ -549,7 +558,7 @@ int fat_free_clusters(struct inode *inode, int cluster)
549 struct fat_entry fatent; 558 struct fat_entry fatent;
550 struct buffer_head *bhs[MAX_BUF_PER_PAGE]; 559 struct buffer_head *bhs[MAX_BUF_PER_PAGE];
551 int i, err, nr_bhs; 560 int i, err, nr_bhs;
552 int first_cl = cluster; 561 int first_cl = cluster, dirty_fsinfo = 0;
553 562
554 nr_bhs = 0; 563 nr_bhs = 0;
555 fatent_init(&fatent); 564 fatent_init(&fatent);
@@ -587,7 +596,7 @@ int fat_free_clusters(struct inode *inode, int cluster)
587 ops->ent_put(&fatent, FAT_ENT_FREE); 596 ops->ent_put(&fatent, FAT_ENT_FREE);
588 if (sbi->free_clusters != -1) { 597 if (sbi->free_clusters != -1) {
589 sbi->free_clusters++; 598 sbi->free_clusters++;
590 sb->s_dirt = 1; 599 dirty_fsinfo = 1;
591 } 600 }
592 601
593 if (nr_bhs + fatent.nr_bhs > MAX_BUF_PER_PAGE) { 602 if (nr_bhs + fatent.nr_bhs > MAX_BUF_PER_PAGE) {
@@ -617,6 +626,8 @@ error:
617 for (i = 0; i < nr_bhs; i++) 626 for (i = 0; i < nr_bhs; i++)
618 brelse(bhs[i]); 627 brelse(bhs[i]);
619 unlock_fat(sbi); 628 unlock_fat(sbi);
629 if (dirty_fsinfo)
630 mark_fsinfo_dirty(sb);
620 631
621 return err; 632 return err;
622} 633}
@@ -677,7 +688,7 @@ int fat_count_free_clusters(struct super_block *sb)
677 } 688 }
678 sbi->free_clusters = free; 689 sbi->free_clusters = free;
679 sbi->free_clus_valid = 1; 690 sbi->free_clus_valid = 1;
680 sb->s_dirt = 1; 691 mark_fsinfo_dirty(sb);
681 fatent_brelse(&fatent); 692 fatent_brelse(&fatent);
682out: 693out:
683 unlock_fat(sbi); 694 unlock_fat(sbi);
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index b3d290c1b513..a3d81ebf6d86 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -459,37 +459,11 @@ static void fat_evict_inode(struct inode *inode)
459 fat_detach(inode); 459 fat_detach(inode);
460} 460}
461 461
462static void fat_write_super(struct super_block *sb)
463{
464 lock_super(sb);
465 sb->s_dirt = 0;
466
467 if (!(sb->s_flags & MS_RDONLY))
468 fat_clusters_flush(sb);
469 unlock_super(sb);
470}
471
472static int fat_sync_fs(struct super_block *sb, int wait)
473{
474 int err = 0;
475
476 if (sb->s_dirt) {
477 lock_super(sb);
478 sb->s_dirt = 0;
479 err = fat_clusters_flush(sb);
480 unlock_super(sb);
481 }
482
483 return err;
484}
485
486static void fat_put_super(struct super_block *sb) 462static void fat_put_super(struct super_block *sb)
487{ 463{
488 struct msdos_sb_info *sbi = MSDOS_SB(sb); 464 struct msdos_sb_info *sbi = MSDOS_SB(sb);
489 465
490 if (sb->s_dirt) 466 iput(sbi->fsinfo_inode);
491 fat_write_super(sb);
492
493 iput(sbi->fat_inode); 467 iput(sbi->fat_inode);
494 468
495 unload_nls(sbi->nls_disk); 469 unload_nls(sbi->nls_disk);
@@ -661,7 +635,18 @@ retry:
661 635
662static int fat_write_inode(struct inode *inode, struct writeback_control *wbc) 636static int fat_write_inode(struct inode *inode, struct writeback_control *wbc)
663{ 637{
664 return __fat_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL); 638 int err;
639
640 if (inode->i_ino == MSDOS_FSINFO_INO) {
641 struct super_block *sb = inode->i_sb;
642
643 lock_super(sb);
644 err = fat_clusters_flush(sb);
645 unlock_super(sb);
646 } else
647 err = __fat_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
648
649 return err;
665} 650}
666 651
667int fat_sync_inode(struct inode *inode) 652int fat_sync_inode(struct inode *inode)
@@ -678,8 +663,6 @@ static const struct super_operations fat_sops = {
678 .write_inode = fat_write_inode, 663 .write_inode = fat_write_inode,
679 .evict_inode = fat_evict_inode, 664 .evict_inode = fat_evict_inode,
680 .put_super = fat_put_super, 665 .put_super = fat_put_super,
681 .write_super = fat_write_super,
682 .sync_fs = fat_sync_fs,
683 .statfs = fat_statfs, 666 .statfs = fat_statfs,
684 .remount_fs = fat_remount, 667 .remount_fs = fat_remount,
685 668
@@ -752,10 +735,9 @@ static struct dentry *fat_fh_to_dentry(struct super_block *sb,
752} 735}
753 736
754static int 737static int
755fat_encode_fh(struct dentry *de, __u32 *fh, int *lenp, int connectable) 738fat_encode_fh(struct inode *inode, __u32 *fh, int *lenp, struct inode *parent)
756{ 739{
757 int len = *lenp; 740 int len = *lenp;
758 struct inode *inode = de->d_inode;
759 u32 ipos_h, ipos_m, ipos_l; 741 u32 ipos_h, ipos_m, ipos_l;
760 742
761 if (len < 5) { 743 if (len < 5) {
@@ -771,9 +753,9 @@ fat_encode_fh(struct dentry *de, __u32 *fh, int *lenp, int connectable)
771 fh[1] = inode->i_generation; 753 fh[1] = inode->i_generation;
772 fh[2] = ipos_h; 754 fh[2] = ipos_h;
773 fh[3] = ipos_m | MSDOS_I(inode)->i_logstart; 755 fh[3] = ipos_m | MSDOS_I(inode)->i_logstart;
774 spin_lock(&de->d_lock); 756 fh[4] = ipos_l;
775 fh[4] = ipos_l | MSDOS_I(de->d_parent->d_inode)->i_logstart; 757 if (parent)
776 spin_unlock(&de->d_lock); 758 fh[4] |= MSDOS_I(parent)->i_logstart;
777 return 3; 759 return 3;
778} 760}
779 761
@@ -1244,6 +1226,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
1244 void (*setup)(struct super_block *)) 1226 void (*setup)(struct super_block *))
1245{ 1227{
1246 struct inode *root_inode = NULL, *fat_inode = NULL; 1228 struct inode *root_inode = NULL, *fat_inode = NULL;
1229 struct inode *fsinfo_inode = NULL;
1247 struct buffer_head *bh; 1230 struct buffer_head *bh;
1248 struct fat_boot_sector *b; 1231 struct fat_boot_sector *b;
1249 struct msdos_sb_info *sbi; 1232 struct msdos_sb_info *sbi;
@@ -1490,6 +1473,14 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
1490 goto out_fail; 1473 goto out_fail;
1491 MSDOS_I(fat_inode)->i_pos = 0; 1474 MSDOS_I(fat_inode)->i_pos = 0;
1492 sbi->fat_inode = fat_inode; 1475 sbi->fat_inode = fat_inode;
1476
1477 fsinfo_inode = new_inode(sb);
1478 if (!fsinfo_inode)
1479 goto out_fail;
1480 fsinfo_inode->i_ino = MSDOS_FSINFO_INO;
1481 sbi->fsinfo_inode = fsinfo_inode;
1482 insert_inode_hash(fsinfo_inode);
1483
1493 root_inode = new_inode(sb); 1484 root_inode = new_inode(sb);
1494 if (!root_inode) 1485 if (!root_inode)
1495 goto out_fail; 1486 goto out_fail;
@@ -1516,6 +1507,8 @@ out_invalid:
1516 fat_msg(sb, KERN_INFO, "Can't find a valid FAT filesystem"); 1507 fat_msg(sb, KERN_INFO, "Can't find a valid FAT filesystem");
1517 1508
1518out_fail: 1509out_fail:
1510 if (fsinfo_inode)
1511 iput(fsinfo_inode);
1519 if (fat_inode) 1512 if (fat_inode)
1520 iput(fat_inode); 1513 iput(fat_inode);
1521 unload_nls(sbi->nls_io); 1514 unload_nls(sbi->nls_io);
diff --git a/fs/fcntl.c b/fs/fcntl.c
index d078b75572a7..81b70e665bf0 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -442,28 +442,24 @@ static int check_fcntl_cmd(unsigned cmd)
442SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) 442SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
443{ 443{
444 struct file *filp; 444 struct file *filp;
445 int fput_needed;
445 long err = -EBADF; 446 long err = -EBADF;
446 447
447 filp = fget_raw(fd); 448 filp = fget_raw_light(fd, &fput_needed);
448 if (!filp) 449 if (!filp)
449 goto out; 450 goto out;
450 451
451 if (unlikely(filp->f_mode & FMODE_PATH)) { 452 if (unlikely(filp->f_mode & FMODE_PATH)) {
452 if (!check_fcntl_cmd(cmd)) { 453 if (!check_fcntl_cmd(cmd))
453 fput(filp); 454 goto out1;
454 goto out;
455 }
456 } 455 }
457 456
458 err = security_file_fcntl(filp, cmd, arg); 457 err = security_file_fcntl(filp, cmd, arg);
459 if (err) { 458 if (!err)
460 fput(filp); 459 err = do_fcntl(fd, cmd, arg, filp);
461 return err;
462 }
463 460
464 err = do_fcntl(fd, cmd, arg, filp); 461out1:
465 462 fput_light(filp, fput_needed);
466 fput(filp);
467out: 463out:
468 return err; 464 return err;
469} 465}
@@ -473,26 +469,21 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
473 unsigned long, arg) 469 unsigned long, arg)
474{ 470{
475 struct file * filp; 471 struct file * filp;
476 long err; 472 long err = -EBADF;
473 int fput_needed;
477 474
478 err = -EBADF; 475 filp = fget_raw_light(fd, &fput_needed);
479 filp = fget_raw(fd);
480 if (!filp) 476 if (!filp)
481 goto out; 477 goto out;
482 478
483 if (unlikely(filp->f_mode & FMODE_PATH)) { 479 if (unlikely(filp->f_mode & FMODE_PATH)) {
484 if (!check_fcntl_cmd(cmd)) { 480 if (!check_fcntl_cmd(cmd))
485 fput(filp); 481 goto out1;
486 goto out;
487 }
488 } 482 }
489 483
490 err = security_file_fcntl(filp, cmd, arg); 484 err = security_file_fcntl(filp, cmd, arg);
491 if (err) { 485 if (err)
492 fput(filp); 486 goto out1;
493 return err;
494 }
495 err = -EBADF;
496 487
497 switch (cmd) { 488 switch (cmd) {
498 case F_GETLK64: 489 case F_GETLK64:
@@ -507,7 +498,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
507 err = do_fcntl(fd, cmd, arg, filp); 498 err = do_fcntl(fd, cmd, arg, filp);
508 break; 499 break;
509 } 500 }
510 fput(filp); 501out1:
502 fput_light(filp, fput_needed);
511out: 503out:
512 return err; 504 return err;
513} 505}
diff --git a/fs/file_table.c b/fs/file_table.c
index 70f2a0fd6aec..a305d9e2d1b2 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -34,7 +34,6 @@ struct files_stat_struct files_stat = {
34 .max_files = NR_FILE 34 .max_files = NR_FILE
35}; 35};
36 36
37DECLARE_LGLOCK(files_lglock);
38DEFINE_LGLOCK(files_lglock); 37DEFINE_LGLOCK(files_lglock);
39 38
40/* SLAB cache for file structures */ 39/* SLAB cache for file structures */
@@ -421,9 +420,9 @@ static inline void __file_sb_list_add(struct file *file, struct super_block *sb)
421 */ 420 */
422void file_sb_list_add(struct file *file, struct super_block *sb) 421void file_sb_list_add(struct file *file, struct super_block *sb)
423{ 422{
424 lg_local_lock(files_lglock); 423 lg_local_lock(&files_lglock);
425 __file_sb_list_add(file, sb); 424 __file_sb_list_add(file, sb);
426 lg_local_unlock(files_lglock); 425 lg_local_unlock(&files_lglock);
427} 426}
428 427
429/** 428/**
@@ -436,9 +435,9 @@ void file_sb_list_add(struct file *file, struct super_block *sb)
436void file_sb_list_del(struct file *file) 435void file_sb_list_del(struct file *file)
437{ 436{
438 if (!list_empty(&file->f_u.fu_list)) { 437 if (!list_empty(&file->f_u.fu_list)) {
439 lg_local_lock_cpu(files_lglock, file_list_cpu(file)); 438 lg_local_lock_cpu(&files_lglock, file_list_cpu(file));
440 list_del_init(&file->f_u.fu_list); 439 list_del_init(&file->f_u.fu_list);
441 lg_local_unlock_cpu(files_lglock, file_list_cpu(file)); 440 lg_local_unlock_cpu(&files_lglock, file_list_cpu(file));
442 } 441 }
443} 442}
444 443
@@ -485,7 +484,7 @@ void mark_files_ro(struct super_block *sb)
485 struct file *f; 484 struct file *f;
486 485
487retry: 486retry:
488 lg_global_lock(files_lglock); 487 lg_global_lock(&files_lglock);
489 do_file_list_for_each_entry(sb, f) { 488 do_file_list_for_each_entry(sb, f) {
490 struct vfsmount *mnt; 489 struct vfsmount *mnt;
491 if (!S_ISREG(f->f_path.dentry->d_inode->i_mode)) 490 if (!S_ISREG(f->f_path.dentry->d_inode->i_mode))
@@ -502,12 +501,12 @@ retry:
502 file_release_write(f); 501 file_release_write(f);
503 mnt = mntget(f->f_path.mnt); 502 mnt = mntget(f->f_path.mnt);
504 /* This can sleep, so we can't hold the spinlock. */ 503 /* This can sleep, so we can't hold the spinlock. */
505 lg_global_unlock(files_lglock); 504 lg_global_unlock(&files_lglock);
506 mnt_drop_write(mnt); 505 mnt_drop_write(mnt);
507 mntput(mnt); 506 mntput(mnt);
508 goto retry; 507 goto retry;
509 } while_file_list_for_each_entry; 508 } while_file_list_for_each_entry;
510 lg_global_unlock(files_lglock); 509 lg_global_unlock(&files_lglock);
511} 510}
512 511
513void __init files_init(unsigned long mempages) 512void __init files_init(unsigned long mempages)
@@ -525,6 +524,6 @@ void __init files_init(unsigned long mempages)
525 n = (mempages * (PAGE_SIZE / 1024)) / 10; 524 n = (mempages * (PAGE_SIZE / 1024)) / 10;
526 files_stat.max_files = max_t(unsigned long, n, NR_FILE); 525 files_stat.max_files = max_t(unsigned long, n, NR_FILE);
527 files_defer_init(); 526 files_defer_init();
528 lg_lock_init(files_lglock); 527 lg_lock_init(&files_lglock, "files_lglock");
529 percpu_counter_init(&nr_files, 0); 528 percpu_counter_init(&nr_files, 0);
530} 529}
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 504e61b7fd75..9562109d3a87 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -962,7 +962,9 @@ static ssize_t fuse_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
962 if (err) 962 if (err)
963 goto out; 963 goto out;
964 964
965 file_update_time(file); 965 err = file_update_time(file);
966 if (err)
967 goto out;
966 968
967 if (file->f_flags & O_DIRECT) { 969 if (file->f_flags & O_DIRECT) {
968 written = generic_file_direct_write(iocb, iov, &nr_segs, 970 written = generic_file_direct_write(iocb, iov, &nr_segs,
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 56f6dcf30768..42678a33b7bb 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -627,12 +627,10 @@ static struct dentry *fuse_get_dentry(struct super_block *sb,
627 return ERR_PTR(err); 627 return ERR_PTR(err);
628} 628}
629 629
630static int fuse_encode_fh(struct dentry *dentry, u32 *fh, int *max_len, 630static int fuse_encode_fh(struct inode *inode, u32 *fh, int *max_len,
631 int connectable) 631 struct inode *parent)
632{ 632{
633 struct inode *inode = dentry->d_inode; 633 int len = parent ? 6 : 3;
634 bool encode_parent = connectable && !S_ISDIR(inode->i_mode);
635 int len = encode_parent ? 6 : 3;
636 u64 nodeid; 634 u64 nodeid;
637 u32 generation; 635 u32 generation;
638 636
@@ -648,14 +646,9 @@ static int fuse_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
648 fh[1] = (u32)(nodeid & 0xffffffff); 646 fh[1] = (u32)(nodeid & 0xffffffff);
649 fh[2] = generation; 647 fh[2] = generation;
650 648
651 if (encode_parent) { 649 if (parent) {
652 struct inode *parent;
653
654 spin_lock(&dentry->d_lock);
655 parent = dentry->d_parent->d_inode;
656 nodeid = get_fuse_inode(parent)->nodeid; 650 nodeid = get_fuse_inode(parent)->nodeid;
657 generation = parent->i_generation; 651 generation = parent->i_generation;
658 spin_unlock(&dentry->d_lock);
659 652
660 fh[3] = (u32)(nodeid >> 32); 653 fh[3] = (u32)(nodeid >> 32);
661 fh[4] = (u32)(nodeid & 0xffffffff); 654 fh[4] = (u32)(nodeid & 0xffffffff);
@@ -663,7 +656,7 @@ static int fuse_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
663 } 656 }
664 657
665 *max_len = len; 658 *max_len = len;
666 return encode_parent ? 0x82 : 0x81; 659 return parent ? 0x82 : 0x81;
667} 660}
668 661
669static struct dentry *fuse_fh_to_dentry(struct super_block *sb, 662static struct dentry *fuse_fh_to_dentry(struct super_block *sb,
diff --git a/fs/gfs2/export.c b/fs/gfs2/export.c
index 70ba891654f8..e8ed6d4a6181 100644
--- a/fs/gfs2/export.c
+++ b/fs/gfs2/export.c
@@ -28,15 +28,14 @@
28#define GFS2_LARGE_FH_SIZE 8 28#define GFS2_LARGE_FH_SIZE 8
29#define GFS2_OLD_FH_SIZE 10 29#define GFS2_OLD_FH_SIZE 10
30 30
31static int gfs2_encode_fh(struct dentry *dentry, __u32 *p, int *len, 31static int gfs2_encode_fh(struct inode *inode, __u32 *p, int *len,
32 int connectable) 32 struct inode *parent)
33{ 33{
34 __be32 *fh = (__force __be32 *)p; 34 __be32 *fh = (__force __be32 *)p;
35 struct inode *inode = dentry->d_inode;
36 struct super_block *sb = inode->i_sb; 35 struct super_block *sb = inode->i_sb;
37 struct gfs2_inode *ip = GFS2_I(inode); 36 struct gfs2_inode *ip = GFS2_I(inode);
38 37
39 if (connectable && (*len < GFS2_LARGE_FH_SIZE)) { 38 if (parent && (*len < GFS2_LARGE_FH_SIZE)) {
40 *len = GFS2_LARGE_FH_SIZE; 39 *len = GFS2_LARGE_FH_SIZE;
41 return 255; 40 return 255;
42 } else if (*len < GFS2_SMALL_FH_SIZE) { 41 } else if (*len < GFS2_SMALL_FH_SIZE) {
@@ -50,14 +49,10 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *p, int *len,
50 fh[3] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF); 49 fh[3] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF);
51 *len = GFS2_SMALL_FH_SIZE; 50 *len = GFS2_SMALL_FH_SIZE;
52 51
53 if (!connectable || inode == sb->s_root->d_inode) 52 if (!parent || inode == sb->s_root->d_inode)
54 return *len; 53 return *len;
55 54
56 spin_lock(&dentry->d_lock); 55 ip = GFS2_I(parent);
57 inode = dentry->d_parent->d_inode;
58 ip = GFS2_I(inode);
59 igrab(inode);
60 spin_unlock(&dentry->d_lock);
61 56
62 fh[4] = cpu_to_be32(ip->i_no_formal_ino >> 32); 57 fh[4] = cpu_to_be32(ip->i_no_formal_ino >> 32);
63 fh[5] = cpu_to_be32(ip->i_no_formal_ino & 0xFFFFFFFF); 58 fh[5] = cpu_to_be32(ip->i_no_formal_ino & 0xFFFFFFFF);
@@ -65,8 +60,6 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *p, int *len,
65 fh[7] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF); 60 fh[7] = cpu_to_be32(ip->i_no_addr & 0xFFFFFFFF);
66 *len = GFS2_LARGE_FH_SIZE; 61 *len = GFS2_LARGE_FH_SIZE;
67 62
68 iput(inode);
69
70 return *len; 63 return *len;
71} 64}
72 65
diff --git a/fs/hpfs/alloc.c b/fs/hpfs/alloc.c
index 7a5eb2c718c8..cdb84a838068 100644
--- a/fs/hpfs/alloc.c
+++ b/fs/hpfs/alloc.c
@@ -16,9 +16,9 @@
16static int chk_if_allocated(struct super_block *s, secno sec, char *msg) 16static int chk_if_allocated(struct super_block *s, secno sec, char *msg)
17{ 17{
18 struct quad_buffer_head qbh; 18 struct quad_buffer_head qbh;
19 u32 *bmp; 19 __le32 *bmp;
20 if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "chk"))) goto fail; 20 if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "chk"))) goto fail;
21 if ((cpu_to_le32(bmp[(sec & 0x3fff) >> 5]) >> (sec & 0x1f)) & 1) { 21 if ((le32_to_cpu(bmp[(sec & 0x3fff) >> 5]) >> (sec & 0x1f)) & 1) {
22 hpfs_error(s, "sector '%s' - %08x not allocated in bitmap", msg, sec); 22 hpfs_error(s, "sector '%s' - %08x not allocated in bitmap", msg, sec);
23 goto fail1; 23 goto fail1;
24 } 24 }
@@ -62,7 +62,7 @@ int hpfs_chk_sectors(struct super_block *s, secno start, int len, char *msg)
62static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigned forward) 62static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigned forward)
63{ 63{
64 struct quad_buffer_head qbh; 64 struct quad_buffer_head qbh;
65 unsigned *bmp; 65 __le32 *bmp;
66 unsigned bs = near & ~0x3fff; 66 unsigned bs = near & ~0x3fff;
67 unsigned nr = (near & 0x3fff) & ~(n - 1); 67 unsigned nr = (near & 0x3fff) & ~(n - 1);
68 /*unsigned mnr;*/ 68 /*unsigned mnr;*/
@@ -236,7 +236,7 @@ static secno alloc_in_dirband(struct super_block *s, secno near)
236int hpfs_alloc_if_possible(struct super_block *s, secno sec) 236int hpfs_alloc_if_possible(struct super_block *s, secno sec)
237{ 237{
238 struct quad_buffer_head qbh; 238 struct quad_buffer_head qbh;
239 u32 *bmp; 239 __le32 *bmp;
240 if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "aip"))) goto end; 240 if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "aip"))) goto end;
241 if (le32_to_cpu(bmp[(sec & 0x3fff) >> 5]) & (1 << (sec & 0x1f))) { 241 if (le32_to_cpu(bmp[(sec & 0x3fff) >> 5]) & (1 << (sec & 0x1f))) {
242 bmp[(sec & 0x3fff) >> 5] &= cpu_to_le32(~(1 << (sec & 0x1f))); 242 bmp[(sec & 0x3fff) >> 5] &= cpu_to_le32(~(1 << (sec & 0x1f)));
@@ -254,7 +254,7 @@ int hpfs_alloc_if_possible(struct super_block *s, secno sec)
254void hpfs_free_sectors(struct super_block *s, secno sec, unsigned n) 254void hpfs_free_sectors(struct super_block *s, secno sec, unsigned n)
255{ 255{
256 struct quad_buffer_head qbh; 256 struct quad_buffer_head qbh;
257 u32 *bmp; 257 __le32 *bmp;
258 struct hpfs_sb_info *sbi = hpfs_sb(s); 258 struct hpfs_sb_info *sbi = hpfs_sb(s);
259 /*printk("2 - ");*/ 259 /*printk("2 - ");*/
260 if (!n) return; 260 if (!n) return;
@@ -299,7 +299,7 @@ int hpfs_check_free_dnodes(struct super_block *s, int n)
299 int n_bmps = (hpfs_sb(s)->sb_fs_size + 0x4000 - 1) >> 14; 299 int n_bmps = (hpfs_sb(s)->sb_fs_size + 0x4000 - 1) >> 14;
300 int b = hpfs_sb(s)->sb_c_bitmap & 0x0fffffff; 300 int b = hpfs_sb(s)->sb_c_bitmap & 0x0fffffff;
301 int i, j; 301 int i, j;
302 u32 *bmp; 302 __le32 *bmp;
303 struct quad_buffer_head qbh; 303 struct quad_buffer_head qbh;
304 if ((bmp = hpfs_map_dnode_bitmap(s, &qbh))) { 304 if ((bmp = hpfs_map_dnode_bitmap(s, &qbh))) {
305 for (j = 0; j < 512; j++) { 305 for (j = 0; j < 512; j++) {
@@ -351,7 +351,7 @@ void hpfs_free_dnode(struct super_block *s, dnode_secno dno)
351 hpfs_free_sectors(s, dno, 4); 351 hpfs_free_sectors(s, dno, 4);
352 } else { 352 } else {
353 struct quad_buffer_head qbh; 353 struct quad_buffer_head qbh;
354 u32 *bmp; 354 __le32 *bmp;
355 unsigned ssec = (dno - hpfs_sb(s)->sb_dirband_start) / 4; 355 unsigned ssec = (dno - hpfs_sb(s)->sb_dirband_start) / 4;
356 if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) { 356 if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) {
357 return; 357 return;
diff --git a/fs/hpfs/anode.c b/fs/hpfs/anode.c
index 08b503e8ed29..4bae4a4a60b1 100644
--- a/fs/hpfs/anode.c
+++ b/fs/hpfs/anode.c
@@ -20,7 +20,7 @@ secno hpfs_bplus_lookup(struct super_block *s, struct inode *inode,
20 int c1, c2 = 0; 20 int c1, c2 = 0;
21 go_down: 21 go_down:
22 if (hpfs_sb(s)->sb_chk) if (hpfs_stop_cycles(s, a, &c1, &c2, "hpfs_bplus_lookup")) return -1; 22 if (hpfs_sb(s)->sb_chk) if (hpfs_stop_cycles(s, a, &c1, &c2, "hpfs_bplus_lookup")) return -1;
23 if (btree->internal) { 23 if (bp_internal(btree)) {
24 for (i = 0; i < btree->n_used_nodes; i++) 24 for (i = 0; i < btree->n_used_nodes; i++)
25 if (le32_to_cpu(btree->u.internal[i].file_secno) > sec) { 25 if (le32_to_cpu(btree->u.internal[i].file_secno) > sec) {
26 a = le32_to_cpu(btree->u.internal[i].down); 26 a = le32_to_cpu(btree->u.internal[i].down);
@@ -82,7 +82,7 @@ secno hpfs_add_sector_to_btree(struct super_block *s, secno node, int fnod, unsi
82 brelse(bh); 82 brelse(bh);
83 return -1; 83 return -1;
84 } 84 }
85 if (btree->internal) { 85 if (bp_internal(btree)) {
86 a = le32_to_cpu(btree->u.internal[n].down); 86 a = le32_to_cpu(btree->u.internal[n].down);
87 btree->u.internal[n].file_secno = cpu_to_le32(-1); 87 btree->u.internal[n].file_secno = cpu_to_le32(-1);
88 mark_buffer_dirty(bh); 88 mark_buffer_dirty(bh);
@@ -129,12 +129,12 @@ secno hpfs_add_sector_to_btree(struct super_block *s, secno node, int fnod, unsi
129 } 129 }
130 if (a == node && fnod) { 130 if (a == node && fnod) {
131 anode->up = cpu_to_le32(node); 131 anode->up = cpu_to_le32(node);
132 anode->btree.fnode_parent = 1; 132 anode->btree.flags |= BP_fnode_parent;
133 anode->btree.n_used_nodes = btree->n_used_nodes; 133 anode->btree.n_used_nodes = btree->n_used_nodes;
134 anode->btree.first_free = btree->first_free; 134 anode->btree.first_free = btree->first_free;
135 anode->btree.n_free_nodes = 40 - anode->btree.n_used_nodes; 135 anode->btree.n_free_nodes = 40 - anode->btree.n_used_nodes;
136 memcpy(&anode->u, &btree->u, btree->n_used_nodes * 12); 136 memcpy(&anode->u, &btree->u, btree->n_used_nodes * 12);
137 btree->internal = 1; 137 btree->flags |= BP_internal;
138 btree->n_free_nodes = 11; 138 btree->n_free_nodes = 11;
139 btree->n_used_nodes = 1; 139 btree->n_used_nodes = 1;
140 btree->first_free = cpu_to_le16((char *)&(btree->u.internal[1]) - (char *)btree); 140 btree->first_free = cpu_to_le16((char *)&(btree->u.internal[1]) - (char *)btree);
@@ -184,7 +184,10 @@ secno hpfs_add_sector_to_btree(struct super_block *s, secno node, int fnod, unsi
184 hpfs_free_sectors(s, ra, 1); 184 hpfs_free_sectors(s, ra, 1);
185 if ((anode = hpfs_map_anode(s, na, &bh))) { 185 if ((anode = hpfs_map_anode(s, na, &bh))) {
186 anode->up = cpu_to_le32(up); 186 anode->up = cpu_to_le32(up);
187 anode->btree.fnode_parent = up == node && fnod; 187 if (up == node && fnod)
188 anode->btree.flags |= BP_fnode_parent;
189 else
190 anode->btree.flags &= ~BP_fnode_parent;
188 mark_buffer_dirty(bh); 191 mark_buffer_dirty(bh);
189 brelse(bh); 192 brelse(bh);
190 } 193 }
@@ -198,7 +201,7 @@ secno hpfs_add_sector_to_btree(struct super_block *s, secno node, int fnod, unsi
198 if ((new_anode = hpfs_alloc_anode(s, a, &na, &bh))) { 201 if ((new_anode = hpfs_alloc_anode(s, a, &na, &bh))) {
199 anode = new_anode; 202 anode = new_anode;
200 /*anode->up = cpu_to_le32(up != -1 ? up : ra);*/ 203 /*anode->up = cpu_to_le32(up != -1 ? up : ra);*/
201 anode->btree.internal = 1; 204 anode->btree.flags |= BP_internal;
202 anode->btree.n_used_nodes = 1; 205 anode->btree.n_used_nodes = 1;
203 anode->btree.n_free_nodes = 59; 206 anode->btree.n_free_nodes = 59;
204 anode->btree.first_free = cpu_to_le16(16); 207 anode->btree.first_free = cpu_to_le16(16);
@@ -215,7 +218,8 @@ secno hpfs_add_sector_to_btree(struct super_block *s, secno node, int fnod, unsi
215 } 218 }
216 if ((anode = hpfs_map_anode(s, na, &bh))) { 219 if ((anode = hpfs_map_anode(s, na, &bh))) {
217 anode->up = cpu_to_le32(node); 220 anode->up = cpu_to_le32(node);
218 if (fnod) anode->btree.fnode_parent = 1; 221 if (fnod)
222 anode->btree.flags |= BP_fnode_parent;
219 mark_buffer_dirty(bh); 223 mark_buffer_dirty(bh);
220 brelse(bh); 224 brelse(bh);
221 } 225 }
@@ -234,18 +238,19 @@ secno hpfs_add_sector_to_btree(struct super_block *s, secno node, int fnod, unsi
234 } 238 }
235 ranode->up = cpu_to_le32(node); 239 ranode->up = cpu_to_le32(node);
236 memcpy(&ranode->btree, btree, le16_to_cpu(btree->first_free)); 240 memcpy(&ranode->btree, btree, le16_to_cpu(btree->first_free));
237 if (fnod) ranode->btree.fnode_parent = 1; 241 if (fnod)
238 ranode->btree.n_free_nodes = (ranode->btree.internal ? 60 : 40) - ranode->btree.n_used_nodes; 242 ranode->btree.flags |= BP_fnode_parent;
239 if (ranode->btree.internal) for (n = 0; n < ranode->btree.n_used_nodes; n++) { 243 ranode->btree.n_free_nodes = (bp_internal(&ranode->btree) ? 60 : 40) - ranode->btree.n_used_nodes;
244 if (bp_internal(&ranode->btree)) for (n = 0; n < ranode->btree.n_used_nodes; n++) {
240 struct anode *unode; 245 struct anode *unode;
241 if ((unode = hpfs_map_anode(s, le32_to_cpu(ranode->u.internal[n].down), &bh1))) { 246 if ((unode = hpfs_map_anode(s, le32_to_cpu(ranode->u.internal[n].down), &bh1))) {
242 unode->up = cpu_to_le32(ra); 247 unode->up = cpu_to_le32(ra);
243 unode->btree.fnode_parent = 0; 248 unode->btree.flags &= ~BP_fnode_parent;
244 mark_buffer_dirty(bh1); 249 mark_buffer_dirty(bh1);
245 brelse(bh1); 250 brelse(bh1);
246 } 251 }
247 } 252 }
248 btree->internal = 1; 253 btree->flags |= BP_internal;
249 btree->n_free_nodes = fnod ? 10 : 58; 254 btree->n_free_nodes = fnod ? 10 : 58;
250 btree->n_used_nodes = 2; 255 btree->n_used_nodes = 2;
251 btree->first_free = cpu_to_le16((char *)&btree->u.internal[2] - (char *)btree); 256 btree->first_free = cpu_to_le16((char *)&btree->u.internal[2] - (char *)btree);
@@ -278,7 +283,7 @@ void hpfs_remove_btree(struct super_block *s, struct bplus_header *btree)
278 int d1, d2; 283 int d1, d2;
279 go_down: 284 go_down:
280 d2 = 0; 285 d2 = 0;
281 while (btree1->internal) { 286 while (bp_internal(btree1)) {
282 ano = le32_to_cpu(btree1->u.internal[pos].down); 287 ano = le32_to_cpu(btree1->u.internal[pos].down);
283 if (level) brelse(bh); 288 if (level) brelse(bh);
284 if (hpfs_sb(s)->sb_chk) 289 if (hpfs_sb(s)->sb_chk)
@@ -412,13 +417,13 @@ void hpfs_truncate_btree(struct super_block *s, secno f, int fno, unsigned secs)
412 btree->n_free_nodes = 8; 417 btree->n_free_nodes = 8;
413 btree->n_used_nodes = 0; 418 btree->n_used_nodes = 0;
414 btree->first_free = cpu_to_le16(8); 419 btree->first_free = cpu_to_le16(8);
415 btree->internal = 0; 420 btree->flags &= ~BP_internal;
416 mark_buffer_dirty(bh); 421 mark_buffer_dirty(bh);
417 } else hpfs_free_sectors(s, f, 1); 422 } else hpfs_free_sectors(s, f, 1);
418 brelse(bh); 423 brelse(bh);
419 return; 424 return;
420 } 425 }
421 while (btree->internal) { 426 while (bp_internal(btree)) {
422 nodes = btree->n_used_nodes + btree->n_free_nodes; 427 nodes = btree->n_used_nodes + btree->n_free_nodes;
423 for (i = 0; i < btree->n_used_nodes; i++) 428 for (i = 0; i < btree->n_used_nodes; i++)
424 if (le32_to_cpu(btree->u.internal[i].file_secno) >= secs) goto f; 429 if (le32_to_cpu(btree->u.internal[i].file_secno) >= secs) goto f;
@@ -479,13 +484,13 @@ void hpfs_remove_fnode(struct super_block *s, fnode_secno fno)
479 struct extended_attribute *ea; 484 struct extended_attribute *ea;
480 struct extended_attribute *ea_end; 485 struct extended_attribute *ea_end;
481 if (!(fnode = hpfs_map_fnode(s, fno, &bh))) return; 486 if (!(fnode = hpfs_map_fnode(s, fno, &bh))) return;
482 if (!fnode->dirflag) hpfs_remove_btree(s, &fnode->btree); 487 if (!fnode_is_dir(fnode)) hpfs_remove_btree(s, &fnode->btree);
483 else hpfs_remove_dtree(s, le32_to_cpu(fnode->u.external[0].disk_secno)); 488 else hpfs_remove_dtree(s, le32_to_cpu(fnode->u.external[0].disk_secno));
484 ea_end = fnode_end_ea(fnode); 489 ea_end = fnode_end_ea(fnode);
485 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea)) 490 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
486 if (ea->indirect) 491 if (ea_indirect(ea))
487 hpfs_ea_remove(s, ea_sec(ea), ea->anode, ea_len(ea)); 492 hpfs_ea_remove(s, ea_sec(ea), ea_in_anode(ea), ea_len(ea));
488 hpfs_ea_ext_remove(s, le32_to_cpu(fnode->ea_secno), fnode->ea_anode, le32_to_cpu(fnode->ea_size_l)); 493 hpfs_ea_ext_remove(s, le32_to_cpu(fnode->ea_secno), fnode_in_anode(fnode), le32_to_cpu(fnode->ea_size_l));
489 brelse(bh); 494 brelse(bh);
490 hpfs_free_sectors(s, fno, 1); 495 hpfs_free_sectors(s, fno, 1);
491} 496}
diff --git a/fs/hpfs/buffer.c b/fs/hpfs/buffer.c
index 9ecde27d1e29..f49d1498aa2e 100644
--- a/fs/hpfs/buffer.c
+++ b/fs/hpfs/buffer.c
@@ -156,7 +156,6 @@ void hpfs_brelse4(struct quad_buffer_head *qbh)
156 156
157void hpfs_mark_4buffers_dirty(struct quad_buffer_head *qbh) 157void hpfs_mark_4buffers_dirty(struct quad_buffer_head *qbh)
158{ 158{
159 PRINTK(("hpfs_mark_4buffers_dirty\n"));
160 memcpy(qbh->bh[0]->b_data, qbh->data, 512); 159 memcpy(qbh->bh[0]->b_data, qbh->data, 512);
161 memcpy(qbh->bh[1]->b_data, qbh->data + 512, 512); 160 memcpy(qbh->bh[1]->b_data, qbh->data + 512, 512);
162 memcpy(qbh->bh[2]->b_data, qbh->data + 2 * 512, 512); 161 memcpy(qbh->bh[2]->b_data, qbh->data + 2 * 512, 512);
diff --git a/fs/hpfs/dir.c b/fs/hpfs/dir.c
index 2fa0089a02a8..b8472f803f4e 100644
--- a/fs/hpfs/dir.c
+++ b/fs/hpfs/dir.c
@@ -87,7 +87,7 @@ static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
87 ret = -EIOERROR; 87 ret = -EIOERROR;
88 goto out; 88 goto out;
89 } 89 }
90 if (!fno->dirflag) { 90 if (!fnode_is_dir(fno)) {
91 e = 1; 91 e = 1;
92 hpfs_error(inode->i_sb, "not a directory, fnode %08lx", 92 hpfs_error(inode->i_sb, "not a directory, fnode %08lx",
93 (unsigned long)inode->i_ino); 93 (unsigned long)inode->i_ino);
diff --git a/fs/hpfs/dnode.c b/fs/hpfs/dnode.c
index 1e0e2ac30fd3..3228c524ebe5 100644
--- a/fs/hpfs/dnode.c
+++ b/fs/hpfs/dnode.c
@@ -153,7 +153,7 @@ static void set_last_pointer(struct super_block *s, struct dnode *d, dnode_secno
153 } 153 }
154 de->length = cpu_to_le16(36); 154 de->length = cpu_to_le16(36);
155 de->down = 1; 155 de->down = 1;
156 *(dnode_secno *)((char *)de + 32) = cpu_to_le32(ptr); 156 *(__le32 *)((char *)de + 32) = cpu_to_le32(ptr);
157 } 157 }
158} 158}
159 159
@@ -177,7 +177,7 @@ struct hpfs_dirent *hpfs_add_de(struct super_block *s, struct dnode *d,
177 memmove((char *)de + d_size, de, (char *)de_end - (char *)de); 177 memmove((char *)de + d_size, de, (char *)de_end - (char *)de);
178 memset(de, 0, d_size); 178 memset(de, 0, d_size);
179 if (down_ptr) { 179 if (down_ptr) {
180 *(dnode_secno *)((char *)de + d_size - 4) = cpu_to_le32(down_ptr); 180 *(__le32 *)((char *)de + d_size - 4) = cpu_to_le32(down_ptr);
181 de->down = 1; 181 de->down = 1;
182 } 182 }
183 de->length = cpu_to_le16(d_size); 183 de->length = cpu_to_le16(d_size);
@@ -656,7 +656,7 @@ static void delete_empty_dnode(struct inode *i, dnode_secno dno)
656 del->down = 0; 656 del->down = 0;
657 d1->first_free = cpu_to_le32(le32_to_cpu(d1->first_free) - 4); 657 d1->first_free = cpu_to_le32(le32_to_cpu(d1->first_free) - 4);
658 } else if (down) 658 } else if (down)
659 *(dnode_secno *) ((void *) del + le16_to_cpu(del->length) - 4) = cpu_to_le32(down); 659 *(__le32 *) ((void *) del + le16_to_cpu(del->length) - 4) = cpu_to_le32(down);
660 } else goto endm; 660 } else goto endm;
661 if (!(de_cp = kmalloc(le16_to_cpu(de_prev->length), GFP_NOFS))) { 661 if (!(de_cp = kmalloc(le16_to_cpu(de_prev->length), GFP_NOFS))) {
662 printk("HPFS: out of memory for dtree balancing\n"); 662 printk("HPFS: out of memory for dtree balancing\n");
@@ -672,7 +672,7 @@ static void delete_empty_dnode(struct inode *i, dnode_secno dno)
672 de_prev->down = 1; 672 de_prev->down = 1;
673 dnode->first_free = cpu_to_le32(le32_to_cpu(dnode->first_free) + 4); 673 dnode->first_free = cpu_to_le32(le32_to_cpu(dnode->first_free) + 4);
674 } 674 }
675 *(dnode_secno *) ((void *) de_prev + le16_to_cpu(de_prev->length) - 4) = cpu_to_le32(ndown); 675 *(__le32 *) ((void *) de_prev + le16_to_cpu(de_prev->length) - 4) = cpu_to_le32(ndown);
676 hpfs_mark_4buffers_dirty(&qbh); 676 hpfs_mark_4buffers_dirty(&qbh);
677 hpfs_brelse4(&qbh); 677 hpfs_brelse4(&qbh);
678 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | (p - 1), 4); 678 for_all_poss(i, hpfs_pos_subst, ((loff_t)up << 4) | (p - 1), 4);
@@ -1015,7 +1015,7 @@ struct hpfs_dirent *map_fnode_dirent(struct super_block *s, fnode_secno fno,
1015 kfree(name2); 1015 kfree(name2);
1016 return NULL; 1016 return NULL;
1017 } 1017 }
1018 if (!upf->dirflag) { 1018 if (!fnode_is_dir(upf)) {
1019 brelse(bh); 1019 brelse(bh);
1020 hpfs_error(s, "fnode %08x has non-directory parent %08x", fno, le32_to_cpu(f->up)); 1020 hpfs_error(s, "fnode %08x has non-directory parent %08x", fno, le32_to_cpu(f->up));
1021 kfree(name2); 1021 kfree(name2);
diff --git a/fs/hpfs/ea.c b/fs/hpfs/ea.c
index d8b84d113c89..bcaafcd2666a 100644
--- a/fs/hpfs/ea.c
+++ b/fs/hpfs/ea.c
@@ -23,15 +23,15 @@ void hpfs_ea_ext_remove(struct super_block *s, secno a, int ano, unsigned len)
23 return; 23 return;
24 } 24 }
25 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return; 25 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return;
26 if (ea->indirect) { 26 if (ea_indirect(ea)) {
27 if (ea_valuelen(ea) != 8) { 27 if (ea_valuelen(ea) != 8) {
28 hpfs_error(s, "ea->indirect set while ea->valuelen!=8, %s %08x, pos %08x", 28 hpfs_error(s, "ea_indirect(ea) set while ea->valuelen!=8, %s %08x, pos %08x",
29 ano ? "anode" : "sectors", a, pos); 29 ano ? "anode" : "sectors", a, pos);
30 return; 30 return;
31 } 31 }
32 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 9, ex+4)) 32 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 9, ex+4))
33 return; 33 return;
34 hpfs_ea_remove(s, ea_sec(ea), ea->anode, ea_len(ea)); 34 hpfs_ea_remove(s, ea_sec(ea), ea_in_anode(ea), ea_len(ea));
35 } 35 }
36 pos += ea->namelen + ea_valuelen(ea) + 5; 36 pos += ea->namelen + ea_valuelen(ea) + 5;
37 } 37 }
@@ -81,7 +81,7 @@ int hpfs_read_ea(struct super_block *s, struct fnode *fnode, char *key,
81 struct extended_attribute *ea_end = fnode_end_ea(fnode); 81 struct extended_attribute *ea_end = fnode_end_ea(fnode);
82 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea)) 82 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
83 if (!strcmp(ea->name, key)) { 83 if (!strcmp(ea->name, key)) {
84 if (ea->indirect) 84 if (ea_indirect(ea))
85 goto indirect; 85 goto indirect;
86 if (ea_valuelen(ea) >= size) 86 if (ea_valuelen(ea) >= size)
87 return -EINVAL; 87 return -EINVAL;
@@ -91,7 +91,7 @@ int hpfs_read_ea(struct super_block *s, struct fnode *fnode, char *key,
91 } 91 }
92 a = le32_to_cpu(fnode->ea_secno); 92 a = le32_to_cpu(fnode->ea_secno);
93 len = le32_to_cpu(fnode->ea_size_l); 93 len = le32_to_cpu(fnode->ea_size_l);
94 ano = fnode->ea_anode; 94 ano = fnode_in_anode(fnode);
95 pos = 0; 95 pos = 0;
96 while (pos < len) { 96 while (pos < len) {
97 ea = (struct extended_attribute *)ex; 97 ea = (struct extended_attribute *)ex;
@@ -101,10 +101,10 @@ int hpfs_read_ea(struct super_block *s, struct fnode *fnode, char *key,
101 return -EIO; 101 return -EIO;
102 } 102 }
103 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return -EIO; 103 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return -EIO;
104 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea->indirect ? 8 : 0), ex + 4)) 104 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea_indirect(ea) ? 8 : 0), ex + 4))
105 return -EIO; 105 return -EIO;
106 if (!strcmp(ea->name, key)) { 106 if (!strcmp(ea->name, key)) {
107 if (ea->indirect) 107 if (ea_indirect(ea))
108 goto indirect; 108 goto indirect;
109 if (ea_valuelen(ea) >= size) 109 if (ea_valuelen(ea) >= size)
110 return -EINVAL; 110 return -EINVAL;
@@ -119,7 +119,7 @@ int hpfs_read_ea(struct super_block *s, struct fnode *fnode, char *key,
119indirect: 119indirect:
120 if (ea_len(ea) >= size) 120 if (ea_len(ea) >= size)
121 return -EINVAL; 121 return -EINVAL;
122 if (hpfs_ea_read(s, ea_sec(ea), ea->anode, 0, ea_len(ea), buf)) 122 if (hpfs_ea_read(s, ea_sec(ea), ea_in_anode(ea), 0, ea_len(ea), buf))
123 return -EIO; 123 return -EIO;
124 buf[ea_len(ea)] = 0; 124 buf[ea_len(ea)] = 0;
125 return 0; 125 return 0;
@@ -136,8 +136,8 @@ char *hpfs_get_ea(struct super_block *s, struct fnode *fnode, char *key, int *si
136 struct extended_attribute *ea_end = fnode_end_ea(fnode); 136 struct extended_attribute *ea_end = fnode_end_ea(fnode);
137 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea)) 137 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
138 if (!strcmp(ea->name, key)) { 138 if (!strcmp(ea->name, key)) {
139 if (ea->indirect) 139 if (ea_indirect(ea))
140 return get_indirect_ea(s, ea->anode, ea_sec(ea), *size = ea_len(ea)); 140 return get_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), *size = ea_len(ea));
141 if (!(ret = kmalloc((*size = ea_valuelen(ea)) + 1, GFP_NOFS))) { 141 if (!(ret = kmalloc((*size = ea_valuelen(ea)) + 1, GFP_NOFS))) {
142 printk("HPFS: out of memory for EA\n"); 142 printk("HPFS: out of memory for EA\n");
143 return NULL; 143 return NULL;
@@ -148,7 +148,7 @@ char *hpfs_get_ea(struct super_block *s, struct fnode *fnode, char *key, int *si
148 } 148 }
149 a = le32_to_cpu(fnode->ea_secno); 149 a = le32_to_cpu(fnode->ea_secno);
150 len = le32_to_cpu(fnode->ea_size_l); 150 len = le32_to_cpu(fnode->ea_size_l);
151 ano = fnode->ea_anode; 151 ano = fnode_in_anode(fnode);
152 pos = 0; 152 pos = 0;
153 while (pos < len) { 153 while (pos < len) {
154 char ex[4 + 255 + 1 + 8]; 154 char ex[4 + 255 + 1 + 8];
@@ -159,11 +159,11 @@ char *hpfs_get_ea(struct super_block *s, struct fnode *fnode, char *key, int *si
159 return NULL; 159 return NULL;
160 } 160 }
161 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return NULL; 161 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return NULL;
162 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea->indirect ? 8 : 0), ex + 4)) 162 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea_indirect(ea) ? 8 : 0), ex + 4))
163 return NULL; 163 return NULL;
164 if (!strcmp(ea->name, key)) { 164 if (!strcmp(ea->name, key)) {
165 if (ea->indirect) 165 if (ea_indirect(ea))
166 return get_indirect_ea(s, ea->anode, ea_sec(ea), *size = ea_len(ea)); 166 return get_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), *size = ea_len(ea));
167 if (!(ret = kmalloc((*size = ea_valuelen(ea)) + 1, GFP_NOFS))) { 167 if (!(ret = kmalloc((*size = ea_valuelen(ea)) + 1, GFP_NOFS))) {
168 printk("HPFS: out of memory for EA\n"); 168 printk("HPFS: out of memory for EA\n");
169 return NULL; 169 return NULL;
@@ -199,9 +199,9 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
199 struct extended_attribute *ea_end = fnode_end_ea(fnode); 199 struct extended_attribute *ea_end = fnode_end_ea(fnode);
200 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea)) 200 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
201 if (!strcmp(ea->name, key)) { 201 if (!strcmp(ea->name, key)) {
202 if (ea->indirect) { 202 if (ea_indirect(ea)) {
203 if (ea_len(ea) == size) 203 if (ea_len(ea) == size)
204 set_indirect_ea(s, ea->anode, ea_sec(ea), data, size); 204 set_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), data, size);
205 } else if (ea_valuelen(ea) == size) { 205 } else if (ea_valuelen(ea) == size) {
206 memcpy(ea_data(ea), data, size); 206 memcpy(ea_data(ea), data, size);
207 } 207 }
@@ -209,7 +209,7 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
209 } 209 }
210 a = le32_to_cpu(fnode->ea_secno); 210 a = le32_to_cpu(fnode->ea_secno);
211 len = le32_to_cpu(fnode->ea_size_l); 211 len = le32_to_cpu(fnode->ea_size_l);
212 ano = fnode->ea_anode; 212 ano = fnode_in_anode(fnode);
213 pos = 0; 213 pos = 0;
214 while (pos < len) { 214 while (pos < len) {
215 char ex[4 + 255 + 1 + 8]; 215 char ex[4 + 255 + 1 + 8];
@@ -220,12 +220,12 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
220 return; 220 return;
221 } 221 }
222 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return; 222 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return;
223 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea->indirect ? 8 : 0), ex + 4)) 223 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea_indirect(ea) ? 8 : 0), ex + 4))
224 return; 224 return;
225 if (!strcmp(ea->name, key)) { 225 if (!strcmp(ea->name, key)) {
226 if (ea->indirect) { 226 if (ea_indirect(ea)) {
227 if (ea_len(ea) == size) 227 if (ea_len(ea) == size)
228 set_indirect_ea(s, ea->anode, ea_sec(ea), data, size); 228 set_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), data, size);
229 } 229 }
230 else { 230 else {
231 if (ea_valuelen(ea) == size) 231 if (ea_valuelen(ea) == size)
@@ -246,7 +246,7 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
246 if (le16_to_cpu(fnode->ea_offs) < 0xc4 || le16_to_cpu(fnode->ea_offs) + le16_to_cpu(fnode->acl_size_s) + le16_to_cpu(fnode->ea_size_s) > 0x200) { 246 if (le16_to_cpu(fnode->ea_offs) < 0xc4 || le16_to_cpu(fnode->ea_offs) + le16_to_cpu(fnode->acl_size_s) + le16_to_cpu(fnode->ea_size_s) > 0x200) {
247 hpfs_error(s, "fnode %08lx: ea_offs == %03x, ea_size_s == %03x", 247 hpfs_error(s, "fnode %08lx: ea_offs == %03x, ea_size_s == %03x",
248 (unsigned long)inode->i_ino, 248 (unsigned long)inode->i_ino,
249 le32_to_cpu(fnode->ea_offs), le16_to_cpu(fnode->ea_size_s)); 249 le16_to_cpu(fnode->ea_offs), le16_to_cpu(fnode->ea_size_s));
250 return; 250 return;
251 } 251 }
252 if ((le16_to_cpu(fnode->ea_size_s) || !le32_to_cpu(fnode->ea_size_l)) && 252 if ((le16_to_cpu(fnode->ea_size_s) || !le32_to_cpu(fnode->ea_size_l)) &&
@@ -276,7 +276,7 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
276 fnode->ea_size_l = cpu_to_le32(le16_to_cpu(fnode->ea_size_s)); 276 fnode->ea_size_l = cpu_to_le32(le16_to_cpu(fnode->ea_size_s));
277 fnode->ea_size_s = cpu_to_le16(0); 277 fnode->ea_size_s = cpu_to_le16(0);
278 fnode->ea_secno = cpu_to_le32(n); 278 fnode->ea_secno = cpu_to_le32(n);
279 fnode->ea_anode = cpu_to_le32(0); 279 fnode->flags &= ~FNODE_anode;
280 mark_buffer_dirty(bh); 280 mark_buffer_dirty(bh);
281 brelse(bh); 281 brelse(bh);
282 } 282 }
@@ -288,9 +288,9 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
288 secno q = hpfs_alloc_sector(s, fno, 1, 0); 288 secno q = hpfs_alloc_sector(s, fno, 1, 0);
289 if (!q) goto bail; 289 if (!q) goto bail;
290 fnode->ea_secno = cpu_to_le32(q); 290 fnode->ea_secno = cpu_to_le32(q);
291 fnode->ea_anode = 0; 291 fnode->flags &= ~FNODE_anode;
292 len++; 292 len++;
293 } else if (!fnode->ea_anode) { 293 } else if (!fnode_in_anode(fnode)) {
294 if (hpfs_alloc_if_possible(s, le32_to_cpu(fnode->ea_secno) + len)) { 294 if (hpfs_alloc_if_possible(s, le32_to_cpu(fnode->ea_secno) + len)) {
295 len++; 295 len++;
296 } else { 296 } else {
@@ -310,7 +310,7 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
310 anode->u.external[0].length = cpu_to_le32(len); 310 anode->u.external[0].length = cpu_to_le32(len);
311 mark_buffer_dirty(bh); 311 mark_buffer_dirty(bh);
312 brelse(bh); 312 brelse(bh);
313 fnode->ea_anode = 1; 313 fnode->flags |= FNODE_anode;
314 fnode->ea_secno = cpu_to_le32(a_s);*/ 314 fnode->ea_secno = cpu_to_le32(a_s);*/
315 secno new_sec; 315 secno new_sec;
316 int i; 316 int i;
@@ -338,7 +338,7 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
338 len = (pos + 511) >> 9; 338 len = (pos + 511) >> 9;
339 } 339 }
340 } 340 }
341 if (fnode->ea_anode) { 341 if (fnode_in_anode(fnode)) {
342 if (hpfs_add_sector_to_btree(s, le32_to_cpu(fnode->ea_secno), 342 if (hpfs_add_sector_to_btree(s, le32_to_cpu(fnode->ea_secno),
343 0, len) != -1) { 343 0, len) != -1) {
344 len++; 344 len++;
@@ -351,16 +351,16 @@ void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
351 h[1] = strlen(key); 351 h[1] = strlen(key);
352 h[2] = size & 0xff; 352 h[2] = size & 0xff;
353 h[3] = size >> 8; 353 h[3] = size >> 8;
354 if (hpfs_ea_write(s, le32_to_cpu(fnode->ea_secno), fnode->ea_anode, le32_to_cpu(fnode->ea_size_l), 4, h)) goto bail; 354 if (hpfs_ea_write(s, le32_to_cpu(fnode->ea_secno), fnode_in_anode(fnode), le32_to_cpu(fnode->ea_size_l), 4, h)) goto bail;
355 if (hpfs_ea_write(s, le32_to_cpu(fnode->ea_secno), fnode->ea_anode, le32_to_cpu(fnode->ea_size_l) + 4, h[1] + 1, key)) goto bail; 355 if (hpfs_ea_write(s, le32_to_cpu(fnode->ea_secno), fnode_in_anode(fnode), le32_to_cpu(fnode->ea_size_l) + 4, h[1] + 1, key)) goto bail;
356 if (hpfs_ea_write(s, le32_to_cpu(fnode->ea_secno), fnode->ea_anode, le32_to_cpu(fnode->ea_size_l) + 5 + h[1], size, data)) goto bail; 356 if (hpfs_ea_write(s, le32_to_cpu(fnode->ea_secno), fnode_in_anode(fnode), le32_to_cpu(fnode->ea_size_l) + 5 + h[1], size, data)) goto bail;
357 fnode->ea_size_l = cpu_to_le32(pos); 357 fnode->ea_size_l = cpu_to_le32(pos);
358 ret: 358 ret:
359 hpfs_i(inode)->i_ea_size += 5 + strlen(key) + size; 359 hpfs_i(inode)->i_ea_size += 5 + strlen(key) + size;
360 return; 360 return;
361 bail: 361 bail:
362 if (le32_to_cpu(fnode->ea_secno)) 362 if (le32_to_cpu(fnode->ea_secno))
363 if (fnode->ea_anode) hpfs_truncate_btree(s, le32_to_cpu(fnode->ea_secno), 1, (le32_to_cpu(fnode->ea_size_l) + 511) >> 9); 363 if (fnode_in_anode(fnode)) hpfs_truncate_btree(s, le32_to_cpu(fnode->ea_secno), 1, (le32_to_cpu(fnode->ea_size_l) + 511) >> 9);
364 else hpfs_free_sectors(s, le32_to_cpu(fnode->ea_secno) + ((le32_to_cpu(fnode->ea_size_l) + 511) >> 9), len - ((le32_to_cpu(fnode->ea_size_l) + 511) >> 9)); 364 else hpfs_free_sectors(s, le32_to_cpu(fnode->ea_secno) + ((le32_to_cpu(fnode->ea_size_l) + 511) >> 9), len - ((le32_to_cpu(fnode->ea_size_l) + 511) >> 9));
365 else fnode->ea_secno = fnode->ea_size_l = cpu_to_le32(0); 365 else fnode->ea_secno = fnode->ea_size_l = cpu_to_le32(0);
366} 366}
diff --git a/fs/hpfs/hpfs.h b/fs/hpfs/hpfs.h
index 8b0650aae328..cce025aff1b1 100644
--- a/fs/hpfs/hpfs.h
+++ b/fs/hpfs/hpfs.h
@@ -51,11 +51,11 @@ struct hpfs_boot_block
51 u8 n_rootdir_entries[2]; 51 u8 n_rootdir_entries[2];
52 u8 n_sectors_s[2]; 52 u8 n_sectors_s[2];
53 u8 media_byte; 53 u8 media_byte;
54 u16 sectors_per_fat; 54 __le16 sectors_per_fat;
55 u16 sectors_per_track; 55 __le16 sectors_per_track;
56 u16 heads_per_cyl; 56 __le16 heads_per_cyl;
57 u32 n_hidden_sectors; 57 __le32 n_hidden_sectors;
58 u32 n_sectors_l; /* size of partition */ 58 __le32 n_sectors_l; /* size of partition */
59 u8 drive_number; 59 u8 drive_number;
60 u8 mbz; 60 u8 mbz;
61 u8 sig_28h; /* 28h */ 61 u8 sig_28h; /* 28h */
@@ -63,7 +63,7 @@ struct hpfs_boot_block
63 u8 vol_label[11]; 63 u8 vol_label[11];
64 u8 sig_hpfs[8]; /* "HPFS " */ 64 u8 sig_hpfs[8]; /* "HPFS " */
65 u8 pad[448]; 65 u8 pad[448];
66 u16 magic; /* aa55 */ 66 __le16 magic; /* aa55 */
67}; 67};
68 68
69 69
@@ -75,28 +75,28 @@ struct hpfs_boot_block
75 75
76struct hpfs_super_block 76struct hpfs_super_block
77{ 77{
78 u32 magic; /* f995 e849 */ 78 __le32 magic; /* f995 e849 */
79 u32 magic1; /* fa53 e9c5, more magic? */ 79 __le32 magic1; /* fa53 e9c5, more magic? */
80 u8 version; /* version of a filesystem usually 2 */ 80 u8 version; /* version of a filesystem usually 2 */
81 u8 funcversion; /* functional version - oldest version 81 u8 funcversion; /* functional version - oldest version
82 of filesystem that can understand 82 of filesystem that can understand
83 this disk */ 83 this disk */
84 u16 zero; /* 0 */ 84 __le16 zero; /* 0 */
85 fnode_secno root; /* fnode of root directory */ 85 __le32 root; /* fnode of root directory */
86 secno n_sectors; /* size of filesystem */ 86 __le32 n_sectors; /* size of filesystem */
87 u32 n_badblocks; /* number of bad blocks */ 87 __le32 n_badblocks; /* number of bad blocks */
88 secno bitmaps; /* pointers to free space bit maps */ 88 __le32 bitmaps; /* pointers to free space bit maps */
89 u32 zero1; /* 0 */ 89 __le32 zero1; /* 0 */
90 secno badblocks; /* bad block list */ 90 __le32 badblocks; /* bad block list */
91 u32 zero3; /* 0 */ 91 __le32 zero3; /* 0 */
92 time32_t last_chkdsk; /* date last checked, 0 if never */ 92 __le32 last_chkdsk; /* date last checked, 0 if never */
93 time32_t last_optimize; /* date last optimized, 0 if never */ 93 __le32 last_optimize; /* date last optimized, 0 if never */
94 secno n_dir_band; /* number of sectors in dir band */ 94 __le32 n_dir_band; /* number of sectors in dir band */
95 secno dir_band_start; /* first sector in dir band */ 95 __le32 dir_band_start; /* first sector in dir band */
96 secno dir_band_end; /* last sector in dir band */ 96 __le32 dir_band_end; /* last sector in dir band */
97 secno dir_band_bitmap; /* free space map, 1 dnode per bit */ 97 __le32 dir_band_bitmap; /* free space map, 1 dnode per bit */
98 u8 volume_name[32]; /* not used */ 98 u8 volume_name[32]; /* not used */
99 secno user_id_table; /* 8 preallocated sectors - user id */ 99 __le32 user_id_table; /* 8 preallocated sectors - user id */
100 u32 zero6[103]; /* 0 */ 100 u32 zero6[103]; /* 0 */
101}; 101};
102 102
@@ -109,8 +109,8 @@ struct hpfs_super_block
109 109
110struct hpfs_spare_block 110struct hpfs_spare_block
111{ 111{
112 u32 magic; /* f991 1849 */ 112 __le32 magic; /* f991 1849 */
113 u32 magic1; /* fa52 29c5, more magic? */ 113 __le32 magic1; /* fa52 29c5, more magic? */
114 114
115#ifdef __LITTLE_ENDIAN 115#ifdef __LITTLE_ENDIAN
116 u8 dirty: 1; /* 0 clean, 1 "improperly stopped" */ 116 u8 dirty: 1; /* 0 clean, 1 "improperly stopped" */
@@ -153,21 +153,21 @@ struct hpfs_spare_block
153 u8 mm_contlgulty; 153 u8 mm_contlgulty;
154 u8 unused; 154 u8 unused;
155 155
156 secno hotfix_map; /* info about remapped bad sectors */ 156 __le32 hotfix_map; /* info about remapped bad sectors */
157 u32 n_spares_used; /* number of hotfixes */ 157 __le32 n_spares_used; /* number of hotfixes */
158 u32 n_spares; /* number of spares in hotfix map */ 158 __le32 n_spares; /* number of spares in hotfix map */
159 u32 n_dnode_spares_free; /* spare dnodes unused */ 159 __le32 n_dnode_spares_free; /* spare dnodes unused */
160 u32 n_dnode_spares; /* length of spare_dnodes[] list, 160 __le32 n_dnode_spares; /* length of spare_dnodes[] list,
161 follows in this block*/ 161 follows in this block*/
162 secno code_page_dir; /* code page directory block */ 162 __le32 code_page_dir; /* code page directory block */
163 u32 n_code_pages; /* number of code pages */ 163 __le32 n_code_pages; /* number of code pages */
164 u32 super_crc; /* on HPFS386 and LAN Server this is 164 __le32 super_crc; /* on HPFS386 and LAN Server this is
165 checksum of superblock, on normal 165 checksum of superblock, on normal
166 OS/2 unused */ 166 OS/2 unused */
167 u32 spare_crc; /* on HPFS386 checksum of spareblock */ 167 __le32 spare_crc; /* on HPFS386 checksum of spareblock */
168 u32 zero1[15]; /* unused */ 168 __le32 zero1[15]; /* unused */
169 dnode_secno spare_dnodes[100]; /* emergency free dnode list */ 169 __le32 spare_dnodes[100]; /* emergency free dnode list */
170 u32 zero2[1]; /* room for more? */ 170 __le32 zero2[1]; /* room for more? */
171}; 171};
172 172
173/* The bad block list is 4 sectors long. The first word must be zero, 173/* The bad block list is 4 sectors long. The first word must be zero,
@@ -202,18 +202,18 @@ struct hpfs_spare_block
202 202
203struct code_page_directory 203struct code_page_directory
204{ 204{
205 u32 magic; /* 4945 21f7 */ 205 __le32 magic; /* 4945 21f7 */
206 u32 n_code_pages; /* number of pointers following */ 206 __le32 n_code_pages; /* number of pointers following */
207 u32 zero1[2]; 207 __le32 zero1[2];
208 struct { 208 struct {
209 u16 ix; /* index */ 209 __le16 ix; /* index */
210 u16 code_page_number; /* code page number */ 210 __le16 code_page_number; /* code page number */
211 u32 bounds; /* matches corresponding word 211 __le32 bounds; /* matches corresponding word
212 in data block */ 212 in data block */
213 secno code_page_data; /* sector number of a code_page_data 213 __le32 code_page_data; /* sector number of a code_page_data
214 containing c.p. array */ 214 containing c.p. array */
215 u16 index; /* index in c.p. array in that sector*/ 215 __le16 index; /* index in c.p. array in that sector*/
216 u16 unknown; /* some unknown value; usually 0; 216 __le16 unknown; /* some unknown value; usually 0;
217 2 in Japanese version */ 217 2 in Japanese version */
218 } array[31]; /* unknown length */ 218 } array[31]; /* unknown length */
219}; 219};
@@ -224,19 +224,19 @@ struct code_page_directory
224 224
225struct code_page_data 225struct code_page_data
226{ 226{
227 u32 magic; /* 8945 21f7 */ 227 __le32 magic; /* 8945 21f7 */
228 u32 n_used; /* # elements used in c_p_data[] */ 228 __le32 n_used; /* # elements used in c_p_data[] */
229 u32 bounds[3]; /* looks a bit like 229 __le32 bounds[3]; /* looks a bit like
230 (beg1,end1), (beg2,end2) 230 (beg1,end1), (beg2,end2)
231 one byte each */ 231 one byte each */
232 u16 offs[3]; /* offsets from start of sector 232 __le16 offs[3]; /* offsets from start of sector
233 to start of c_p_data[ix] */ 233 to start of c_p_data[ix] */
234 struct { 234 struct {
235 u16 ix; /* index */ 235 __le16 ix; /* index */
236 u16 code_page_number; /* code page number */ 236 __le16 code_page_number; /* code page number */
237 u16 unknown; /* the same as in cp directory */ 237 __le16 unknown; /* the same as in cp directory */
238 u8 map[128]; /* upcase table for chars 80..ff */ 238 u8 map[128]; /* upcase table for chars 80..ff */
239 u16 zero2; 239 __le16 zero2;
240 } code_page[3]; 240 } code_page[3];
241 u8 incognita[78]; 241 u8 incognita[78];
242}; 242};
@@ -278,8 +278,8 @@ struct code_page_data
278#define DNODE_MAGIC 0x77e40aae 278#define DNODE_MAGIC 0x77e40aae
279 279
280struct dnode { 280struct dnode {
281 u32 magic; /* 77e4 0aae */ 281 __le32 magic; /* 77e4 0aae */
282 u32 first_free; /* offset from start of dnode to 282 __le32 first_free; /* offset from start of dnode to
283 first free dir entry */ 283 first free dir entry */
284#ifdef __LITTLE_ENDIAN 284#ifdef __LITTLE_ENDIAN
285 u8 root_dnode: 1; /* Is it root dnode? */ 285 u8 root_dnode: 1; /* Is it root dnode? */
@@ -293,14 +293,14 @@ struct dnode {
293 u8 root_dnode: 1; /* Is it root dnode? */ 293 u8 root_dnode: 1; /* Is it root dnode? */
294#endif 294#endif
295 u8 increment_me2[3]; 295 u8 increment_me2[3];
296 secno up; /* (root dnode) directory's fnode 296 __le32 up; /* (root dnode) directory's fnode
297 (nonroot) parent dnode */ 297 (nonroot) parent dnode */
298 dnode_secno self; /* pointer to this dnode */ 298 __le32 self; /* pointer to this dnode */
299 u8 dirent[2028]; /* one or more dirents */ 299 u8 dirent[2028]; /* one or more dirents */
300}; 300};
301 301
302struct hpfs_dirent { 302struct hpfs_dirent {
303 u16 length; /* offset to next dirent */ 303 __le16 length; /* offset to next dirent */
304 304
305#ifdef __LITTLE_ENDIAN 305#ifdef __LITTLE_ENDIAN
306 u8 first: 1; /* set on phony ^A^A (".") entry */ 306 u8 first: 1; /* set on phony ^A^A (".") entry */
@@ -346,12 +346,12 @@ struct hpfs_dirent {
346 u8 read_only: 1; /* dos attrib */ 346 u8 read_only: 1; /* dos attrib */
347#endif 347#endif
348 348
349 fnode_secno fnode; /* fnode giving allocation info */ 349 __le32 fnode; /* fnode giving allocation info */
350 time32_t write_date; /* mtime */ 350 __le32 write_date; /* mtime */
351 u32 file_size; /* file length, bytes */ 351 __le32 file_size; /* file length, bytes */
352 time32_t read_date; /* atime */ 352 __le32 read_date; /* atime */
353 time32_t creation_date; /* ctime */ 353 __le32 creation_date; /* ctime */
354 u32 ea_size; /* total EA length, bytes */ 354 __le32 ea_size; /* total EA length, bytes */
355 u8 no_of_acls; /* number of ACL's (low 3 bits) */ 355 u8 no_of_acls; /* number of ACL's (low 3 bits) */
356 u8 ix; /* code page index (of filename), see 356 u8 ix; /* code page index (of filename), see
357 struct code_page_data */ 357 struct code_page_data */
@@ -375,50 +375,36 @@ struct hpfs_dirent {
375 375
376struct bplus_leaf_node 376struct bplus_leaf_node
377{ 377{
378 u32 file_secno; /* first file sector in extent */ 378 __le32 file_secno; /* first file sector in extent */
379 u32 length; /* length, sectors */ 379 __le32 length; /* length, sectors */
380 secno disk_secno; /* first corresponding disk sector */ 380 __le32 disk_secno; /* first corresponding disk sector */
381}; 381};
382 382
383struct bplus_internal_node 383struct bplus_internal_node
384{ 384{
385 u32 file_secno; /* subtree maps sectors < this */ 385 __le32 file_secno; /* subtree maps sectors < this */
386 anode_secno down; /* pointer to subtree */ 386 __le32 down; /* pointer to subtree */
387}; 387};
388 388
389enum {
390 BP_hbff = 1,
391 BP_fnode_parent = 0x20,
392 BP_binary_search = 0x40,
393 BP_internal = 0x80
394};
389struct bplus_header 395struct bplus_header
390{ 396{
391#ifdef __LITTLE_ENDIAN 397 u8 flags; /* bit 0 - high bit of first free entry offset
392 u8 hbff: 1; /* high bit of first free entry offset */ 398 bit 5 - we're pointed to by an fnode,
393 u8 flag1234: 4;
394 u8 fnode_parent: 1; /* ? we're pointed to by an fnode,
395 the data btree or some ea or the
396 main ea bootage pointer ea_secno */
397 /* also can get set in fnodes, which
398 may be a chkdsk glitch or may mean
399 this bit is irrelevant in fnodes,
400 or this interpretation is all wet */
401 u8 binary_search: 1; /* suggest binary search (unused) */
402 u8 internal: 1; /* 1 -> (internal) tree of anodes
403 0 -> (leaf) list of extents */
404#else
405 u8 internal: 1; /* 1 -> (internal) tree of anodes
406 0 -> (leaf) list of extents */
407 u8 binary_search: 1; /* suggest binary search (unused) */
408 u8 fnode_parent: 1; /* ? we're pointed to by an fnode,
409 the data btree or some ea or the 399 the data btree or some ea or the
410 main ea bootage pointer ea_secno */ 400 main ea bootage pointer ea_secno
411 /* also can get set in fnodes, which 401 bit 6 - suggest binary search (unused)
412 may be a chkdsk glitch or may mean 402 bit 7 - 1 -> (internal) tree of anodes
413 this bit is irrelevant in fnodes, 403 0 -> (leaf) list of extents */
414 or this interpretation is all wet */
415 u8 flag1234: 4;
416 u8 hbff: 1; /* high bit of first free entry offset */
417#endif
418 u8 fill[3]; 404 u8 fill[3];
419 u8 n_free_nodes; /* free nodes in following array */ 405 u8 n_free_nodes; /* free nodes in following array */
420 u8 n_used_nodes; /* used nodes in following array */ 406 u8 n_used_nodes; /* used nodes in following array */
421 u16 first_free; /* offset from start of header to 407 __le16 first_free; /* offset from start of header to
422 first free node in array */ 408 first free node in array */
423 union { 409 union {
424 struct bplus_internal_node internal[0]; /* (internal) 2-word entries giving 410 struct bplus_internal_node internal[0]; /* (internal) 2-word entries giving
@@ -428,6 +414,16 @@ struct bplus_header
428 } u; 414 } u;
429}; 415};
430 416
417static inline bool bp_internal(struct bplus_header *bp)
418{
419 return bp->flags & BP_internal;
420}
421
422static inline bool bp_fnode_parent(struct bplus_header *bp)
423{
424 return bp->flags & BP_fnode_parent;
425}
426
431/* fnode: root of allocation b+ tree, and EA's */ 427/* fnode: root of allocation b+ tree, and EA's */
432 428
433/* Every file and every directory has one fnode, pointed to by the directory 429/* Every file and every directory has one fnode, pointed to by the directory
@@ -436,62 +432,56 @@ struct bplus_header
436 432
437#define FNODE_MAGIC 0xf7e40aae 433#define FNODE_MAGIC 0xf7e40aae
438 434
435enum {FNODE_anode = cpu_to_le16(2), FNODE_dir = cpu_to_le16(256)};
439struct fnode 436struct fnode
440{ 437{
441 u32 magic; /* f7e4 0aae */ 438 __le32 magic; /* f7e4 0aae */
442 u32 zero1[2]; /* read history */ 439 __le32 zero1[2]; /* read history */
443 u8 len, name[15]; /* true length, truncated name */ 440 u8 len, name[15]; /* true length, truncated name */
444 fnode_secno up; /* pointer to file's directory fnode */ 441 __le32 up; /* pointer to file's directory fnode */
445 secno acl_size_l; 442 __le32 acl_size_l;
446 secno acl_secno; 443 __le32 acl_secno;
447 u16 acl_size_s; 444 __le16 acl_size_s;
448 u8 acl_anode; 445 u8 acl_anode;
449 u8 zero2; /* history bit count */ 446 u8 zero2; /* history bit count */
450 u32 ea_size_l; /* length of disk-resident ea's */ 447 __le32 ea_size_l; /* length of disk-resident ea's */
451 secno ea_secno; /* first sector of disk-resident ea's*/ 448 __le32 ea_secno; /* first sector of disk-resident ea's*/
452 u16 ea_size_s; /* length of fnode-resident ea's */ 449 __le16 ea_size_s; /* length of fnode-resident ea's */
453
454#ifdef __LITTLE_ENDIAN
455 u8 flag0: 1;
456 u8 ea_anode: 1; /* 1 -> ea_secno is an anode */
457 u8 flag234567: 6;
458#else
459 u8 flag234567: 6;
460 u8 ea_anode: 1; /* 1 -> ea_secno is an anode */
461 u8 flag0: 1;
462#endif
463 450
464#ifdef __LITTLE_ENDIAN 451 __le16 flags; /* bit 1 set -> ea_secno is an anode */
465 u8 dirflag: 1; /* 1 -> directory. first & only extent 452 /* bit 8 set -> directory. first & only extent
466 points to dnode. */
467 u8 flag9012345: 7;
468#else
469 u8 flag9012345: 7;
470 u8 dirflag: 1; /* 1 -> directory. first & only extent
471 points to dnode. */ 453 points to dnode. */
472#endif
473
474 struct bplus_header btree; /* b+ tree, 8 extents or 12 subtrees */ 454 struct bplus_header btree; /* b+ tree, 8 extents or 12 subtrees */
475 union { 455 union {
476 struct bplus_leaf_node external[8]; 456 struct bplus_leaf_node external[8];
477 struct bplus_internal_node internal[12]; 457 struct bplus_internal_node internal[12];
478 } u; 458 } u;
479 459
480 u32 file_size; /* file length, bytes */ 460 __le32 file_size; /* file length, bytes */
481 u32 n_needea; /* number of EA's with NEEDEA set */ 461 __le32 n_needea; /* number of EA's with NEEDEA set */
482 u8 user_id[16]; /* unused */ 462 u8 user_id[16]; /* unused */
483 u16 ea_offs; /* offset from start of fnode 463 __le16 ea_offs; /* offset from start of fnode
484 to first fnode-resident ea */ 464 to first fnode-resident ea */
485 u8 dasd_limit_treshhold; 465 u8 dasd_limit_treshhold;
486 u8 dasd_limit_delta; 466 u8 dasd_limit_delta;
487 u32 dasd_limit; 467 __le32 dasd_limit;
488 u32 dasd_usage; 468 __le32 dasd_usage;
489 u8 ea[316]; /* zero or more EA's, packed together 469 u8 ea[316]; /* zero or more EA's, packed together
490 with no alignment padding. 470 with no alignment padding.
491 (Do not use this name, get here 471 (Do not use this name, get here
492 via fnode + ea_offs. I think.) */ 472 via fnode + ea_offs. I think.) */
493}; 473};
494 474
475static inline bool fnode_in_anode(struct fnode *p)
476{
477 return (p->flags & FNODE_anode) != 0;
478}
479
480static inline bool fnode_is_dir(struct fnode *p)
481{
482 return (p->flags & FNODE_dir) != 0;
483}
484
495 485
496/* anode: 99.44% pure allocation tree */ 486/* anode: 99.44% pure allocation tree */
497 487
@@ -499,9 +489,9 @@ struct fnode
499 489
500struct anode 490struct anode
501{ 491{
502 u32 magic; /* 37e4 0aae */ 492 __le32 magic; /* 37e4 0aae */
503 anode_secno self; /* pointer to this anode */ 493 __le32 self; /* pointer to this anode */
504 secno up; /* parent anode or fnode */ 494 __le32 up; /* parent anode or fnode */
505 495
506 struct bplus_header btree; /* b+tree, 40 extents or 60 subtrees */ 496 struct bplus_header btree; /* b+tree, 40 extents or 60 subtrees */
507 union { 497 union {
@@ -509,7 +499,7 @@ struct anode
509 struct bplus_internal_node internal[60]; 499 struct bplus_internal_node internal[60];
510 } u; 500 } u;
511 501
512 u32 fill[3]; /* unused */ 502 __le32 fill[3]; /* unused */
513}; 503};
514 504
515 505
@@ -528,32 +518,23 @@ struct anode
528 run, or in multiple runs. Flags in the fnode tell whether the EA list 518 run, or in multiple runs. Flags in the fnode tell whether the EA list
529 is immediate, in a single run, or in multiple runs. */ 519 is immediate, in a single run, or in multiple runs. */
530 520
521enum {EA_indirect = 1, EA_anode = 2, EA_needea = 128 };
531struct extended_attribute 522struct extended_attribute
532{ 523{
533#ifdef __LITTLE_ENDIAN 524 u8 flags; /* bit 0 set -> value gives sector number
534 u8 indirect: 1; /* 1 -> value gives sector number
535 where real value starts */ 525 where real value starts */
536 u8 anode: 1; /* 1 -> sector is an anode 526 /* bit 1 set -> sector is an anode
537 that points to fragmented value */ 527 that points to fragmented value */
538 u8 flag23456: 5; 528 /* bit 7 set -> required ea */
539 u8 needea: 1; /* required ea */
540#else
541 u8 needea: 1; /* required ea */
542 u8 flag23456: 5;
543 u8 anode: 1; /* 1 -> sector is an anode
544 that points to fragmented value */
545 u8 indirect: 1; /* 1 -> value gives sector number
546 where real value starts */
547#endif
548 u8 namelen; /* length of name, bytes */ 529 u8 namelen; /* length of name, bytes */
549 u8 valuelen_lo; /* length of value, bytes */ 530 u8 valuelen_lo; /* length of value, bytes */
550 u8 valuelen_hi; /* length of value, bytes */ 531 u8 valuelen_hi; /* length of value, bytes */
551 u8 name[0]; 532 u8 name[];
552 /* 533 /*
553 u8 name[namelen]; ascii attrib name 534 u8 name[namelen]; ascii attrib name
554 u8 nul; terminating '\0', not counted 535 u8 nul; terminating '\0', not counted
555 u8 value[valuelen]; value, arbitrary 536 u8 value[valuelen]; value, arbitrary
556 if this.indirect, valuelen is 8 and the value is 537 if this.flags & 1, valuelen is 8 and the value is
557 u32 length; real length of value, bytes 538 u32 length; real length of value, bytes
558 secno secno; sector address where it starts 539 secno secno; sector address where it starts
559 if this.anode, the above sector number is the root of an anode tree 540 if this.anode, the above sector number is the root of an anode tree
@@ -561,6 +542,16 @@ struct extended_attribute
561 */ 542 */
562}; 543};
563 544
545static inline bool ea_indirect(struct extended_attribute *ea)
546{
547 return ea->flags & EA_indirect;
548}
549
550static inline bool ea_in_anode(struct extended_attribute *ea)
551{
552 return ea->flags & EA_anode;
553}
554
564/* 555/*
565 Local Variables: 556 Local Variables:
566 comment-column: 40 557 comment-column: 40
diff --git a/fs/hpfs/hpfs_fn.h b/fs/hpfs/hpfs_fn.h
index de946170ebb1..c07ef1f1ced6 100644
--- a/fs/hpfs/hpfs_fn.h
+++ b/fs/hpfs/hpfs_fn.h
@@ -35,13 +35,6 @@
35 35
36#define CHKCOND(x,y) if (!(x)) printk y 36#define CHKCOND(x,y) if (!(x)) printk y
37 37
38#ifdef DBG
39#define PRINTK(x) printk x
40#else
41#undef PRINTK
42#define PRINTK(x)
43#endif
44
45struct hpfs_inode_info { 38struct hpfs_inode_info {
46 loff_t mmu_private; 39 loff_t mmu_private;
47 ino_t i_parent_dir; /* (directories) gives fnode of parent dir */ 40 ino_t i_parent_dir; /* (directories) gives fnode of parent dir */
@@ -82,7 +75,7 @@ struct hpfs_sb_info {
82 unsigned char *sb_cp_table; /* code page tables: */ 75 unsigned char *sb_cp_table; /* code page tables: */
83 /* 128 bytes uppercasing table & */ 76 /* 128 bytes uppercasing table & */
84 /* 128 bytes lowercasing table */ 77 /* 128 bytes lowercasing table */
85 unsigned *sb_bmp_dir; /* main bitmap directory */ 78 __le32 *sb_bmp_dir; /* main bitmap directory */
86 unsigned sb_c_bitmap; /* current bitmap */ 79 unsigned sb_c_bitmap; /* current bitmap */
87 unsigned sb_max_fwd_alloc; /* max forwad allocation */ 80 unsigned sb_max_fwd_alloc; /* max forwad allocation */
88 int sb_timeshift; 81 int sb_timeshift;
@@ -100,7 +93,7 @@ struct quad_buffer_head {
100static inline dnode_secno de_down_pointer (struct hpfs_dirent *de) 93static inline dnode_secno de_down_pointer (struct hpfs_dirent *de)
101{ 94{
102 CHKCOND(de->down,("HPFS: de_down_pointer: !de->down\n")); 95 CHKCOND(de->down,("HPFS: de_down_pointer: !de->down\n"));
103 return le32_to_cpu(*(dnode_secno *) ((void *) de + le16_to_cpu(de->length) - 4)); 96 return le32_to_cpu(*(__le32 *) ((void *) de + le16_to_cpu(de->length) - 4));
104} 97}
105 98
106/* The first dir entry in a dnode */ 99/* The first dir entry in a dnode */
@@ -148,12 +141,12 @@ static inline struct extended_attribute *next_ea(struct extended_attribute *ea)
148 141
149static inline secno ea_sec(struct extended_attribute *ea) 142static inline secno ea_sec(struct extended_attribute *ea)
150{ 143{
151 return le32_to_cpu(get_unaligned((secno *)((char *)ea + 9 + ea->namelen))); 144 return le32_to_cpu(get_unaligned((__le32 *)((char *)ea + 9 + ea->namelen)));
152} 145}
153 146
154static inline secno ea_len(struct extended_attribute *ea) 147static inline secno ea_len(struct extended_attribute *ea)
155{ 148{
156 return le32_to_cpu(get_unaligned((secno *)((char *)ea + 5 + ea->namelen))); 149 return le32_to_cpu(get_unaligned((__le32 *)((char *)ea + 5 + ea->namelen)));
157} 150}
158 151
159static inline char *ea_data(struct extended_attribute *ea) 152static inline char *ea_data(struct extended_attribute *ea)
@@ -178,7 +171,7 @@ static inline void copy_de(struct hpfs_dirent *dst, struct hpfs_dirent *src)
178 dst->not_8x3 = n; 171 dst->not_8x3 = n;
179} 172}
180 173
181static inline unsigned tstbits(u32 *bmp, unsigned b, unsigned n) 174static inline unsigned tstbits(__le32 *bmp, unsigned b, unsigned n)
182{ 175{
183 int i; 176 int i;
184 if ((b >= 0x4000) || (b + n - 1 >= 0x4000)) return n; 177 if ((b >= 0x4000) || (b + n - 1 >= 0x4000)) return n;
@@ -275,10 +268,10 @@ void hpfs_evict_inode(struct inode *);
275 268
276/* map.c */ 269/* map.c */
277 270
278unsigned *hpfs_map_dnode_bitmap(struct super_block *, struct quad_buffer_head *); 271__le32 *hpfs_map_dnode_bitmap(struct super_block *, struct quad_buffer_head *);
279unsigned *hpfs_map_bitmap(struct super_block *, unsigned, struct quad_buffer_head *, char *); 272__le32 *hpfs_map_bitmap(struct super_block *, unsigned, struct quad_buffer_head *, char *);
280unsigned char *hpfs_load_code_page(struct super_block *, secno); 273unsigned char *hpfs_load_code_page(struct super_block *, secno);
281secno *hpfs_load_bitmap_directory(struct super_block *, secno bmp); 274__le32 *hpfs_load_bitmap_directory(struct super_block *, secno bmp);
282struct fnode *hpfs_map_fnode(struct super_block *s, ino_t, struct buffer_head **); 275struct fnode *hpfs_map_fnode(struct super_block *s, ino_t, struct buffer_head **);
283struct anode *hpfs_map_anode(struct super_block *s, anode_secno, struct buffer_head **); 276struct anode *hpfs_map_anode(struct super_block *s, anode_secno, struct buffer_head **);
284struct dnode *hpfs_map_dnode(struct super_block *s, dnode_secno, struct quad_buffer_head *); 277struct dnode *hpfs_map_dnode(struct super_block *s, dnode_secno, struct quad_buffer_head *);
diff --git a/fs/hpfs/inode.c b/fs/hpfs/inode.c
index b43066cbdc6a..ed671e0ea784 100644
--- a/fs/hpfs/inode.c
+++ b/fs/hpfs/inode.c
@@ -110,7 +110,7 @@ void hpfs_read_inode(struct inode *i)
110 } 110 }
111 } 111 }
112 } 112 }
113 if (fnode->dirflag) { 113 if (fnode_is_dir(fnode)) {
114 int n_dnodes, n_subdirs; 114 int n_dnodes, n_subdirs;
115 i->i_mode |= S_IFDIR; 115 i->i_mode |= S_IFDIR;
116 i->i_op = &hpfs_dir_iops; 116 i->i_op = &hpfs_dir_iops;
diff --git a/fs/hpfs/map.c b/fs/hpfs/map.c
index a790821366a7..4acb19d78359 100644
--- a/fs/hpfs/map.c
+++ b/fs/hpfs/map.c
@@ -8,12 +8,12 @@
8 8
9#include "hpfs_fn.h" 9#include "hpfs_fn.h"
10 10
11unsigned *hpfs_map_dnode_bitmap(struct super_block *s, struct quad_buffer_head *qbh) 11__le32 *hpfs_map_dnode_bitmap(struct super_block *s, struct quad_buffer_head *qbh)
12{ 12{
13 return hpfs_map_4sectors(s, hpfs_sb(s)->sb_dmap, qbh, 0); 13 return hpfs_map_4sectors(s, hpfs_sb(s)->sb_dmap, qbh, 0);
14} 14}
15 15
16unsigned int *hpfs_map_bitmap(struct super_block *s, unsigned bmp_block, 16__le32 *hpfs_map_bitmap(struct super_block *s, unsigned bmp_block,
17 struct quad_buffer_head *qbh, char *id) 17 struct quad_buffer_head *qbh, char *id)
18{ 18{
19 secno sec; 19 secno sec;
@@ -89,18 +89,18 @@ unsigned char *hpfs_load_code_page(struct super_block *s, secno cps)
89 return cp_table; 89 return cp_table;
90} 90}
91 91
92secno *hpfs_load_bitmap_directory(struct super_block *s, secno bmp) 92__le32 *hpfs_load_bitmap_directory(struct super_block *s, secno bmp)
93{ 93{
94 struct buffer_head *bh; 94 struct buffer_head *bh;
95 int n = (hpfs_sb(s)->sb_fs_size + 0x200000 - 1) >> 21; 95 int n = (hpfs_sb(s)->sb_fs_size + 0x200000 - 1) >> 21;
96 int i; 96 int i;
97 secno *b; 97 __le32 *b;
98 if (!(b = kmalloc(n * 512, GFP_KERNEL))) { 98 if (!(b = kmalloc(n * 512, GFP_KERNEL))) {
99 printk("HPFS: can't allocate memory for bitmap directory\n"); 99 printk("HPFS: can't allocate memory for bitmap directory\n");
100 return NULL; 100 return NULL;
101 } 101 }
102 for (i=0;i<n;i++) { 102 for (i=0;i<n;i++) {
103 secno *d = hpfs_map_sector(s, bmp+i, &bh, n - i - 1); 103 __le32 *d = hpfs_map_sector(s, bmp+i, &bh, n - i - 1);
104 if (!d) { 104 if (!d) {
105 kfree(b); 105 kfree(b);
106 return NULL; 106 return NULL;
@@ -130,16 +130,16 @@ struct fnode *hpfs_map_fnode(struct super_block *s, ino_t ino, struct buffer_hea
130 (unsigned long)ino); 130 (unsigned long)ino);
131 goto bail; 131 goto bail;
132 } 132 }
133 if (!fnode->dirflag) { 133 if (!fnode_is_dir(fnode)) {
134 if ((unsigned)fnode->btree.n_used_nodes + (unsigned)fnode->btree.n_free_nodes != 134 if ((unsigned)fnode->btree.n_used_nodes + (unsigned)fnode->btree.n_free_nodes !=
135 (fnode->btree.internal ? 12 : 8)) { 135 (bp_internal(&fnode->btree) ? 12 : 8)) {
136 hpfs_error(s, 136 hpfs_error(s,
137 "bad number of nodes in fnode %08lx", 137 "bad number of nodes in fnode %08lx",
138 (unsigned long)ino); 138 (unsigned long)ino);
139 goto bail; 139 goto bail;
140 } 140 }
141 if (le16_to_cpu(fnode->btree.first_free) != 141 if (le16_to_cpu(fnode->btree.first_free) !=
142 8 + fnode->btree.n_used_nodes * (fnode->btree.internal ? 8 : 12)) { 142 8 + fnode->btree.n_used_nodes * (bp_internal(&fnode->btree) ? 8 : 12)) {
143 hpfs_error(s, 143 hpfs_error(s,
144 "bad first_free pointer in fnode %08lx", 144 "bad first_free pointer in fnode %08lx",
145 (unsigned long)ino); 145 (unsigned long)ino);
@@ -187,12 +187,12 @@ struct anode *hpfs_map_anode(struct super_block *s, anode_secno ano, struct buff
187 goto bail; 187 goto bail;
188 } 188 }
189 if ((unsigned)anode->btree.n_used_nodes + (unsigned)anode->btree.n_free_nodes != 189 if ((unsigned)anode->btree.n_used_nodes + (unsigned)anode->btree.n_free_nodes !=
190 (anode->btree.internal ? 60 : 40)) { 190 (bp_internal(&anode->btree) ? 60 : 40)) {
191 hpfs_error(s, "bad number of nodes in anode %08x", ano); 191 hpfs_error(s, "bad number of nodes in anode %08x", ano);
192 goto bail; 192 goto bail;
193 } 193 }
194 if (le16_to_cpu(anode->btree.first_free) != 194 if (le16_to_cpu(anode->btree.first_free) !=
195 8 + anode->btree.n_used_nodes * (anode->btree.internal ? 8 : 12)) { 195 8 + anode->btree.n_used_nodes * (bp_internal(&anode->btree) ? 8 : 12)) {
196 hpfs_error(s, "bad first_free pointer in anode %08x", ano); 196 hpfs_error(s, "bad first_free pointer in anode %08x", ano);
197 goto bail; 197 goto bail;
198 } 198 }
diff --git a/fs/hpfs/namei.c b/fs/hpfs/namei.c
index 30dd7b10b507..9083ef8af58c 100644
--- a/fs/hpfs/namei.c
+++ b/fs/hpfs/namei.c
@@ -70,7 +70,7 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
70 fnode->len = len; 70 fnode->len = len;
71 memcpy(fnode->name, name, len > 15 ? 15 : len); 71 memcpy(fnode->name, name, len > 15 ? 15 : len);
72 fnode->up = cpu_to_le32(dir->i_ino); 72 fnode->up = cpu_to_le32(dir->i_ino);
73 fnode->dirflag = 1; 73 fnode->flags |= FNODE_dir;
74 fnode->btree.n_free_nodes = 7; 74 fnode->btree.n_free_nodes = 7;
75 fnode->btree.n_used_nodes = 1; 75 fnode->btree.n_used_nodes = 1;
76 fnode->btree.first_free = cpu_to_le16(0x14); 76 fnode->btree.first_free = cpu_to_le16(0x14);
diff --git a/fs/hpfs/super.c b/fs/hpfs/super.c
index 54f6eccb79d9..706a12c083ea 100644
--- a/fs/hpfs/super.c
+++ b/fs/hpfs/super.c
@@ -572,7 +572,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
572 mark_buffer_dirty(bh2); 572 mark_buffer_dirty(bh2);
573 } 573 }
574 574
575 if (le32_to_cpu(spareblock->hotfixes_used) || le32_to_cpu(spareblock->n_spares_used)) { 575 if (spareblock->hotfixes_used || spareblock->n_spares_used) {
576 if (errs >= 2) { 576 if (errs >= 2) {
577 printk("HPFS: Hotfixes not supported here, try chkdsk\n"); 577 printk("HPFS: Hotfixes not supported here, try chkdsk\n");
578 mark_dirty(s, 0); 578 mark_dirty(s, 0);
@@ -645,7 +645,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
645 root->i_mtime.tv_nsec = 0; 645 root->i_mtime.tv_nsec = 0;
646 root->i_ctime.tv_sec = local_to_gmt(s, le32_to_cpu(de->creation_date)); 646 root->i_ctime.tv_sec = local_to_gmt(s, le32_to_cpu(de->creation_date));
647 root->i_ctime.tv_nsec = 0; 647 root->i_ctime.tv_nsec = 0;
648 hpfs_i(root)->i_ea_size = le16_to_cpu(de->ea_size); 648 hpfs_i(root)->i_ea_size = le32_to_cpu(de->ea_size);
649 hpfs_i(root)->i_parent_dir = root->i_ino; 649 hpfs_i(root)->i_parent_dir = root->i_ino;
650 if (root->i_size == -1) 650 if (root->i_size == -1)
651 root->i_size = 2048; 651 root->i_size = 2048;
diff --git a/fs/inode.c b/fs/inode.c
index c474c1d7062b..c99163b1b310 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1487,10 +1487,30 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
1487 return 0; 1487 return 0;
1488} 1488}
1489 1489
1490/*
1491 * This does the actual work of updating an inodes time or version. Must have
1492 * had called mnt_want_write() before calling this.
1493 */
1494static int update_time(struct inode *inode, struct timespec *time, int flags)
1495{
1496 if (inode->i_op->update_time)
1497 return inode->i_op->update_time(inode, time, flags);
1498
1499 if (flags & S_ATIME)
1500 inode->i_atime = *time;
1501 if (flags & S_VERSION)
1502 inode_inc_iversion(inode);
1503 if (flags & S_CTIME)
1504 inode->i_ctime = *time;
1505 if (flags & S_MTIME)
1506 inode->i_mtime = *time;
1507 mark_inode_dirty_sync(inode);
1508 return 0;
1509}
1510
1490/** 1511/**
1491 * touch_atime - update the access time 1512 * touch_atime - update the access time
1492 * @mnt: mount the inode is accessed on 1513 * @path: the &struct path to update
1493 * @dentry: dentry accessed
1494 * 1514 *
1495 * Update the accessed time on an inode and mark it for writeback. 1515 * Update the accessed time on an inode and mark it for writeback.
1496 * This function automatically handles read only file systems and media, 1516 * This function automatically handles read only file systems and media,
@@ -1525,12 +1545,83 @@ void touch_atime(struct path *path)
1525 if (mnt_want_write(mnt)) 1545 if (mnt_want_write(mnt))
1526 return; 1546 return;
1527 1547
1528 inode->i_atime = now; 1548 /*
1529 mark_inode_dirty_sync(inode); 1549 * File systems can error out when updating inodes if they need to
1550 * allocate new space to modify an inode (such is the case for
1551 * Btrfs), but since we touch atime while walking down the path we
1552 * really don't care if we failed to update the atime of the file,
1553 * so just ignore the return value.
1554 */
1555 update_time(inode, &now, S_ATIME);
1530 mnt_drop_write(mnt); 1556 mnt_drop_write(mnt);
1531} 1557}
1532EXPORT_SYMBOL(touch_atime); 1558EXPORT_SYMBOL(touch_atime);
1533 1559
1560/*
1561 * The logic we want is
1562 *
1563 * if suid or (sgid and xgrp)
1564 * remove privs
1565 */
1566int should_remove_suid(struct dentry *dentry)
1567{
1568 umode_t mode = dentry->d_inode->i_mode;
1569 int kill = 0;
1570
1571 /* suid always must be killed */
1572 if (unlikely(mode & S_ISUID))
1573 kill = ATTR_KILL_SUID;
1574
1575 /*
1576 * sgid without any exec bits is just a mandatory locking mark; leave
1577 * it alone. If some exec bits are set, it's a real sgid; kill it.
1578 */
1579 if (unlikely((mode & S_ISGID) && (mode & S_IXGRP)))
1580 kill |= ATTR_KILL_SGID;
1581
1582 if (unlikely(kill && !capable(CAP_FSETID) && S_ISREG(mode)))
1583 return kill;
1584
1585 return 0;
1586}
1587EXPORT_SYMBOL(should_remove_suid);
1588
1589static int __remove_suid(struct dentry *dentry, int kill)
1590{
1591 struct iattr newattrs;
1592
1593 newattrs.ia_valid = ATTR_FORCE | kill;
1594 return notify_change(dentry, &newattrs);
1595}
1596
1597int file_remove_suid(struct file *file)
1598{
1599 struct dentry *dentry = file->f_path.dentry;
1600 struct inode *inode = dentry->d_inode;
1601 int killsuid;
1602 int killpriv;
1603 int error = 0;
1604
1605 /* Fast path for nothing security related */
1606 if (IS_NOSEC(inode))
1607 return 0;
1608
1609 killsuid = should_remove_suid(dentry);
1610 killpriv = security_inode_need_killpriv(dentry);
1611
1612 if (killpriv < 0)
1613 return killpriv;
1614 if (killpriv)
1615 error = security_inode_killpriv(dentry);
1616 if (!error && killsuid)
1617 error = __remove_suid(dentry, killsuid);
1618 if (!error && (inode->i_sb->s_flags & MS_NOSEC))
1619 inode->i_flags |= S_NOSEC;
1620
1621 return error;
1622}
1623EXPORT_SYMBOL(file_remove_suid);
1624
1534/** 1625/**
1535 * file_update_time - update mtime and ctime time 1626 * file_update_time - update mtime and ctime time
1536 * @file: file accessed 1627 * @file: file accessed
@@ -1540,18 +1631,20 @@ EXPORT_SYMBOL(touch_atime);
1540 * usage in the file write path of filesystems, and filesystems may 1631 * usage in the file write path of filesystems, and filesystems may
1541 * choose to explicitly ignore update via this function with the 1632 * choose to explicitly ignore update via this function with the
1542 * S_NOCMTIME inode flag, e.g. for network filesystem where these 1633 * S_NOCMTIME inode flag, e.g. for network filesystem where these
1543 * timestamps are handled by the server. 1634 * timestamps are handled by the server. This can return an error for
1635 * file systems who need to allocate space in order to update an inode.
1544 */ 1636 */
1545 1637
1546void file_update_time(struct file *file) 1638int file_update_time(struct file *file)
1547{ 1639{
1548 struct inode *inode = file->f_path.dentry->d_inode; 1640 struct inode *inode = file->f_path.dentry->d_inode;
1549 struct timespec now; 1641 struct timespec now;
1550 enum { S_MTIME = 1, S_CTIME = 2, S_VERSION = 4 } sync_it = 0; 1642 int sync_it = 0;
1643 int ret;
1551 1644
1552 /* First try to exhaust all avenues to not sync */ 1645 /* First try to exhaust all avenues to not sync */
1553 if (IS_NOCMTIME(inode)) 1646 if (IS_NOCMTIME(inode))
1554 return; 1647 return 0;
1555 1648
1556 now = current_fs_time(inode->i_sb); 1649 now = current_fs_time(inode->i_sb);
1557 if (!timespec_equal(&inode->i_mtime, &now)) 1650 if (!timespec_equal(&inode->i_mtime, &now))
@@ -1564,21 +1657,16 @@ void file_update_time(struct file *file)
1564 sync_it |= S_VERSION; 1657 sync_it |= S_VERSION;
1565 1658
1566 if (!sync_it) 1659 if (!sync_it)
1567 return; 1660 return 0;
1568 1661
1569 /* Finally allowed to write? Takes lock. */ 1662 /* Finally allowed to write? Takes lock. */
1570 if (mnt_want_write_file(file)) 1663 if (mnt_want_write_file(file))
1571 return; 1664 return 0;
1572 1665
1573 /* Only change inode inside the lock region */ 1666 ret = update_time(inode, &now, sync_it);
1574 if (sync_it & S_VERSION)
1575 inode_inc_iversion(inode);
1576 if (sync_it & S_CTIME)
1577 inode->i_ctime = now;
1578 if (sync_it & S_MTIME)
1579 inode->i_mtime = now;
1580 mark_inode_dirty_sync(inode);
1581 mnt_drop_write_file(file); 1667 mnt_drop_write_file(file);
1668
1669 return ret;
1582} 1670}
1583EXPORT_SYMBOL(file_update_time); 1671EXPORT_SYMBOL(file_update_time);
1584 1672
diff --git a/fs/internal.h b/fs/internal.h
index 9962c59ba280..18bc216ea09d 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -56,7 +56,7 @@ extern int sb_prepare_remount_readonly(struct super_block *);
56 56
57extern void __init mnt_init(void); 57extern void __init mnt_init(void);
58 58
59DECLARE_BRLOCK(vfsmount_lock); 59extern struct lglock vfsmount_lock;
60 60
61 61
62/* 62/*
@@ -100,6 +100,7 @@ extern struct file *do_file_open_root(struct dentry *, struct vfsmount *,
100 100
101extern long do_handle_open(int mountdirfd, 101extern long do_handle_open(int mountdirfd,
102 struct file_handle __user *ufh, int open_flag); 102 struct file_handle __user *ufh, int open_flag);
103extern int open_check_o_direct(struct file *f);
103 104
104/* 105/*
105 * inode.c 106 * inode.c
diff --git a/fs/isofs/export.c b/fs/isofs/export.c
index dd4687ff30d0..aa4356d09eee 100644
--- a/fs/isofs/export.c
+++ b/fs/isofs/export.c
@@ -107,12 +107,11 @@ static struct dentry *isofs_export_get_parent(struct dentry *child)
107} 107}
108 108
109static int 109static int
110isofs_export_encode_fh(struct dentry *dentry, 110isofs_export_encode_fh(struct inode *inode,
111 __u32 *fh32, 111 __u32 *fh32,
112 int *max_len, 112 int *max_len,
113 int connectable) 113 struct inode *parent)
114{ 114{
115 struct inode * inode = dentry->d_inode;
116 struct iso_inode_info * ei = ISOFS_I(inode); 115 struct iso_inode_info * ei = ISOFS_I(inode);
117 int len = *max_len; 116 int len = *max_len;
118 int type = 1; 117 int type = 1;
@@ -124,7 +123,7 @@ isofs_export_encode_fh(struct dentry *dentry,
124 * offset of the inode and the upper 16 bits of fh32[1] to 123 * offset of the inode and the upper 16 bits of fh32[1] to
125 * hold the offset of the parent. 124 * hold the offset of the parent.
126 */ 125 */
127 if (connectable && (len < 5)) { 126 if (parent && (len < 5)) {
128 *max_len = 5; 127 *max_len = 5;
129 return 255; 128 return 255;
130 } else if (len < 3) { 129 } else if (len < 3) {
@@ -136,16 +135,12 @@ isofs_export_encode_fh(struct dentry *dentry,
136 fh32[0] = ei->i_iget5_block; 135 fh32[0] = ei->i_iget5_block;
137 fh16[2] = (__u16)ei->i_iget5_offset; /* fh16 [sic] */ 136 fh16[2] = (__u16)ei->i_iget5_offset; /* fh16 [sic] */
138 fh32[2] = inode->i_generation; 137 fh32[2] = inode->i_generation;
139 if (connectable && !S_ISDIR(inode->i_mode)) { 138 if (parent) {
140 struct inode *parent;
141 struct iso_inode_info *eparent; 139 struct iso_inode_info *eparent;
142 spin_lock(&dentry->d_lock);
143 parent = dentry->d_parent->d_inode;
144 eparent = ISOFS_I(parent); 140 eparent = ISOFS_I(parent);
145 fh32[3] = eparent->i_iget5_block; 141 fh32[3] = eparent->i_iget5_block;
146 fh16[3] = (__u16)eparent->i_iget5_offset; /* fh16 [sic] */ 142 fh16[3] = (__u16)eparent->i_iget5_offset; /* fh16 [sic] */
147 fh32[4] = parent->i_generation; 143 fh32[4] = parent->i_generation;
148 spin_unlock(&dentry->d_lock);
149 len = 5; 144 len = 5;
150 type = 2; 145 type = 2;
151 } 146 }
diff --git a/fs/jbd2/Kconfig b/fs/jbd2/Kconfig
index f32f346f4b0a..69a48c2944da 100644
--- a/fs/jbd2/Kconfig
+++ b/fs/jbd2/Kconfig
@@ -1,6 +1,8 @@
1config JBD2 1config JBD2
2 tristate 2 tristate
3 select CRC32 3 select CRC32
4 select CRYPTO
5 select CRYPTO_CRC32C
4 help 6 help
5 This is a generic journaling layer for block devices that support 7 This is a generic journaling layer for block devices that support
6 both 32-bit and 64-bit block numbers. It is currently used by 8 both 32-bit and 64-bit block numbers. It is currently used by
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 840f70f50792..216f4299f65e 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -85,6 +85,24 @@ nope:
85 __brelse(bh); 85 __brelse(bh);
86} 86}
87 87
88static void jbd2_commit_block_csum_set(journal_t *j,
89 struct journal_head *descriptor)
90{
91 struct commit_header *h;
92 __u32 csum;
93
94 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
95 return;
96
97 h = (struct commit_header *)(jh2bh(descriptor)->b_data);
98 h->h_chksum_type = 0;
99 h->h_chksum_size = 0;
100 h->h_chksum[0] = 0;
101 csum = jbd2_chksum(j, j->j_csum_seed, jh2bh(descriptor)->b_data,
102 j->j_blocksize);
103 h->h_chksum[0] = cpu_to_be32(csum);
104}
105
88/* 106/*
89 * Done it all: now submit the commit record. We should have 107 * Done it all: now submit the commit record. We should have
90 * cleaned up our previous buffers by now, so if we are in abort 108 * cleaned up our previous buffers by now, so if we are in abort
@@ -128,6 +146,7 @@ static int journal_submit_commit_record(journal_t *journal,
128 tmp->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE; 146 tmp->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE;
129 tmp->h_chksum[0] = cpu_to_be32(crc32_sum); 147 tmp->h_chksum[0] = cpu_to_be32(crc32_sum);
130 } 148 }
149 jbd2_commit_block_csum_set(journal, descriptor);
131 150
132 JBUFFER_TRACE(descriptor, "submit commit block"); 151 JBUFFER_TRACE(descriptor, "submit commit block");
133 lock_buffer(bh); 152 lock_buffer(bh);
@@ -301,6 +320,44 @@ static void write_tag_block(int tag_bytes, journal_block_tag_t *tag,
301 tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1); 320 tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1);
302} 321}
303 322
323static void jbd2_descr_block_csum_set(journal_t *j,
324 struct journal_head *descriptor)
325{
326 struct jbd2_journal_block_tail *tail;
327 __u32 csum;
328
329 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
330 return;
331
332 tail = (struct jbd2_journal_block_tail *)
333 (jh2bh(descriptor)->b_data + j->j_blocksize -
334 sizeof(struct jbd2_journal_block_tail));
335 tail->t_checksum = 0;
336 csum = jbd2_chksum(j, j->j_csum_seed, jh2bh(descriptor)->b_data,
337 j->j_blocksize);
338 tail->t_checksum = cpu_to_be32(csum);
339}
340
341static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
342 struct buffer_head *bh, __u32 sequence)
343{
344 struct page *page = bh->b_page;
345 __u8 *addr;
346 __u32 csum;
347
348 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
349 return;
350
351 sequence = cpu_to_be32(sequence);
352 addr = kmap_atomic(page, KM_USER0);
353 csum = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence,
354 sizeof(sequence));
355 csum = jbd2_chksum(j, csum, addr + offset_in_page(bh->b_data),
356 bh->b_size);
357 kunmap_atomic(addr, KM_USER0);
358
359 tag->t_checksum = cpu_to_be32(csum);
360}
304/* 361/*
305 * jbd2_journal_commit_transaction 362 * jbd2_journal_commit_transaction
306 * 363 *
@@ -334,6 +391,10 @@ void jbd2_journal_commit_transaction(journal_t *journal)
334 unsigned long first_block; 391 unsigned long first_block;
335 tid_t first_tid; 392 tid_t first_tid;
336 int update_tail; 393 int update_tail;
394 int csum_size = 0;
395
396 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2))
397 csum_size = sizeof(struct jbd2_journal_block_tail);
337 398
338 /* 399 /*
339 * First job: lock down the current transaction and wait for 400 * First job: lock down the current transaction and wait for
@@ -627,7 +688,9 @@ void jbd2_journal_commit_transaction(journal_t *journal)
627 688
628 tag = (journal_block_tag_t *) tagp; 689 tag = (journal_block_tag_t *) tagp;
629 write_tag_block(tag_bytes, tag, jh2bh(jh)->b_blocknr); 690 write_tag_block(tag_bytes, tag, jh2bh(jh)->b_blocknr);
630 tag->t_flags = cpu_to_be32(tag_flag); 691 tag->t_flags = cpu_to_be16(tag_flag);
692 jbd2_block_tag_csum_set(journal, tag, jh2bh(new_jh),
693 commit_transaction->t_tid);
631 tagp += tag_bytes; 694 tagp += tag_bytes;
632 space_left -= tag_bytes; 695 space_left -= tag_bytes;
633 696
@@ -643,7 +706,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
643 706
644 if (bufs == journal->j_wbufsize || 707 if (bufs == journal->j_wbufsize ||
645 commit_transaction->t_buffers == NULL || 708 commit_transaction->t_buffers == NULL ||
646 space_left < tag_bytes + 16) { 709 space_left < tag_bytes + 16 + csum_size) {
647 710
648 jbd_debug(4, "JBD2: Submit %d IOs\n", bufs); 711 jbd_debug(4, "JBD2: Submit %d IOs\n", bufs);
649 712
@@ -651,8 +714,9 @@ void jbd2_journal_commit_transaction(journal_t *journal)
651 submitting the IOs. "tag" still points to 714 submitting the IOs. "tag" still points to
652 the last tag we set up. */ 715 the last tag we set up. */
653 716
654 tag->t_flags |= cpu_to_be32(JBD2_FLAG_LAST_TAG); 717 tag->t_flags |= cpu_to_be16(JBD2_FLAG_LAST_TAG);
655 718
719 jbd2_descr_block_csum_set(journal, descriptor);
656start_journal_io: 720start_journal_io:
657 for (i = 0; i < bufs; i++) { 721 for (i = 0; i < bufs; i++) {
658 struct buffer_head *bh = wbuf[i]; 722 struct buffer_head *bh = wbuf[i];
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 1afb701622b0..e9a3c4c85594 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -97,6 +97,43 @@ EXPORT_SYMBOL(jbd2_inode_cache);
97static void __journal_abort_soft (journal_t *journal, int errno); 97static void __journal_abort_soft (journal_t *journal, int errno);
98static int jbd2_journal_create_slab(size_t slab_size); 98static int jbd2_journal_create_slab(size_t slab_size);
99 99
100/* Checksumming functions */
101int jbd2_verify_csum_type(journal_t *j, journal_superblock_t *sb)
102{
103 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
104 return 1;
105
106 return sb->s_checksum_type == JBD2_CRC32C_CHKSUM;
107}
108
109static __u32 jbd2_superblock_csum(journal_t *j, journal_superblock_t *sb)
110{
111 __u32 csum, old_csum;
112
113 old_csum = sb->s_checksum;
114 sb->s_checksum = 0;
115 csum = jbd2_chksum(j, ~0, (char *)sb, sizeof(journal_superblock_t));
116 sb->s_checksum = old_csum;
117
118 return cpu_to_be32(csum);
119}
120
121int jbd2_superblock_csum_verify(journal_t *j, journal_superblock_t *sb)
122{
123 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
124 return 1;
125
126 return sb->s_checksum == jbd2_superblock_csum(j, sb);
127}
128
129void jbd2_superblock_csum_set(journal_t *j, journal_superblock_t *sb)
130{
131 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
132 return;
133
134 sb->s_checksum = jbd2_superblock_csum(j, sb);
135}
136
100/* 137/*
101 * Helper function used to manage commit timeouts 138 * Helper function used to manage commit timeouts
102 */ 139 */
@@ -1348,6 +1385,7 @@ static void jbd2_journal_update_sb_errno(journal_t *journal)
1348 jbd_debug(1, "JBD2: updating superblock error (errno %d)\n", 1385 jbd_debug(1, "JBD2: updating superblock error (errno %d)\n",
1349 journal->j_errno); 1386 journal->j_errno);
1350 sb->s_errno = cpu_to_be32(journal->j_errno); 1387 sb->s_errno = cpu_to_be32(journal->j_errno);
1388 jbd2_superblock_csum_set(journal, sb);
1351 read_unlock(&journal->j_state_lock); 1389 read_unlock(&journal->j_state_lock);
1352 1390
1353 jbd2_write_superblock(journal, WRITE_SYNC); 1391 jbd2_write_superblock(journal, WRITE_SYNC);
@@ -1376,6 +1414,9 @@ static int journal_get_superblock(journal_t *journal)
1376 } 1414 }
1377 } 1415 }
1378 1416
1417 if (buffer_verified(bh))
1418 return 0;
1419
1379 sb = journal->j_superblock; 1420 sb = journal->j_superblock;
1380 1421
1381 err = -EINVAL; 1422 err = -EINVAL;
@@ -1413,6 +1454,43 @@ static int journal_get_superblock(journal_t *journal)
1413 goto out; 1454 goto out;
1414 } 1455 }
1415 1456
1457 if (JBD2_HAS_COMPAT_FEATURE(journal, JBD2_FEATURE_COMPAT_CHECKSUM) &&
1458 JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2)) {
1459 /* Can't have checksum v1 and v2 on at the same time! */
1460 printk(KERN_ERR "JBD: Can't enable checksumming v1 and v2 "
1461 "at the same time!\n");
1462 goto out;
1463 }
1464
1465 if (!jbd2_verify_csum_type(journal, sb)) {
1466 printk(KERN_ERR "JBD: Unknown checksum type\n");
1467 goto out;
1468 }
1469
1470 /* Load the checksum driver */
1471 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2)) {
1472 journal->j_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
1473 if (IS_ERR(journal->j_chksum_driver)) {
1474 printk(KERN_ERR "JBD: Cannot load crc32c driver.\n");
1475 err = PTR_ERR(journal->j_chksum_driver);
1476 journal->j_chksum_driver = NULL;
1477 goto out;
1478 }
1479 }
1480
1481 /* Check superblock checksum */
1482 if (!jbd2_superblock_csum_verify(journal, sb)) {
1483 printk(KERN_ERR "JBD: journal checksum error\n");
1484 goto out;
1485 }
1486
1487 /* Precompute checksum seed for all metadata */
1488 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2))
1489 journal->j_csum_seed = jbd2_chksum(journal, ~0, sb->s_uuid,
1490 sizeof(sb->s_uuid));
1491
1492 set_buffer_verified(bh);
1493
1416 return 0; 1494 return 0;
1417 1495
1418out: 1496out:
@@ -1564,6 +1642,8 @@ int jbd2_journal_destroy(journal_t *journal)
1564 iput(journal->j_inode); 1642 iput(journal->j_inode);
1565 if (journal->j_revoke) 1643 if (journal->j_revoke)
1566 jbd2_journal_destroy_revoke(journal); 1644 jbd2_journal_destroy_revoke(journal);
1645 if (journal->j_chksum_driver)
1646 crypto_free_shash(journal->j_chksum_driver);
1567 kfree(journal->j_wbuf); 1647 kfree(journal->j_wbuf);
1568 kfree(journal); 1648 kfree(journal);
1569 1649
@@ -1653,6 +1733,10 @@ int jbd2_journal_check_available_features (journal_t *journal, unsigned long com
1653int jbd2_journal_set_features (journal_t *journal, unsigned long compat, 1733int jbd2_journal_set_features (journal_t *journal, unsigned long compat,
1654 unsigned long ro, unsigned long incompat) 1734 unsigned long ro, unsigned long incompat)
1655{ 1735{
1736#define INCOMPAT_FEATURE_ON(f) \
1737 ((incompat & (f)) && !(sb->s_feature_incompat & cpu_to_be32(f)))
1738#define COMPAT_FEATURE_ON(f) \
1739 ((compat & (f)) && !(sb->s_feature_compat & cpu_to_be32(f)))
1656 journal_superblock_t *sb; 1740 journal_superblock_t *sb;
1657 1741
1658 if (jbd2_journal_check_used_features(journal, compat, ro, incompat)) 1742 if (jbd2_journal_check_used_features(journal, compat, ro, incompat))
@@ -1661,16 +1745,54 @@ int jbd2_journal_set_features (journal_t *journal, unsigned long compat,
1661 if (!jbd2_journal_check_available_features(journal, compat, ro, incompat)) 1745 if (!jbd2_journal_check_available_features(journal, compat, ro, incompat))
1662 return 0; 1746 return 0;
1663 1747
1748 /* Asking for checksumming v2 and v1? Only give them v2. */
1749 if (incompat & JBD2_FEATURE_INCOMPAT_CSUM_V2 &&
1750 compat & JBD2_FEATURE_COMPAT_CHECKSUM)
1751 compat &= ~JBD2_FEATURE_COMPAT_CHECKSUM;
1752
1664 jbd_debug(1, "Setting new features 0x%lx/0x%lx/0x%lx\n", 1753 jbd_debug(1, "Setting new features 0x%lx/0x%lx/0x%lx\n",
1665 compat, ro, incompat); 1754 compat, ro, incompat);
1666 1755
1667 sb = journal->j_superblock; 1756 sb = journal->j_superblock;
1668 1757
1758 /* If enabling v2 checksums, update superblock */
1759 if (INCOMPAT_FEATURE_ON(JBD2_FEATURE_INCOMPAT_CSUM_V2)) {
1760 sb->s_checksum_type = JBD2_CRC32C_CHKSUM;
1761 sb->s_feature_compat &=
1762 ~cpu_to_be32(JBD2_FEATURE_COMPAT_CHECKSUM);
1763
1764 /* Load the checksum driver */
1765 if (journal->j_chksum_driver == NULL) {
1766 journal->j_chksum_driver = crypto_alloc_shash("crc32c",
1767 0, 0);
1768 if (IS_ERR(journal->j_chksum_driver)) {
1769 printk(KERN_ERR "JBD: Cannot load crc32c "
1770 "driver.\n");
1771 journal->j_chksum_driver = NULL;
1772 return 0;
1773 }
1774 }
1775
1776 /* Precompute checksum seed for all metadata */
1777 if (JBD2_HAS_INCOMPAT_FEATURE(journal,
1778 JBD2_FEATURE_INCOMPAT_CSUM_V2))
1779 journal->j_csum_seed = jbd2_chksum(journal, ~0,
1780 sb->s_uuid,
1781 sizeof(sb->s_uuid));
1782 }
1783
1784 /* If enabling v1 checksums, downgrade superblock */
1785 if (COMPAT_FEATURE_ON(JBD2_FEATURE_COMPAT_CHECKSUM))
1786 sb->s_feature_incompat &=
1787 ~cpu_to_be32(JBD2_FEATURE_INCOMPAT_CSUM_V2);
1788
1669 sb->s_feature_compat |= cpu_to_be32(compat); 1789 sb->s_feature_compat |= cpu_to_be32(compat);
1670 sb->s_feature_ro_compat |= cpu_to_be32(ro); 1790 sb->s_feature_ro_compat |= cpu_to_be32(ro);
1671 sb->s_feature_incompat |= cpu_to_be32(incompat); 1791 sb->s_feature_incompat |= cpu_to_be32(incompat);
1672 1792
1673 return 1; 1793 return 1;
1794#undef COMPAT_FEATURE_ON
1795#undef INCOMPAT_FEATURE_ON
1674} 1796}
1675 1797
1676/* 1798/*
@@ -1975,10 +2097,16 @@ int jbd2_journal_blocks_per_page(struct inode *inode)
1975 */ 2097 */
1976size_t journal_tag_bytes(journal_t *journal) 2098size_t journal_tag_bytes(journal_t *journal)
1977{ 2099{
2100 journal_block_tag_t tag;
2101 size_t x = 0;
2102
2103 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2))
2104 x += sizeof(tag.t_checksum);
2105
1978 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT)) 2106 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
1979 return JBD2_TAG_SIZE64; 2107 return x + JBD2_TAG_SIZE64;
1980 else 2108 else
1981 return JBD2_TAG_SIZE32; 2109 return x + JBD2_TAG_SIZE32;
1982} 2110}
1983 2111
1984/* 2112/*
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
index c1a03354a22f..0131e4362534 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -174,6 +174,25 @@ static int jread(struct buffer_head **bhp, journal_t *journal,
174 return 0; 174 return 0;
175} 175}
176 176
177static int jbd2_descr_block_csum_verify(journal_t *j,
178 void *buf)
179{
180 struct jbd2_journal_block_tail *tail;
181 __u32 provided, calculated;
182
183 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
184 return 1;
185
186 tail = (struct jbd2_journal_block_tail *)(buf + j->j_blocksize -
187 sizeof(struct jbd2_journal_block_tail));
188 provided = tail->t_checksum;
189 tail->t_checksum = 0;
190 calculated = jbd2_chksum(j, j->j_csum_seed, buf, j->j_blocksize);
191 tail->t_checksum = provided;
192
193 provided = be32_to_cpu(provided);
194 return provided == calculated;
195}
177 196
178/* 197/*
179 * Count the number of in-use tags in a journal descriptor block. 198 * Count the number of in-use tags in a journal descriptor block.
@@ -186,6 +205,9 @@ static int count_tags(journal_t *journal, struct buffer_head *bh)
186 int nr = 0, size = journal->j_blocksize; 205 int nr = 0, size = journal->j_blocksize;
187 int tag_bytes = journal_tag_bytes(journal); 206 int tag_bytes = journal_tag_bytes(journal);
188 207
208 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2))
209 size -= sizeof(struct jbd2_journal_block_tail);
210
189 tagp = &bh->b_data[sizeof(journal_header_t)]; 211 tagp = &bh->b_data[sizeof(journal_header_t)];
190 212
191 while ((tagp - bh->b_data + tag_bytes) <= size) { 213 while ((tagp - bh->b_data + tag_bytes) <= size) {
@@ -193,10 +215,10 @@ static int count_tags(journal_t *journal, struct buffer_head *bh)
193 215
194 nr++; 216 nr++;
195 tagp += tag_bytes; 217 tagp += tag_bytes;
196 if (!(tag->t_flags & cpu_to_be32(JBD2_FLAG_SAME_UUID))) 218 if (!(tag->t_flags & cpu_to_be16(JBD2_FLAG_SAME_UUID)))
197 tagp += 16; 219 tagp += 16;
198 220
199 if (tag->t_flags & cpu_to_be32(JBD2_FLAG_LAST_TAG)) 221 if (tag->t_flags & cpu_to_be16(JBD2_FLAG_LAST_TAG))
200 break; 222 break;
201 } 223 }
202 224
@@ -353,6 +375,41 @@ static int calc_chksums(journal_t *journal, struct buffer_head *bh,
353 return 0; 375 return 0;
354} 376}
355 377
378static int jbd2_commit_block_csum_verify(journal_t *j, void *buf)
379{
380 struct commit_header *h;
381 __u32 provided, calculated;
382
383 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
384 return 1;
385
386 h = buf;
387 provided = h->h_chksum[0];
388 h->h_chksum[0] = 0;
389 calculated = jbd2_chksum(j, j->j_csum_seed, buf, j->j_blocksize);
390 h->h_chksum[0] = provided;
391
392 provided = be32_to_cpu(provided);
393 return provided == calculated;
394}
395
396static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag,
397 void *buf, __u32 sequence)
398{
399 __u32 provided, calculated;
400
401 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
402 return 1;
403
404 sequence = cpu_to_be32(sequence);
405 calculated = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence,
406 sizeof(sequence));
407 calculated = jbd2_chksum(j, calculated, buf, j->j_blocksize);
408 provided = be32_to_cpu(tag->t_checksum);
409
410 return provided == cpu_to_be32(calculated);
411}
412
356static int do_one_pass(journal_t *journal, 413static int do_one_pass(journal_t *journal,
357 struct recovery_info *info, enum passtype pass) 414 struct recovery_info *info, enum passtype pass)
358{ 415{
@@ -366,6 +423,7 @@ static int do_one_pass(journal_t *journal,
366 int blocktype; 423 int blocktype;
367 int tag_bytes = journal_tag_bytes(journal); 424 int tag_bytes = journal_tag_bytes(journal);
368 __u32 crc32_sum = ~0; /* Transactional Checksums */ 425 __u32 crc32_sum = ~0; /* Transactional Checksums */
426 int descr_csum_size = 0;
369 427
370 /* 428 /*
371 * First thing is to establish what we expect to find in the log 429 * First thing is to establish what we expect to find in the log
@@ -451,6 +509,18 @@ static int do_one_pass(journal_t *journal,
451 509
452 switch(blocktype) { 510 switch(blocktype) {
453 case JBD2_DESCRIPTOR_BLOCK: 511 case JBD2_DESCRIPTOR_BLOCK:
512 /* Verify checksum first */
513 if (JBD2_HAS_INCOMPAT_FEATURE(journal,
514 JBD2_FEATURE_INCOMPAT_CSUM_V2))
515 descr_csum_size =
516 sizeof(struct jbd2_journal_block_tail);
517 if (descr_csum_size > 0 &&
518 !jbd2_descr_block_csum_verify(journal,
519 bh->b_data)) {
520 err = -EIO;
521 goto failed;
522 }
523
454 /* If it is a valid descriptor block, replay it 524 /* If it is a valid descriptor block, replay it
455 * in pass REPLAY; if journal_checksums enabled, then 525 * in pass REPLAY; if journal_checksums enabled, then
456 * calculate checksums in PASS_SCAN, otherwise, 526 * calculate checksums in PASS_SCAN, otherwise,
@@ -481,11 +551,11 @@ static int do_one_pass(journal_t *journal,
481 551
482 tagp = &bh->b_data[sizeof(journal_header_t)]; 552 tagp = &bh->b_data[sizeof(journal_header_t)];
483 while ((tagp - bh->b_data + tag_bytes) 553 while ((tagp - bh->b_data + tag_bytes)
484 <= journal->j_blocksize) { 554 <= journal->j_blocksize - descr_csum_size) {
485 unsigned long io_block; 555 unsigned long io_block;
486 556
487 tag = (journal_block_tag_t *) tagp; 557 tag = (journal_block_tag_t *) tagp;
488 flags = be32_to_cpu(tag->t_flags); 558 flags = be16_to_cpu(tag->t_flags);
489 559
490 io_block = next_log_block++; 560 io_block = next_log_block++;
491 wrap(journal, next_log_block); 561 wrap(journal, next_log_block);
@@ -516,6 +586,19 @@ static int do_one_pass(journal_t *journal,
516 goto skip_write; 586 goto skip_write;
517 } 587 }
518 588
589 /* Look for block corruption */
590 if (!jbd2_block_tag_csum_verify(
591 journal, tag, obh->b_data,
592 be32_to_cpu(tmp->h_sequence))) {
593 brelse(obh);
594 success = -EIO;
595 printk(KERN_ERR "JBD: Invalid "
596 "checksum recovering "
597 "block %llu in log\n",
598 blocknr);
599 continue;
600 }
601
519 /* Find a buffer for the new 602 /* Find a buffer for the new
520 * data being restored */ 603 * data being restored */
521 nbh = __getblk(journal->j_fs_dev, 604 nbh = __getblk(journal->j_fs_dev,
@@ -650,6 +733,19 @@ static int do_one_pass(journal_t *journal,
650 } 733 }
651 crc32_sum = ~0; 734 crc32_sum = ~0;
652 } 735 }
736 if (pass == PASS_SCAN &&
737 !jbd2_commit_block_csum_verify(journal,
738 bh->b_data)) {
739 info->end_transaction = next_commit_ID;
740
741 if (!JBD2_HAS_INCOMPAT_FEATURE(journal,
742 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
743 journal->j_failed_commit =
744 next_commit_ID;
745 brelse(bh);
746 break;
747 }
748 }
653 brelse(bh); 749 brelse(bh);
654 next_commit_ID++; 750 next_commit_ID++;
655 continue; 751 continue;
@@ -706,6 +802,25 @@ static int do_one_pass(journal_t *journal,
706 return err; 802 return err;
707} 803}
708 804
805static int jbd2_revoke_block_csum_verify(journal_t *j,
806 void *buf)
807{
808 struct jbd2_journal_revoke_tail *tail;
809 __u32 provided, calculated;
810
811 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
812 return 1;
813
814 tail = (struct jbd2_journal_revoke_tail *)(buf + j->j_blocksize -
815 sizeof(struct jbd2_journal_revoke_tail));
816 provided = tail->r_checksum;
817 tail->r_checksum = 0;
818 calculated = jbd2_chksum(j, j->j_csum_seed, buf, j->j_blocksize);
819 tail->r_checksum = provided;
820
821 provided = be32_to_cpu(provided);
822 return provided == calculated;
823}
709 824
710/* Scan a revoke record, marking all blocks mentioned as revoked. */ 825/* Scan a revoke record, marking all blocks mentioned as revoked. */
711 826
@@ -720,6 +835,9 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
720 offset = sizeof(jbd2_journal_revoke_header_t); 835 offset = sizeof(jbd2_journal_revoke_header_t);
721 max = be32_to_cpu(header->r_count); 836 max = be32_to_cpu(header->r_count);
722 837
838 if (!jbd2_revoke_block_csum_verify(journal, header))
839 return -EINVAL;
840
723 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT)) 841 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
724 record_len = 8; 842 record_len = 8;
725 843
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
index 6973705d6a3d..f30b80b4ce8b 100644
--- a/fs/jbd2/revoke.c
+++ b/fs/jbd2/revoke.c
@@ -578,6 +578,7 @@ static void write_one_revoke_record(journal_t *journal,
578 struct jbd2_revoke_record_s *record, 578 struct jbd2_revoke_record_s *record,
579 int write_op) 579 int write_op)
580{ 580{
581 int csum_size = 0;
581 struct journal_head *descriptor; 582 struct journal_head *descriptor;
582 int offset; 583 int offset;
583 journal_header_t *header; 584 journal_header_t *header;
@@ -592,9 +593,13 @@ static void write_one_revoke_record(journal_t *journal,
592 descriptor = *descriptorp; 593 descriptor = *descriptorp;
593 offset = *offsetp; 594 offset = *offsetp;
594 595
596 /* Do we need to leave space at the end for a checksum? */
597 if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2))
598 csum_size = sizeof(struct jbd2_journal_revoke_tail);
599
595 /* Make sure we have a descriptor with space left for the record */ 600 /* Make sure we have a descriptor with space left for the record */
596 if (descriptor) { 601 if (descriptor) {
597 if (offset == journal->j_blocksize) { 602 if (offset >= journal->j_blocksize - csum_size) {
598 flush_descriptor(journal, descriptor, offset, write_op); 603 flush_descriptor(journal, descriptor, offset, write_op);
599 descriptor = NULL; 604 descriptor = NULL;
600 } 605 }
@@ -631,6 +636,24 @@ static void write_one_revoke_record(journal_t *journal,
631 *offsetp = offset; 636 *offsetp = offset;
632} 637}
633 638
639static void jbd2_revoke_csum_set(journal_t *j,
640 struct journal_head *descriptor)
641{
642 struct jbd2_journal_revoke_tail *tail;
643 __u32 csum;
644
645 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
646 return;
647
648 tail = (struct jbd2_journal_revoke_tail *)
649 (jh2bh(descriptor)->b_data + j->j_blocksize -
650 sizeof(struct jbd2_journal_revoke_tail));
651 tail->r_checksum = 0;
652 csum = jbd2_chksum(j, j->j_csum_seed, jh2bh(descriptor)->b_data,
653 j->j_blocksize);
654 tail->r_checksum = cpu_to_be32(csum);
655}
656
634/* 657/*
635 * Flush a revoke descriptor out to the journal. If we are aborting, 658 * Flush a revoke descriptor out to the journal. If we are aborting,
636 * this is a noop; otherwise we are generating a buffer which needs to 659 * this is a noop; otherwise we are generating a buffer which needs to
@@ -652,6 +675,8 @@ static void flush_descriptor(journal_t *journal,
652 675
653 header = (jbd2_journal_revoke_header_t *) jh2bh(descriptor)->b_data; 676 header = (jbd2_journal_revoke_header_t *) jh2bh(descriptor)->b_data;
654 header->r_count = cpu_to_be32(offset); 677 header->r_count = cpu_to_be32(offset);
678 jbd2_revoke_csum_set(journal, descriptor);
679
655 set_buffer_jwrite(bh); 680 set_buffer_jwrite(bh);
656 BUFFER_TRACE(bh, "write"); 681 BUFFER_TRACE(bh, "write");
657 set_buffer_dirty(bh); 682 set_buffer_dirty(bh);
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index ddcd3549c6c2..fb1ab9533b67 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -162,8 +162,8 @@ static int start_this_handle(journal_t *journal, handle_t *handle,
162 162
163alloc_transaction: 163alloc_transaction:
164 if (!journal->j_running_transaction) { 164 if (!journal->j_running_transaction) {
165 new_transaction = kmem_cache_alloc(transaction_cache, 165 new_transaction = kmem_cache_zalloc(transaction_cache,
166 gfp_mask | __GFP_ZERO); 166 gfp_mask);
167 if (!new_transaction) { 167 if (!new_transaction) {
168 /* 168 /*
169 * If __GFP_FS is not present, then we may be 169 * If __GFP_FS is not present, then we may be
diff --git a/fs/jffs2/jffs2_fs_sb.h b/fs/jffs2/jffs2_fs_sb.h
index 55a0c1dceadf..413ef89c2d1b 100644
--- a/fs/jffs2/jffs2_fs_sb.h
+++ b/fs/jffs2/jffs2_fs_sb.h
@@ -32,6 +32,13 @@ struct jffs2_inodirty;
32struct jffs2_mount_opts { 32struct jffs2_mount_opts {
33 bool override_compr; 33 bool override_compr;
34 unsigned int compr; 34 unsigned int compr;
35
36 /* The size of the reserved pool. The reserved pool is the JFFS2 flash
37 * space which may only be used by root cannot be used by the other
38 * users. This is implemented simply by means of not allowing the
39 * latter users to write to the file system if the amount if the
40 * available space is less then 'rp_size'. */
41 unsigned int rp_size;
35}; 42};
36 43
37/* A struct for the overall file system control. Pointers to 44/* A struct for the overall file system control. Pointers to
@@ -126,6 +133,10 @@ struct jffs2_sb_info {
126 struct jffs2_inodirty *wbuf_inodes; 133 struct jffs2_inodirty *wbuf_inodes;
127 struct rw_semaphore wbuf_sem; /* Protects the write buffer */ 134 struct rw_semaphore wbuf_sem; /* Protects the write buffer */
128 135
136 struct delayed_work wbuf_dwork; /* write-buffer write-out work */
137 int wbuf_queued; /* non-zero delayed work is queued */
138 spinlock_t wbuf_dwork_lock; /* protects wbuf_dwork and and wbuf_queued */
139
129 unsigned char *oobbuf; 140 unsigned char *oobbuf;
130 int oobavail; /* How many bytes are available for JFFS2 in OOB */ 141 int oobavail; /* How many bytes are available for JFFS2 in OOB */
131#endif 142#endif
diff --git a/fs/jffs2/nodemgmt.c b/fs/jffs2/nodemgmt.c
index 6784d1e7a7eb..0c96eb52c797 100644
--- a/fs/jffs2/nodemgmt.c
+++ b/fs/jffs2/nodemgmt.c
@@ -18,6 +18,37 @@
18#include "nodelist.h" 18#include "nodelist.h"
19#include "debug.h" 19#include "debug.h"
20 20
21/*
22 * Check whether the user is allowed to write.
23 */
24static int jffs2_rp_can_write(struct jffs2_sb_info *c)
25{
26 uint32_t avail;
27 struct jffs2_mount_opts *opts = &c->mount_opts;
28
29 avail = c->dirty_size + c->free_size + c->unchecked_size +
30 c->erasing_size - c->resv_blocks_write * c->sector_size
31 - c->nospc_dirty_size;
32
33 if (avail < 2 * opts->rp_size)
34 jffs2_dbg(1, "rpsize %u, dirty_size %u, free_size %u, "
35 "erasing_size %u, unchecked_size %u, "
36 "nr_erasing_blocks %u, avail %u, resrv %u\n",
37 opts->rp_size, c->dirty_size, c->free_size,
38 c->erasing_size, c->unchecked_size,
39 c->nr_erasing_blocks, avail, c->nospc_dirty_size);
40
41 if (avail > opts->rp_size)
42 return 1;
43
44 /* Always allow root */
45 if (capable(CAP_SYS_RESOURCE))
46 return 1;
47
48 jffs2_dbg(1, "forbid writing\n");
49 return 0;
50}
51
21/** 52/**
22 * jffs2_reserve_space - request physical space to write nodes to flash 53 * jffs2_reserve_space - request physical space to write nodes to flash
23 * @c: superblock info 54 * @c: superblock info
@@ -55,6 +86,15 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
55 86
56 spin_lock(&c->erase_completion_lock); 87 spin_lock(&c->erase_completion_lock);
57 88
89 /*
90 * Check if the free space is greater then size of the reserved pool.
91 * If not, only allow root to proceed with writing.
92 */
93 if (prio != ALLOC_DELETION && !jffs2_rp_can_write(c)) {
94 ret = -ENOSPC;
95 goto out;
96 }
97
58 /* this needs a little more thought (true <tglx> :)) */ 98 /* this needs a little more thought (true <tglx> :)) */
59 while(ret == -EAGAIN) { 99 while(ret == -EAGAIN) {
60 while(c->nr_free_blocks + c->nr_erasing_blocks < blocksneeded) { 100 while(c->nr_free_blocks + c->nr_erasing_blocks < blocksneeded) {
@@ -158,6 +198,8 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
158 jffs2_dbg(1, "%s(): ret is %d\n", __func__, ret); 198 jffs2_dbg(1, "%s(): ret is %d\n", __func__, ret);
159 } 199 }
160 } 200 }
201
202out:
161 spin_unlock(&c->erase_completion_lock); 203 spin_unlock(&c->erase_completion_lock);
162 if (!ret) 204 if (!ret)
163 ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1); 205 ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1);
diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h
index 1cd3aec9d9ae..bcd983d7e7f9 100644
--- a/fs/jffs2/os-linux.h
+++ b/fs/jffs2/os-linux.h
@@ -95,6 +95,7 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
95#define jffs2_ubivol(c) (0) 95#define jffs2_ubivol(c) (0)
96#define jffs2_ubivol_setup(c) (0) 96#define jffs2_ubivol_setup(c) (0)
97#define jffs2_ubivol_cleanup(c) do {} while (0) 97#define jffs2_ubivol_cleanup(c) do {} while (0)
98#define jffs2_dirty_trigger(c) do {} while (0)
98 99
99#else /* NAND and/or ECC'd NOR support present */ 100#else /* NAND and/or ECC'd NOR support present */
100 101
@@ -135,14 +136,10 @@ void jffs2_ubivol_cleanup(struct jffs2_sb_info *c);
135#define jffs2_nor_wbuf_flash(c) (c->mtd->type == MTD_NORFLASH && ! (c->mtd->flags & MTD_BIT_WRITEABLE)) 136#define jffs2_nor_wbuf_flash(c) (c->mtd->type == MTD_NORFLASH && ! (c->mtd->flags & MTD_BIT_WRITEABLE))
136int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c); 137int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c);
137void jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c); 138void jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c);
139void jffs2_dirty_trigger(struct jffs2_sb_info *c);
138 140
139#endif /* WRITEBUFFER */ 141#endif /* WRITEBUFFER */
140 142
141static inline void jffs2_dirty_trigger(struct jffs2_sb_info *c)
142{
143 OFNI_BS_2SFFJ(c)->s_dirt = 1;
144}
145
146/* background.c */ 143/* background.c */
147int jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c); 144int jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c);
148void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c); 145void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c);
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index dc0437e84763..1ea349fff68b 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -1266,19 +1266,25 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
1266 /* Symlink's inode data is the target path. Read it and 1266 /* Symlink's inode data is the target path. Read it and
1267 * keep in RAM to facilitate quick follow symlink 1267 * keep in RAM to facilitate quick follow symlink
1268 * operation. */ 1268 * operation. */
1269 f->target = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL); 1269 uint32_t csize = je32_to_cpu(latest_node->csize);
1270 if (csize > JFFS2_MAX_NAME_LEN) {
1271 mutex_unlock(&f->sem);
1272 jffs2_do_clear_inode(c, f);
1273 return -ENAMETOOLONG;
1274 }
1275 f->target = kmalloc(csize + 1, GFP_KERNEL);
1270 if (!f->target) { 1276 if (!f->target) {
1271 JFFS2_ERROR("can't allocate %d bytes of memory for the symlink target path cache\n", je32_to_cpu(latest_node->csize)); 1277 JFFS2_ERROR("can't allocate %u bytes of memory for the symlink target path cache\n", csize);
1272 mutex_unlock(&f->sem); 1278 mutex_unlock(&f->sem);
1273 jffs2_do_clear_inode(c, f); 1279 jffs2_do_clear_inode(c, f);
1274 return -ENOMEM; 1280 return -ENOMEM;
1275 } 1281 }
1276 1282
1277 ret = jffs2_flash_read(c, ref_offset(rii.latest_ref) + sizeof(*latest_node), 1283 ret = jffs2_flash_read(c, ref_offset(rii.latest_ref) + sizeof(*latest_node),
1278 je32_to_cpu(latest_node->csize), &retlen, (char *)f->target); 1284 csize, &retlen, (char *)f->target);
1279 1285
1280 if (ret || retlen != je32_to_cpu(latest_node->csize)) { 1286 if (ret || retlen != csize) {
1281 if (retlen != je32_to_cpu(latest_node->csize)) 1287 if (retlen != csize)
1282 ret = -EIO; 1288 ret = -EIO;
1283 kfree(f->target); 1289 kfree(f->target);
1284 f->target = NULL; 1290 f->target = NULL;
@@ -1287,7 +1293,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
1287 return ret; 1293 return ret;
1288 } 1294 }
1289 1295
1290 f->target[je32_to_cpu(latest_node->csize)] = '\0'; 1296 f->target[csize] = '\0';
1291 dbg_readinode("symlink's target '%s' cached\n", f->target); 1297 dbg_readinode("symlink's target '%s' cached\n", f->target);
1292 } 1298 }
1293 1299
@@ -1415,6 +1421,7 @@ int jffs2_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *i
1415 mutex_unlock(&f->sem); 1421 mutex_unlock(&f->sem);
1416 jffs2_do_clear_inode(c, f); 1422 jffs2_do_clear_inode(c, f);
1417 } 1423 }
1424 jffs2_xattr_do_crccheck_inode(c, ic);
1418 kfree (f); 1425 kfree (f);
1419 return ret; 1426 return ret;
1420} 1427}
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index f9916f312bd8..61ea41389f90 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -63,21 +63,6 @@ static void jffs2_i_init_once(void *foo)
63 inode_init_once(&f->vfs_inode); 63 inode_init_once(&f->vfs_inode);
64} 64}
65 65
66static void jffs2_write_super(struct super_block *sb)
67{
68 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
69
70 lock_super(sb);
71 sb->s_dirt = 0;
72
73 if (!(sb->s_flags & MS_RDONLY)) {
74 jffs2_dbg(1, "%s()\n", __func__);
75 jffs2_flush_wbuf_gc(c, 0);
76 }
77
78 unlock_super(sb);
79}
80
81static const char *jffs2_compr_name(unsigned int compr) 66static const char *jffs2_compr_name(unsigned int compr)
82{ 67{
83 switch (compr) { 68 switch (compr) {
@@ -105,6 +90,8 @@ static int jffs2_show_options(struct seq_file *s, struct dentry *root)
105 90
106 if (opts->override_compr) 91 if (opts->override_compr)
107 seq_printf(s, ",compr=%s", jffs2_compr_name(opts->compr)); 92 seq_printf(s, ",compr=%s", jffs2_compr_name(opts->compr));
93 if (opts->rp_size)
94 seq_printf(s, ",rp_size=%u", opts->rp_size / 1024);
108 95
109 return 0; 96 return 0;
110} 97}
@@ -113,8 +100,6 @@ static int jffs2_sync_fs(struct super_block *sb, int wait)
113{ 100{
114 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); 101 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
115 102
116 jffs2_write_super(sb);
117
118 mutex_lock(&c->alloc_sem); 103 mutex_lock(&c->alloc_sem);
119 jffs2_flush_wbuf_pad(c); 104 jffs2_flush_wbuf_pad(c);
120 mutex_unlock(&c->alloc_sem); 105 mutex_unlock(&c->alloc_sem);
@@ -171,15 +156,18 @@ static const struct export_operations jffs2_export_ops = {
171 * JFFS2 mount options. 156 * JFFS2 mount options.
172 * 157 *
173 * Opt_override_compr: override default compressor 158 * Opt_override_compr: override default compressor
159 * Opt_rp_size: size of reserved pool in KiB
174 * Opt_err: just end of array marker 160 * Opt_err: just end of array marker
175 */ 161 */
176enum { 162enum {
177 Opt_override_compr, 163 Opt_override_compr,
164 Opt_rp_size,
178 Opt_err, 165 Opt_err,
179}; 166};
180 167
181static const match_table_t tokens = { 168static const match_table_t tokens = {
182 {Opt_override_compr, "compr=%s"}, 169 {Opt_override_compr, "compr=%s"},
170 {Opt_rp_size, "rp_size=%u"},
183 {Opt_err, NULL}, 171 {Opt_err, NULL},
184}; 172};
185 173
@@ -187,6 +175,7 @@ static int jffs2_parse_options(struct jffs2_sb_info *c, char *data)
187{ 175{
188 substring_t args[MAX_OPT_ARGS]; 176 substring_t args[MAX_OPT_ARGS];
189 char *p, *name; 177 char *p, *name;
178 unsigned int opt;
190 179
191 if (!data) 180 if (!data)
192 return 0; 181 return 0;
@@ -224,6 +213,17 @@ static int jffs2_parse_options(struct jffs2_sb_info *c, char *data)
224 kfree(name); 213 kfree(name);
225 c->mount_opts.override_compr = true; 214 c->mount_opts.override_compr = true;
226 break; 215 break;
216 case Opt_rp_size:
217 if (match_int(&args[0], &opt))
218 return -EINVAL;
219 opt *= 1024;
220 if (opt > c->mtd->size) {
221 pr_warn("Too large reserve pool specified, max "
222 "is %llu KB\n", c->mtd->size / 1024);
223 return -EINVAL;
224 }
225 c->mount_opts.rp_size = opt;
226 break;
227 default: 227 default:
228 pr_err("Error: unrecognized mount option '%s' or missing value\n", 228 pr_err("Error: unrecognized mount option '%s' or missing value\n",
229 p); 229 p);
@@ -251,7 +251,6 @@ static const struct super_operations jffs2_super_operations =
251 .alloc_inode = jffs2_alloc_inode, 251 .alloc_inode = jffs2_alloc_inode,
252 .destroy_inode =jffs2_destroy_inode, 252 .destroy_inode =jffs2_destroy_inode,
253 .put_super = jffs2_put_super, 253 .put_super = jffs2_put_super,
254 .write_super = jffs2_write_super,
255 .statfs = jffs2_statfs, 254 .statfs = jffs2_statfs,
256 .remount_fs = jffs2_remount_fs, 255 .remount_fs = jffs2_remount_fs,
257 .evict_inode = jffs2_evict_inode, 256 .evict_inode = jffs2_evict_inode,
@@ -319,9 +318,6 @@ static void jffs2_put_super (struct super_block *sb)
319 318
320 jffs2_dbg(2, "%s()\n", __func__); 319 jffs2_dbg(2, "%s()\n", __func__);
321 320
322 if (sb->s_dirt)
323 jffs2_write_super(sb);
324
325 mutex_lock(&c->alloc_sem); 321 mutex_lock(&c->alloc_sem);
326 jffs2_flush_wbuf_pad(c); 322 jffs2_flush_wbuf_pad(c);
327 mutex_unlock(&c->alloc_sem); 323 mutex_unlock(&c->alloc_sem);
diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
index 74d9be19df3f..6f4529d3697f 100644
--- a/fs/jffs2/wbuf.c
+++ b/fs/jffs2/wbuf.c
@@ -20,6 +20,7 @@
20#include <linux/mtd/nand.h> 20#include <linux/mtd/nand.h>
21#include <linux/jiffies.h> 21#include <linux/jiffies.h>
22#include <linux/sched.h> 22#include <linux/sched.h>
23#include <linux/writeback.h>
23 24
24#include "nodelist.h" 25#include "nodelist.h"
25 26
@@ -85,7 +86,7 @@ static void jffs2_wbuf_dirties_inode(struct jffs2_sb_info *c, uint32_t ino)
85{ 86{
86 struct jffs2_inodirty *new; 87 struct jffs2_inodirty *new;
87 88
88 /* Mark the superblock dirty so that kupdated will flush... */ 89 /* Schedule delayed write-buffer write-out */
89 jffs2_dirty_trigger(c); 90 jffs2_dirty_trigger(c);
90 91
91 if (jffs2_wbuf_pending_for_ino(c, ino)) 92 if (jffs2_wbuf_pending_for_ino(c, ino))
@@ -1148,6 +1149,47 @@ int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *
1148 return 1; 1149 return 1;
1149} 1150}
1150 1151
1152static struct jffs2_sb_info *work_to_sb(struct work_struct *work)
1153{
1154 struct delayed_work *dwork;
1155
1156 dwork = container_of(work, struct delayed_work, work);
1157 return container_of(dwork, struct jffs2_sb_info, wbuf_dwork);
1158}
1159
1160static void delayed_wbuf_sync(struct work_struct *work)
1161{
1162 struct jffs2_sb_info *c = work_to_sb(work);
1163 struct super_block *sb = OFNI_BS_2SFFJ(c);
1164
1165 spin_lock(&c->wbuf_dwork_lock);
1166 c->wbuf_queued = 0;
1167 spin_unlock(&c->wbuf_dwork_lock);
1168
1169 if (!(sb->s_flags & MS_RDONLY)) {
1170 jffs2_dbg(1, "%s()\n", __func__);
1171 jffs2_flush_wbuf_gc(c, 0);
1172 }
1173}
1174
1175void jffs2_dirty_trigger(struct jffs2_sb_info *c)
1176{
1177 struct super_block *sb = OFNI_BS_2SFFJ(c);
1178 unsigned long delay;
1179
1180 if (sb->s_flags & MS_RDONLY)
1181 return;
1182
1183 spin_lock(&c->wbuf_dwork_lock);
1184 if (!c->wbuf_queued) {
1185 jffs2_dbg(1, "%s()\n", __func__);
1186 delay = msecs_to_jiffies(dirty_writeback_interval * 10);
1187 queue_delayed_work(system_long_wq, &c->wbuf_dwork, delay);
1188 c->wbuf_queued = 1;
1189 }
1190 spin_unlock(&c->wbuf_dwork_lock);
1191}
1192
1151int jffs2_nand_flash_setup(struct jffs2_sb_info *c) 1193int jffs2_nand_flash_setup(struct jffs2_sb_info *c)
1152{ 1194{
1153 struct nand_ecclayout *oinfo = c->mtd->ecclayout; 1195 struct nand_ecclayout *oinfo = c->mtd->ecclayout;
@@ -1169,6 +1211,8 @@ int jffs2_nand_flash_setup(struct jffs2_sb_info *c)
1169 1211
1170 /* Initialise write buffer */ 1212 /* Initialise write buffer */
1171 init_rwsem(&c->wbuf_sem); 1213 init_rwsem(&c->wbuf_sem);
1214 spin_lock_init(&c->wbuf_dwork_lock);
1215 INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
1172 c->wbuf_pagesize = c->mtd->writesize; 1216 c->wbuf_pagesize = c->mtd->writesize;
1173 c->wbuf_ofs = 0xFFFFFFFF; 1217 c->wbuf_ofs = 0xFFFFFFFF;
1174 1218
@@ -1207,8 +1251,8 @@ int jffs2_dataflash_setup(struct jffs2_sb_info *c) {
1207 1251
1208 /* Initialize write buffer */ 1252 /* Initialize write buffer */
1209 init_rwsem(&c->wbuf_sem); 1253 init_rwsem(&c->wbuf_sem);
1210 1254 spin_lock_init(&c->wbuf_dwork_lock);
1211 1255 INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
1212 c->wbuf_pagesize = c->mtd->erasesize; 1256 c->wbuf_pagesize = c->mtd->erasesize;
1213 1257
1214 /* Find a suitable c->sector_size 1258 /* Find a suitable c->sector_size
@@ -1267,6 +1311,9 @@ int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c) {
1267 1311
1268 /* Initialize write buffer */ 1312 /* Initialize write buffer */
1269 init_rwsem(&c->wbuf_sem); 1313 init_rwsem(&c->wbuf_sem);
1314 spin_lock_init(&c->wbuf_dwork_lock);
1315 INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
1316
1270 c->wbuf_pagesize = c->mtd->writesize; 1317 c->wbuf_pagesize = c->mtd->writesize;
1271 c->wbuf_ofs = 0xFFFFFFFF; 1318 c->wbuf_ofs = 0xFFFFFFFF;
1272 1319
@@ -1299,6 +1346,8 @@ int jffs2_ubivol_setup(struct jffs2_sb_info *c) {
1299 return 0; 1346 return 0;
1300 1347
1301 init_rwsem(&c->wbuf_sem); 1348 init_rwsem(&c->wbuf_sem);
1349 spin_lock_init(&c->wbuf_dwork_lock);
1350 INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
1302 1351
1303 c->wbuf_pagesize = c->mtd->writesize; 1352 c->wbuf_pagesize = c->mtd->writesize;
1304 c->wbuf_ofs = 0xFFFFFFFF; 1353 c->wbuf_ofs = 0xFFFFFFFF;
diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
index b55b803eddcb..3034e970eb9a 100644
--- a/fs/jffs2/xattr.c
+++ b/fs/jffs2/xattr.c
@@ -11,6 +11,8 @@
11 11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 13
14#define JFFS2_XATTR_IS_CORRUPTED 1
15
14#include <linux/kernel.h> 16#include <linux/kernel.h>
15#include <linux/slab.h> 17#include <linux/slab.h>
16#include <linux/fs.h> 18#include <linux/fs.h>
@@ -153,7 +155,7 @@ static int do_verify_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_dat
153 JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", 155 JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n",
154 offset, je32_to_cpu(rx.hdr_crc), crc); 156 offset, je32_to_cpu(rx.hdr_crc), crc);
155 xd->flags |= JFFS2_XFLAGS_INVALID; 157 xd->flags |= JFFS2_XFLAGS_INVALID;
156 return -EIO; 158 return JFFS2_XATTR_IS_CORRUPTED;
157 } 159 }
158 totlen = PAD(sizeof(rx) + rx.name_len + 1 + je16_to_cpu(rx.value_len)); 160 totlen = PAD(sizeof(rx) + rx.name_len + 1 + je16_to_cpu(rx.value_len));
159 if (je16_to_cpu(rx.magic) != JFFS2_MAGIC_BITMASK 161 if (je16_to_cpu(rx.magic) != JFFS2_MAGIC_BITMASK
@@ -169,7 +171,7 @@ static int do_verify_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_dat
169 je32_to_cpu(rx.xid), xd->xid, 171 je32_to_cpu(rx.xid), xd->xid,
170 je32_to_cpu(rx.version), xd->version); 172 je32_to_cpu(rx.version), xd->version);
171 xd->flags |= JFFS2_XFLAGS_INVALID; 173 xd->flags |= JFFS2_XFLAGS_INVALID;
172 return -EIO; 174 return JFFS2_XATTR_IS_CORRUPTED;
173 } 175 }
174 xd->xprefix = rx.xprefix; 176 xd->xprefix = rx.xprefix;
175 xd->name_len = rx.name_len; 177 xd->name_len = rx.name_len;
@@ -227,12 +229,12 @@ static int do_load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum
227 data[xd->name_len] = '\0'; 229 data[xd->name_len] = '\0';
228 crc = crc32(0, data, length); 230 crc = crc32(0, data, length);
229 if (crc != xd->data_crc) { 231 if (crc != xd->data_crc) {
230 JFFS2_WARNING("node CRC failed (JFFS2_NODETYPE_XREF)" 232 JFFS2_WARNING("node CRC failed (JFFS2_NODETYPE_XATTR)"
231 " at %#08x, read: 0x%08x calculated: 0x%08x\n", 233 " at %#08x, read: 0x%08x calculated: 0x%08x\n",
232 ref_offset(xd->node), xd->data_crc, crc); 234 ref_offset(xd->node), xd->data_crc, crc);
233 kfree(data); 235 kfree(data);
234 xd->flags |= JFFS2_XFLAGS_INVALID; 236 xd->flags |= JFFS2_XFLAGS_INVALID;
235 return -EIO; 237 return JFFS2_XATTR_IS_CORRUPTED;
236 } 238 }
237 239
238 xd->flags |= JFFS2_XFLAGS_HOT; 240 xd->flags |= JFFS2_XFLAGS_HOT;
@@ -270,7 +272,7 @@ static int load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *x
270 if (xd->xname) 272 if (xd->xname)
271 return 0; 273 return 0;
272 if (xd->flags & JFFS2_XFLAGS_INVALID) 274 if (xd->flags & JFFS2_XFLAGS_INVALID)
273 return -EIO; 275 return JFFS2_XATTR_IS_CORRUPTED;
274 if (unlikely(is_xattr_datum_unchecked(c, xd))) 276 if (unlikely(is_xattr_datum_unchecked(c, xd)))
275 rc = do_verify_xattr_datum(c, xd); 277 rc = do_verify_xattr_datum(c, xd);
276 if (!rc) 278 if (!rc)
@@ -435,6 +437,8 @@ static void unrefer_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datu
435 * is called to release xattr related objects when unmounting. 437 * is called to release xattr related objects when unmounting.
436 * check_xattr_ref_inode(c, ic) 438 * check_xattr_ref_inode(c, ic)
437 * is used to confirm inode does not have duplicate xattr name/value pair. 439 * is used to confirm inode does not have duplicate xattr name/value pair.
440 * jffs2_xattr_do_crccheck_inode(c, ic)
441 * is used to force xattr data integrity check during the initial gc scan.
438 * -------------------------------------------------- */ 442 * -------------------------------------------------- */
439static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) 443static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
440{ 444{
@@ -462,7 +466,7 @@ static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref
462 if (crc != je32_to_cpu(rr.node_crc)) { 466 if (crc != je32_to_cpu(rr.node_crc)) {
463 JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n", 467 JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n",
464 offset, je32_to_cpu(rr.node_crc), crc); 468 offset, je32_to_cpu(rr.node_crc), crc);
465 return -EIO; 469 return JFFS2_XATTR_IS_CORRUPTED;
466 } 470 }
467 if (je16_to_cpu(rr.magic) != JFFS2_MAGIC_BITMASK 471 if (je16_to_cpu(rr.magic) != JFFS2_MAGIC_BITMASK
468 || je16_to_cpu(rr.nodetype) != JFFS2_NODETYPE_XREF 472 || je16_to_cpu(rr.nodetype) != JFFS2_NODETYPE_XREF
@@ -472,7 +476,7 @@ static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref
472 offset, je16_to_cpu(rr.magic), JFFS2_MAGIC_BITMASK, 476 offset, je16_to_cpu(rr.magic), JFFS2_MAGIC_BITMASK,
473 je16_to_cpu(rr.nodetype), JFFS2_NODETYPE_XREF, 477 je16_to_cpu(rr.nodetype), JFFS2_NODETYPE_XREF,
474 je32_to_cpu(rr.totlen), PAD(sizeof(rr))); 478 je32_to_cpu(rr.totlen), PAD(sizeof(rr)));
475 return -EIO; 479 return JFFS2_XATTR_IS_CORRUPTED;
476 } 480 }
477 ref->ino = je32_to_cpu(rr.ino); 481 ref->ino = je32_to_cpu(rr.ino);
478 ref->xid = je32_to_cpu(rr.xid); 482 ref->xid = je32_to_cpu(rr.xid);
@@ -682,6 +686,11 @@ static int check_xattr_ref_inode(struct jffs2_sb_info *c, struct jffs2_inode_cac
682 return rc; 686 return rc;
683} 687}
684 688
689void jffs2_xattr_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic)
690{
691 check_xattr_ref_inode(c, ic);
692}
693
685/* -------- xattr subsystem functions --------------- 694/* -------- xattr subsystem functions ---------------
686 * jffs2_init_xattr_subsystem(c) 695 * jffs2_init_xattr_subsystem(c)
687 * is used to initialize semaphore and list_head, and some variables. 696 * is used to initialize semaphore and list_head, and some variables.
diff --git a/fs/jffs2/xattr.h b/fs/jffs2/xattr.h
index 7be4beb306f3..467ff376ee26 100644
--- a/fs/jffs2/xattr.h
+++ b/fs/jffs2/xattr.h
@@ -77,6 +77,7 @@ extern void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c);
77extern struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c, 77extern struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c,
78 uint32_t xid, uint32_t version); 78 uint32_t xid, uint32_t version);
79 79
80extern void jffs2_xattr_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic);
80extern void jffs2_xattr_delete_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic); 81extern void jffs2_xattr_delete_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic);
81extern void jffs2_xattr_free_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic); 82extern void jffs2_xattr_free_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic);
82 83
@@ -108,6 +109,7 @@ extern ssize_t jffs2_listxattr(struct dentry *, char *, size_t);
108#define jffs2_build_xattr_subsystem(c) 109#define jffs2_build_xattr_subsystem(c)
109#define jffs2_clear_xattr_subsystem(c) 110#define jffs2_clear_xattr_subsystem(c)
110 111
112#define jffs2_xattr_do_crccheck_inode(c, ic)
111#define jffs2_xattr_delete_inode(c, ic) 113#define jffs2_xattr_delete_inode(c, ic)
112#define jffs2_xattr_free_inode(c, ic) 114#define jffs2_xattr_free_inode(c, ic)
113#define jffs2_verify_xattr(c) (1) 115#define jffs2_verify_xattr(c) (1)
diff --git a/fs/lockd/clntlock.c b/fs/lockd/clntlock.c
index ba1dc2eebd1e..ca0a08001449 100644
--- a/fs/lockd/clntlock.c
+++ b/fs/lockd/clntlock.c
@@ -56,7 +56,7 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)
56 u32 nlm_version = (nlm_init->nfs_version == 2) ? 1 : 4; 56 u32 nlm_version = (nlm_init->nfs_version == 2) ? 1 : 4;
57 int status; 57 int status;
58 58
59 status = lockd_up(); 59 status = lockd_up(nlm_init->net);
60 if (status < 0) 60 if (status < 0)
61 return ERR_PTR(status); 61 return ERR_PTR(status);
62 62
@@ -65,7 +65,7 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)
65 nlm_init->hostname, nlm_init->noresvport, 65 nlm_init->hostname, nlm_init->noresvport,
66 nlm_init->net); 66 nlm_init->net);
67 if (host == NULL) { 67 if (host == NULL) {
68 lockd_down(); 68 lockd_down(nlm_init->net);
69 return ERR_PTR(-ENOLCK); 69 return ERR_PTR(-ENOLCK);
70 } 70 }
71 71
@@ -80,8 +80,10 @@ EXPORT_SYMBOL_GPL(nlmclnt_init);
80 */ 80 */
81void nlmclnt_done(struct nlm_host *host) 81void nlmclnt_done(struct nlm_host *host)
82{ 82{
83 struct net *net = host->net;
84
83 nlmclnt_release_host(host); 85 nlmclnt_release_host(host);
84 lockd_down(); 86 lockd_down(net);
85} 87}
86EXPORT_SYMBOL_GPL(nlmclnt_done); 88EXPORT_SYMBOL_GPL(nlmclnt_done);
87 89
@@ -220,11 +222,12 @@ reclaimer(void *ptr)
220 struct nlm_wait *block; 222 struct nlm_wait *block;
221 struct file_lock *fl, *next; 223 struct file_lock *fl, *next;
222 u32 nsmstate; 224 u32 nsmstate;
225 struct net *net = host->net;
223 226
224 allow_signal(SIGKILL); 227 allow_signal(SIGKILL);
225 228
226 down_write(&host->h_rwsem); 229 down_write(&host->h_rwsem);
227 lockd_up(); /* note: this cannot fail as lockd is already running */ 230 lockd_up(net); /* note: this cannot fail as lockd is already running */
228 231
229 dprintk("lockd: reclaiming locks for host %s\n", host->h_name); 232 dprintk("lockd: reclaiming locks for host %s\n", host->h_name);
230 233
@@ -275,6 +278,6 @@ restart:
275 278
276 /* Release host handle after use */ 279 /* Release host handle after use */
277 nlmclnt_release_host(host); 280 nlmclnt_release_host(host);
278 lockd_down(); 281 lockd_down(net);
279 return 0; 282 return 0;
280} 283}
diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
index f49b9afc4436..80938fda67e0 100644
--- a/fs/lockd/svc.c
+++ b/fs/lockd/svc.c
@@ -251,39 +251,40 @@ out_err:
251 return err; 251 return err;
252} 252}
253 253
254static int lockd_up_net(struct net *net) 254static int lockd_up_net(struct svc_serv *serv, struct net *net)
255{ 255{
256 struct lockd_net *ln = net_generic(net, lockd_net_id); 256 struct lockd_net *ln = net_generic(net, lockd_net_id);
257 struct svc_serv *serv = nlmsvc_rqst->rq_server;
258 int error; 257 int error;
259 258
260 if (ln->nlmsvc_users) 259 if (ln->nlmsvc_users++)
261 return 0; 260 return 0;
262 261
263 error = svc_rpcb_setup(serv, net); 262 error = svc_bind(serv, net);
264 if (error) 263 if (error)
265 goto err_rpcb; 264 goto err_bind;
266 265
267 error = make_socks(serv, net); 266 error = make_socks(serv, net);
268 if (error < 0) 267 if (error < 0)
269 goto err_socks; 268 goto err_socks;
269 dprintk("lockd_up_net: per-net data created; net=%p\n", net);
270 return 0; 270 return 0;
271 271
272err_socks: 272err_socks:
273 svc_rpcb_cleanup(serv, net); 273 svc_rpcb_cleanup(serv, net);
274err_rpcb: 274err_bind:
275 ln->nlmsvc_users--;
275 return error; 276 return error;
276} 277}
277 278
278static void lockd_down_net(struct net *net) 279static void lockd_down_net(struct svc_serv *serv, struct net *net)
279{ 280{
280 struct lockd_net *ln = net_generic(net, lockd_net_id); 281 struct lockd_net *ln = net_generic(net, lockd_net_id);
281 struct svc_serv *serv = nlmsvc_rqst->rq_server;
282 282
283 if (ln->nlmsvc_users) { 283 if (ln->nlmsvc_users) {
284 if (--ln->nlmsvc_users == 0) { 284 if (--ln->nlmsvc_users == 0) {
285 nlm_shutdown_hosts_net(net); 285 nlm_shutdown_hosts_net(net);
286 svc_shutdown_net(serv, net); 286 svc_shutdown_net(serv, net);
287 dprintk("lockd_down_net: per-net data destroyed; net=%p\n", net);
287 } 288 }
288 } else { 289 } else {
289 printk(KERN_ERR "lockd_down_net: no users! task=%p, net=%p\n", 290 printk(KERN_ERR "lockd_down_net: no users! task=%p, net=%p\n",
@@ -292,22 +293,60 @@ static void lockd_down_net(struct net *net)
292 } 293 }
293} 294}
294 295
295/* 296static int lockd_start_svc(struct svc_serv *serv)
296 * Bring up the lockd process if it's not already up. 297{
297 */ 298 int error;
298int lockd_up(void) 299
300 if (nlmsvc_rqst)
301 return 0;
302
303 /*
304 * Create the kernel thread and wait for it to start.
305 */
306 nlmsvc_rqst = svc_prepare_thread(serv, &serv->sv_pools[0], NUMA_NO_NODE);
307 if (IS_ERR(nlmsvc_rqst)) {
308 error = PTR_ERR(nlmsvc_rqst);
309 printk(KERN_WARNING
310 "lockd_up: svc_rqst allocation failed, error=%d\n",
311 error);
312 goto out_rqst;
313 }
314
315 svc_sock_update_bufs(serv);
316 serv->sv_maxconn = nlm_max_connections;
317
318 nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
319 if (IS_ERR(nlmsvc_task)) {
320 error = PTR_ERR(nlmsvc_task);
321 printk(KERN_WARNING
322 "lockd_up: kthread_run failed, error=%d\n", error);
323 goto out_task;
324 }
325 dprintk("lockd_up: service started\n");
326 return 0;
327
328out_task:
329 svc_exit_thread(nlmsvc_rqst);
330 nlmsvc_task = NULL;
331out_rqst:
332 nlmsvc_rqst = NULL;
333 return error;
334}
335
336static struct svc_serv *lockd_create_svc(void)
299{ 337{
300 struct svc_serv *serv; 338 struct svc_serv *serv;
301 int error = 0;
302 struct net *net = current->nsproxy->net_ns;
303 339
304 mutex_lock(&nlmsvc_mutex);
305 /* 340 /*
306 * Check whether we're already up and running. 341 * Check whether we're already up and running.
307 */ 342 */
308 if (nlmsvc_rqst) { 343 if (nlmsvc_rqst) {
309 error = lockd_up_net(net); 344 /*
310 goto out; 345 * Note: increase service usage, because later in case of error
346 * svc_destroy() will be called.
347 */
348 svc_get(nlmsvc_rqst->rq_server);
349 return nlmsvc_rqst->rq_server;
311 } 350 }
312 351
313 /* 352 /*
@@ -318,59 +357,53 @@ int lockd_up(void)
318 printk(KERN_WARNING 357 printk(KERN_WARNING
319 "lockd_up: no pid, %d users??\n", nlmsvc_users); 358 "lockd_up: no pid, %d users??\n", nlmsvc_users);
320 359
321 error = -ENOMEM;
322 serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, NULL); 360 serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, NULL);
323 if (!serv) { 361 if (!serv) {
324 printk(KERN_WARNING "lockd_up: create service failed\n"); 362 printk(KERN_WARNING "lockd_up: create service failed\n");
325 goto out; 363 return ERR_PTR(-ENOMEM);
326 } 364 }
365 dprintk("lockd_up: service created\n");
366 return serv;
367}
327 368
328 error = make_socks(serv, net); 369/*
329 if (error < 0) 370 * Bring up the lockd process if it's not already up.
330 goto destroy_and_out; 371 */
372int lockd_up(struct net *net)
373{
374 struct svc_serv *serv;
375 int error;
331 376
332 /* 377 mutex_lock(&nlmsvc_mutex);
333 * Create the kernel thread and wait for it to start. 378
334 */ 379 serv = lockd_create_svc();
335 nlmsvc_rqst = svc_prepare_thread(serv, &serv->sv_pools[0], NUMA_NO_NODE); 380 if (IS_ERR(serv)) {
336 if (IS_ERR(nlmsvc_rqst)) { 381 error = PTR_ERR(serv);
337 error = PTR_ERR(nlmsvc_rqst); 382 goto err_create;
338 nlmsvc_rqst = NULL;
339 printk(KERN_WARNING
340 "lockd_up: svc_rqst allocation failed, error=%d\n",
341 error);
342 goto destroy_and_out;
343 } 383 }
344 384
345 svc_sock_update_bufs(serv); 385 error = lockd_up_net(serv, net);
346 serv->sv_maxconn = nlm_max_connections; 386 if (error < 0)
387 goto err_net;
347 388
348 nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name); 389 error = lockd_start_svc(serv);
349 if (IS_ERR(nlmsvc_task)) { 390 if (error < 0)
350 error = PTR_ERR(nlmsvc_task); 391 goto err_start;
351 svc_exit_thread(nlmsvc_rqst);
352 nlmsvc_task = NULL;
353 nlmsvc_rqst = NULL;
354 printk(KERN_WARNING
355 "lockd_up: kthread_run failed, error=%d\n", error);
356 goto destroy_and_out;
357 }
358 392
393 nlmsvc_users++;
359 /* 394 /*
360 * Note: svc_serv structures have an initial use count of 1, 395 * Note: svc_serv structures have an initial use count of 1,
361 * so we exit through here on both success and failure. 396 * so we exit through here on both success and failure.
362 */ 397 */
363destroy_and_out: 398err_net:
364 svc_destroy(serv); 399 svc_destroy(serv);
365out: 400err_create:
366 if (!error) {
367 struct lockd_net *ln = net_generic(net, lockd_net_id);
368
369 ln->nlmsvc_users++;
370 nlmsvc_users++;
371 }
372 mutex_unlock(&nlmsvc_mutex); 401 mutex_unlock(&nlmsvc_mutex);
373 return error; 402 return error;
403
404err_start:
405 lockd_down_net(serv, net);
406 goto err_net;
374} 407}
375EXPORT_SYMBOL_GPL(lockd_up); 408EXPORT_SYMBOL_GPL(lockd_up);
376 409
@@ -378,14 +411,13 @@ EXPORT_SYMBOL_GPL(lockd_up);
378 * Decrement the user count and bring down lockd if we're the last. 411 * Decrement the user count and bring down lockd if we're the last.
379 */ 412 */
380void 413void
381lockd_down(void) 414lockd_down(struct net *net)
382{ 415{
383 mutex_lock(&nlmsvc_mutex); 416 mutex_lock(&nlmsvc_mutex);
417 lockd_down_net(nlmsvc_rqst->rq_server, net);
384 if (nlmsvc_users) { 418 if (nlmsvc_users) {
385 if (--nlmsvc_users) { 419 if (--nlmsvc_users)
386 lockd_down_net(current->nsproxy->net_ns);
387 goto out; 420 goto out;
388 }
389 } else { 421 } else {
390 printk(KERN_ERR "lockd_down: no users! task=%p\n", 422 printk(KERN_ERR "lockd_down: no users! task=%p\n",
391 nlmsvc_task); 423 nlmsvc_task);
@@ -397,7 +429,9 @@ lockd_down(void)
397 BUG(); 429 BUG();
398 } 430 }
399 kthread_stop(nlmsvc_task); 431 kthread_stop(nlmsvc_task);
432 dprintk("lockd_down: service stopped\n");
400 svc_exit_thread(nlmsvc_rqst); 433 svc_exit_thread(nlmsvc_rqst);
434 dprintk("lockd_down: service destroyed\n");
401 nlmsvc_task = NULL; 435 nlmsvc_task = NULL;
402 nlmsvc_rqst = NULL; 436 nlmsvc_rqst = NULL;
403out: 437out:
diff --git a/fs/locks.c b/fs/locks.c
index 4f441e46cef4..814c51d0de47 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1636,12 +1636,13 @@ EXPORT_SYMBOL(flock_lock_file_wait);
1636SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd) 1636SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
1637{ 1637{
1638 struct file *filp; 1638 struct file *filp;
1639 int fput_needed;
1639 struct file_lock *lock; 1640 struct file_lock *lock;
1640 int can_sleep, unlock; 1641 int can_sleep, unlock;
1641 int error; 1642 int error;
1642 1643
1643 error = -EBADF; 1644 error = -EBADF;
1644 filp = fget(fd); 1645 filp = fget_light(fd, &fput_needed);
1645 if (!filp) 1646 if (!filp)
1646 goto out; 1647 goto out;
1647 1648
@@ -1674,7 +1675,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
1674 locks_free_lock(lock); 1675 locks_free_lock(lock);
1675 1676
1676 out_putf: 1677 out_putf:
1677 fput(filp); 1678 fput_light(filp, fput_needed);
1678 out: 1679 out:
1679 return error; 1680 return error;
1680} 1681}
diff --git a/fs/namei.c b/fs/namei.c
index c651f02c9fec..7d694194024a 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -449,7 +449,7 @@ static int unlazy_walk(struct nameidata *nd, struct dentry *dentry)
449 mntget(nd->path.mnt); 449 mntget(nd->path.mnt);
450 450
451 rcu_read_unlock(); 451 rcu_read_unlock();
452 br_read_unlock(vfsmount_lock); 452 br_read_unlock(&vfsmount_lock);
453 nd->flags &= ~LOOKUP_RCU; 453 nd->flags &= ~LOOKUP_RCU;
454 return 0; 454 return 0;
455 455
@@ -507,14 +507,14 @@ static int complete_walk(struct nameidata *nd)
507 if (unlikely(!__d_rcu_to_refcount(dentry, nd->seq))) { 507 if (unlikely(!__d_rcu_to_refcount(dentry, nd->seq))) {
508 spin_unlock(&dentry->d_lock); 508 spin_unlock(&dentry->d_lock);
509 rcu_read_unlock(); 509 rcu_read_unlock();
510 br_read_unlock(vfsmount_lock); 510 br_read_unlock(&vfsmount_lock);
511 return -ECHILD; 511 return -ECHILD;
512 } 512 }
513 BUG_ON(nd->inode != dentry->d_inode); 513 BUG_ON(nd->inode != dentry->d_inode);
514 spin_unlock(&dentry->d_lock); 514 spin_unlock(&dentry->d_lock);
515 mntget(nd->path.mnt); 515 mntget(nd->path.mnt);
516 rcu_read_unlock(); 516 rcu_read_unlock();
517 br_read_unlock(vfsmount_lock); 517 br_read_unlock(&vfsmount_lock);
518 } 518 }
519 519
520 if (likely(!(nd->flags & LOOKUP_JUMPED))) 520 if (likely(!(nd->flags & LOOKUP_JUMPED)))
@@ -681,15 +681,15 @@ int follow_up(struct path *path)
681 struct mount *parent; 681 struct mount *parent;
682 struct dentry *mountpoint; 682 struct dentry *mountpoint;
683 683
684 br_read_lock(vfsmount_lock); 684 br_read_lock(&vfsmount_lock);
685 parent = mnt->mnt_parent; 685 parent = mnt->mnt_parent;
686 if (&parent->mnt == path->mnt) { 686 if (&parent->mnt == path->mnt) {
687 br_read_unlock(vfsmount_lock); 687 br_read_unlock(&vfsmount_lock);
688 return 0; 688 return 0;
689 } 689 }
690 mntget(&parent->mnt); 690 mntget(&parent->mnt);
691 mountpoint = dget(mnt->mnt_mountpoint); 691 mountpoint = dget(mnt->mnt_mountpoint);
692 br_read_unlock(vfsmount_lock); 692 br_read_unlock(&vfsmount_lock);
693 dput(path->dentry); 693 dput(path->dentry);
694 path->dentry = mountpoint; 694 path->dentry = mountpoint;
695 mntput(path->mnt); 695 mntput(path->mnt);
@@ -947,7 +947,7 @@ failed:
947 if (!(nd->flags & LOOKUP_ROOT)) 947 if (!(nd->flags & LOOKUP_ROOT))
948 nd->root.mnt = NULL; 948 nd->root.mnt = NULL;
949 rcu_read_unlock(); 949 rcu_read_unlock();
950 br_read_unlock(vfsmount_lock); 950 br_read_unlock(&vfsmount_lock);
951 return -ECHILD; 951 return -ECHILD;
952} 952}
953 953
@@ -1125,8 +1125,8 @@ static struct dentry *__lookup_hash(struct qstr *name,
1125 * small and for now I'd prefer to have fast path as straight as possible. 1125 * small and for now I'd prefer to have fast path as straight as possible.
1126 * It _is_ time-critical. 1126 * It _is_ time-critical.
1127 */ 1127 */
1128static int do_lookup(struct nameidata *nd, struct qstr *name, 1128static int lookup_fast(struct nameidata *nd, struct qstr *name,
1129 struct path *path, struct inode **inode) 1129 struct path *path, struct inode **inode)
1130{ 1130{
1131 struct vfsmount *mnt = nd->path.mnt; 1131 struct vfsmount *mnt = nd->path.mnt;
1132 struct dentry *dentry, *parent = nd->path.dentry; 1132 struct dentry *dentry, *parent = nd->path.dentry;
@@ -1208,7 +1208,7 @@ unlazy:
1208 goto need_lookup; 1208 goto need_lookup;
1209 } 1209 }
1210 } 1210 }
1211done: 1211
1212 path->mnt = mnt; 1212 path->mnt = mnt;
1213 path->dentry = dentry; 1213 path->dentry = dentry;
1214 err = follow_managed(path, nd->flags); 1214 err = follow_managed(path, nd->flags);
@@ -1222,6 +1222,17 @@ done:
1222 return 0; 1222 return 0;
1223 1223
1224need_lookup: 1224need_lookup:
1225 return 1;
1226}
1227
1228/* Fast lookup failed, do it the slow way */
1229static int lookup_slow(struct nameidata *nd, struct qstr *name,
1230 struct path *path)
1231{
1232 struct dentry *dentry, *parent;
1233 int err;
1234
1235 parent = nd->path.dentry;
1225 BUG_ON(nd->inode != parent->d_inode); 1236 BUG_ON(nd->inode != parent->d_inode);
1226 1237
1227 mutex_lock(&parent->d_inode->i_mutex); 1238 mutex_lock(&parent->d_inode->i_mutex);
@@ -1229,7 +1240,16 @@ need_lookup:
1229 mutex_unlock(&parent->d_inode->i_mutex); 1240 mutex_unlock(&parent->d_inode->i_mutex);
1230 if (IS_ERR(dentry)) 1241 if (IS_ERR(dentry))
1231 return PTR_ERR(dentry); 1242 return PTR_ERR(dentry);
1232 goto done; 1243 path->mnt = nd->path.mnt;
1244 path->dentry = dentry;
1245 err = follow_managed(path, nd->flags);
1246 if (unlikely(err < 0)) {
1247 path_put_conditional(path, nd);
1248 return err;
1249 }
1250 if (err)
1251 nd->flags |= LOOKUP_JUMPED;
1252 return 0;
1233} 1253}
1234 1254
1235static inline int may_lookup(struct nameidata *nd) 1255static inline int may_lookup(struct nameidata *nd)
@@ -1265,7 +1285,7 @@ static void terminate_walk(struct nameidata *nd)
1265 if (!(nd->flags & LOOKUP_ROOT)) 1285 if (!(nd->flags & LOOKUP_ROOT))
1266 nd->root.mnt = NULL; 1286 nd->root.mnt = NULL;
1267 rcu_read_unlock(); 1287 rcu_read_unlock();
1268 br_read_unlock(vfsmount_lock); 1288 br_read_unlock(&vfsmount_lock);
1269 } 1289 }
1270} 1290}
1271 1291
@@ -1301,21 +1321,26 @@ static inline int walk_component(struct nameidata *nd, struct path *path,
1301 */ 1321 */
1302 if (unlikely(type != LAST_NORM)) 1322 if (unlikely(type != LAST_NORM))
1303 return handle_dots(nd, type); 1323 return handle_dots(nd, type);
1304 err = do_lookup(nd, name, path, &inode); 1324 err = lookup_fast(nd, name, path, &inode);
1305 if (unlikely(err)) { 1325 if (unlikely(err)) {
1306 terminate_walk(nd); 1326 if (err < 0)
1307 return err; 1327 goto out_err;
1308 } 1328
1309 if (!inode) { 1329 err = lookup_slow(nd, name, path);
1310 path_to_nameidata(path, nd); 1330 if (err < 0)
1311 terminate_walk(nd); 1331 goto out_err;
1312 return -ENOENT; 1332
1333 inode = path->dentry->d_inode;
1313 } 1334 }
1335 err = -ENOENT;
1336 if (!inode)
1337 goto out_path_put;
1338
1314 if (should_follow_link(inode, follow)) { 1339 if (should_follow_link(inode, follow)) {
1315 if (nd->flags & LOOKUP_RCU) { 1340 if (nd->flags & LOOKUP_RCU) {
1316 if (unlikely(unlazy_walk(nd, path->dentry))) { 1341 if (unlikely(unlazy_walk(nd, path->dentry))) {
1317 terminate_walk(nd); 1342 err = -ECHILD;
1318 return -ECHILD; 1343 goto out_err;
1319 } 1344 }
1320 } 1345 }
1321 BUG_ON(inode != path->dentry->d_inode); 1346 BUG_ON(inode != path->dentry->d_inode);
@@ -1324,6 +1349,12 @@ static inline int walk_component(struct nameidata *nd, struct path *path,
1324 path_to_nameidata(path, nd); 1349 path_to_nameidata(path, nd);
1325 nd->inode = inode; 1350 nd->inode = inode;
1326 return 0; 1351 return 0;
1352
1353out_path_put:
1354 path_to_nameidata(path, nd);
1355out_err:
1356 terminate_walk(nd);
1357 return err;
1327} 1358}
1328 1359
1329/* 1360/*
@@ -1620,7 +1651,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
1620 nd->path = nd->root; 1651 nd->path = nd->root;
1621 nd->inode = inode; 1652 nd->inode = inode;
1622 if (flags & LOOKUP_RCU) { 1653 if (flags & LOOKUP_RCU) {
1623 br_read_lock(vfsmount_lock); 1654 br_read_lock(&vfsmount_lock);
1624 rcu_read_lock(); 1655 rcu_read_lock();
1625 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); 1656 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq);
1626 } else { 1657 } else {
@@ -1633,7 +1664,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
1633 1664
1634 if (*name=='/') { 1665 if (*name=='/') {
1635 if (flags & LOOKUP_RCU) { 1666 if (flags & LOOKUP_RCU) {
1636 br_read_lock(vfsmount_lock); 1667 br_read_lock(&vfsmount_lock);
1637 rcu_read_lock(); 1668 rcu_read_lock();
1638 set_root_rcu(nd); 1669 set_root_rcu(nd);
1639 } else { 1670 } else {
@@ -1646,7 +1677,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
1646 struct fs_struct *fs = current->fs; 1677 struct fs_struct *fs = current->fs;
1647 unsigned seq; 1678 unsigned seq;
1648 1679
1649 br_read_lock(vfsmount_lock); 1680 br_read_lock(&vfsmount_lock);
1650 rcu_read_lock(); 1681 rcu_read_lock();
1651 1682
1652 do { 1683 do {
@@ -1682,7 +1713,7 @@ static int path_init(int dfd, const char *name, unsigned int flags,
1682 if (fput_needed) 1713 if (fput_needed)
1683 *fp = file; 1714 *fp = file;
1684 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq); 1715 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq);
1685 br_read_lock(vfsmount_lock); 1716 br_read_lock(&vfsmount_lock);
1686 rcu_read_lock(); 1717 rcu_read_lock();
1687 } else { 1718 } else {
1688 path_get(&file->f_path); 1719 path_get(&file->f_path);
@@ -2169,6 +2200,10 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
2169 int want_write = 0; 2200 int want_write = 0;
2170 int acc_mode = op->acc_mode; 2201 int acc_mode = op->acc_mode;
2171 struct file *filp; 2202 struct file *filp;
2203 struct inode *inode;
2204 int symlink_ok = 0;
2205 struct path save_parent = { .dentry = NULL, .mnt = NULL };
2206 bool retried = false;
2172 int error; 2207 int error;
2173 2208
2174 nd->flags &= ~LOOKUP_PARENT; 2209 nd->flags &= ~LOOKUP_PARENT;
@@ -2200,30 +2235,23 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
2200 } 2235 }
2201 2236
2202 if (!(open_flag & O_CREAT)) { 2237 if (!(open_flag & O_CREAT)) {
2203 int symlink_ok = 0;
2204 if (nd->last.name[nd->last.len]) 2238 if (nd->last.name[nd->last.len])
2205 nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY; 2239 nd->flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
2206 if (open_flag & O_PATH && !(nd->flags & LOOKUP_FOLLOW)) 2240 if (open_flag & O_PATH && !(nd->flags & LOOKUP_FOLLOW))
2207 symlink_ok = 1; 2241 symlink_ok = 1;
2208 /* we _can_ be in RCU mode here */ 2242 /* we _can_ be in RCU mode here */
2209 error = walk_component(nd, path, &nd->last, LAST_NORM, 2243 error = lookup_fast(nd, &nd->last, path, &inode);
2210 !symlink_ok); 2244 if (unlikely(error)) {
2211 if (error < 0) 2245 if (error < 0)
2212 return ERR_PTR(error); 2246 goto exit;
2213 if (error) /* symlink */
2214 return NULL;
2215 /* sayonara */
2216 error = complete_walk(nd);
2217 if (error)
2218 return ERR_PTR(error);
2219 2247
2220 error = -ENOTDIR; 2248 error = lookup_slow(nd, &nd->last, path);
2221 if (nd->flags & LOOKUP_DIRECTORY) { 2249 if (error < 0)
2222 if (!nd->inode->i_op->lookup)
2223 goto exit; 2250 goto exit;
2251
2252 inode = path->dentry->d_inode;
2224 } 2253 }
2225 audit_inode(pathname, nd->path.dentry); 2254 goto finish_lookup;
2226 goto ok;
2227 } 2255 }
2228 2256
2229 /* create side of things */ 2257 /* create side of things */
@@ -2241,6 +2269,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
2241 if (nd->last.name[nd->last.len]) 2269 if (nd->last.name[nd->last.len])
2242 goto exit; 2270 goto exit;
2243 2271
2272retry_lookup:
2244 mutex_lock(&dir->d_inode->i_mutex); 2273 mutex_lock(&dir->d_inode->i_mutex);
2245 2274
2246 dentry = lookup_hash(nd); 2275 dentry = lookup_hash(nd);
@@ -2302,22 +2331,49 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
2302 if (error) 2331 if (error)
2303 nd->flags |= LOOKUP_JUMPED; 2332 nd->flags |= LOOKUP_JUMPED;
2304 2333
2334 BUG_ON(nd->flags & LOOKUP_RCU);
2335 inode = path->dentry->d_inode;
2336finish_lookup:
2337 /* we _can_ be in RCU mode here */
2305 error = -ENOENT; 2338 error = -ENOENT;
2306 if (!path->dentry->d_inode) 2339 if (!inode) {
2307 goto exit_dput; 2340 path_to_nameidata(path, nd);
2341 goto exit;
2342 }
2308 2343
2309 if (path->dentry->d_inode->i_op->follow_link) 2344 if (should_follow_link(inode, !symlink_ok)) {
2345 if (nd->flags & LOOKUP_RCU) {
2346 if (unlikely(unlazy_walk(nd, path->dentry))) {
2347 error = -ECHILD;
2348 goto exit;
2349 }
2350 }
2351 BUG_ON(inode != path->dentry->d_inode);
2310 return NULL; 2352 return NULL;
2353 }
2311 2354
2312 path_to_nameidata(path, nd); 2355 if ((nd->flags & LOOKUP_RCU) || nd->path.mnt != path->mnt) {
2313 nd->inode = path->dentry->d_inode; 2356 path_to_nameidata(path, nd);
2357 } else {
2358 save_parent.dentry = nd->path.dentry;
2359 save_parent.mnt = mntget(path->mnt);
2360 nd->path.dentry = path->dentry;
2361
2362 }
2363 nd->inode = inode;
2314 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */ 2364 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
2315 error = complete_walk(nd); 2365 error = complete_walk(nd);
2316 if (error) 2366 if (error) {
2367 path_put(&save_parent);
2317 return ERR_PTR(error); 2368 return ERR_PTR(error);
2369 }
2318 error = -EISDIR; 2370 error = -EISDIR;
2319 if (S_ISDIR(nd->inode->i_mode)) 2371 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
2372 goto exit;
2373 error = -ENOTDIR;
2374 if ((nd->flags & LOOKUP_DIRECTORY) && !nd->inode->i_op->lookup)
2320 goto exit; 2375 goto exit;
2376 audit_inode(pathname, nd->path.dentry);
2321ok: 2377ok:
2322 if (!S_ISREG(nd->inode->i_mode)) 2378 if (!S_ISREG(nd->inode->i_mode))
2323 will_truncate = 0; 2379 will_truncate = 0;
@@ -2333,6 +2389,20 @@ common:
2333 if (error) 2389 if (error)
2334 goto exit; 2390 goto exit;
2335 filp = nameidata_to_filp(nd); 2391 filp = nameidata_to_filp(nd);
2392 if (filp == ERR_PTR(-EOPENSTALE) && save_parent.dentry && !retried) {
2393 BUG_ON(save_parent.dentry != dir);
2394 path_put(&nd->path);
2395 nd->path = save_parent;
2396 nd->inode = dir->d_inode;
2397 save_parent.mnt = NULL;
2398 save_parent.dentry = NULL;
2399 if (want_write) {
2400 mnt_drop_write(nd->path.mnt);
2401 want_write = 0;
2402 }
2403 retried = true;
2404 goto retry_lookup;
2405 }
2336 if (!IS_ERR(filp)) { 2406 if (!IS_ERR(filp)) {
2337 error = ima_file_check(filp, op->acc_mode); 2407 error = ima_file_check(filp, op->acc_mode);
2338 if (error) { 2408 if (error) {
@@ -2352,7 +2422,8 @@ common:
2352out: 2422out:
2353 if (want_write) 2423 if (want_write)
2354 mnt_drop_write(nd->path.mnt); 2424 mnt_drop_write(nd->path.mnt);
2355 path_put(&nd->path); 2425 path_put(&save_parent);
2426 terminate_walk(nd);
2356 return filp; 2427 return filp;
2357 2428
2358exit_mutex_unlock: 2429exit_mutex_unlock:
@@ -2415,6 +2486,12 @@ out:
2415 if (base) 2486 if (base)
2416 fput(base); 2487 fput(base);
2417 release_open_intent(nd); 2488 release_open_intent(nd);
2489 if (filp == ERR_PTR(-EOPENSTALE)) {
2490 if (flags & LOOKUP_RCU)
2491 filp = ERR_PTR(-ECHILD);
2492 else
2493 filp = ERR_PTR(-ESTALE);
2494 }
2418 return filp; 2495 return filp;
2419 2496
2420out_filp: 2497out_filp:
diff --git a/fs/namespace.c b/fs/namespace.c
index e6081996c9a2..1e4a5fe3d7b7 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -397,7 +397,7 @@ static int mnt_make_readonly(struct mount *mnt)
397{ 397{
398 int ret = 0; 398 int ret = 0;
399 399
400 br_write_lock(vfsmount_lock); 400 br_write_lock(&vfsmount_lock);
401 mnt->mnt.mnt_flags |= MNT_WRITE_HOLD; 401 mnt->mnt.mnt_flags |= MNT_WRITE_HOLD;
402 /* 402 /*
403 * After storing MNT_WRITE_HOLD, we'll read the counters. This store 403 * After storing MNT_WRITE_HOLD, we'll read the counters. This store
@@ -431,15 +431,15 @@ static int mnt_make_readonly(struct mount *mnt)
431 */ 431 */
432 smp_wmb(); 432 smp_wmb();
433 mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD; 433 mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD;
434 br_write_unlock(vfsmount_lock); 434 br_write_unlock(&vfsmount_lock);
435 return ret; 435 return ret;
436} 436}
437 437
438static void __mnt_unmake_readonly(struct mount *mnt) 438static void __mnt_unmake_readonly(struct mount *mnt)
439{ 439{
440 br_write_lock(vfsmount_lock); 440 br_write_lock(&vfsmount_lock);
441 mnt->mnt.mnt_flags &= ~MNT_READONLY; 441 mnt->mnt.mnt_flags &= ~MNT_READONLY;
442 br_write_unlock(vfsmount_lock); 442 br_write_unlock(&vfsmount_lock);
443} 443}
444 444
445int sb_prepare_remount_readonly(struct super_block *sb) 445int sb_prepare_remount_readonly(struct super_block *sb)
@@ -451,7 +451,7 @@ int sb_prepare_remount_readonly(struct super_block *sb)
451 if (atomic_long_read(&sb->s_remove_count)) 451 if (atomic_long_read(&sb->s_remove_count))
452 return -EBUSY; 452 return -EBUSY;
453 453
454 br_write_lock(vfsmount_lock); 454 br_write_lock(&vfsmount_lock);
455 list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) { 455 list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) {
456 if (!(mnt->mnt.mnt_flags & MNT_READONLY)) { 456 if (!(mnt->mnt.mnt_flags & MNT_READONLY)) {
457 mnt->mnt.mnt_flags |= MNT_WRITE_HOLD; 457 mnt->mnt.mnt_flags |= MNT_WRITE_HOLD;
@@ -473,7 +473,7 @@ int sb_prepare_remount_readonly(struct super_block *sb)
473 if (mnt->mnt.mnt_flags & MNT_WRITE_HOLD) 473 if (mnt->mnt.mnt_flags & MNT_WRITE_HOLD)
474 mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD; 474 mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD;
475 } 475 }
476 br_write_unlock(vfsmount_lock); 476 br_write_unlock(&vfsmount_lock);
477 477
478 return err; 478 return err;
479} 479}
@@ -522,14 +522,14 @@ struct vfsmount *lookup_mnt(struct path *path)
522{ 522{
523 struct mount *child_mnt; 523 struct mount *child_mnt;
524 524
525 br_read_lock(vfsmount_lock); 525 br_read_lock(&vfsmount_lock);
526 child_mnt = __lookup_mnt(path->mnt, path->dentry, 1); 526 child_mnt = __lookup_mnt(path->mnt, path->dentry, 1);
527 if (child_mnt) { 527 if (child_mnt) {
528 mnt_add_count(child_mnt, 1); 528 mnt_add_count(child_mnt, 1);
529 br_read_unlock(vfsmount_lock); 529 br_read_unlock(&vfsmount_lock);
530 return &child_mnt->mnt; 530 return &child_mnt->mnt;
531 } else { 531 } else {
532 br_read_unlock(vfsmount_lock); 532 br_read_unlock(&vfsmount_lock);
533 return NULL; 533 return NULL;
534 } 534 }
535} 535}
@@ -714,9 +714,9 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void
714 mnt->mnt.mnt_sb = root->d_sb; 714 mnt->mnt.mnt_sb = root->d_sb;
715 mnt->mnt_mountpoint = mnt->mnt.mnt_root; 715 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
716 mnt->mnt_parent = mnt; 716 mnt->mnt_parent = mnt;
717 br_write_lock(vfsmount_lock); 717 br_write_lock(&vfsmount_lock);
718 list_add_tail(&mnt->mnt_instance, &root->d_sb->s_mounts); 718 list_add_tail(&mnt->mnt_instance, &root->d_sb->s_mounts);
719 br_write_unlock(vfsmount_lock); 719 br_write_unlock(&vfsmount_lock);
720 return &mnt->mnt; 720 return &mnt->mnt;
721} 721}
722EXPORT_SYMBOL_GPL(vfs_kern_mount); 722EXPORT_SYMBOL_GPL(vfs_kern_mount);
@@ -745,9 +745,9 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,
745 mnt->mnt.mnt_root = dget(root); 745 mnt->mnt.mnt_root = dget(root);
746 mnt->mnt_mountpoint = mnt->mnt.mnt_root; 746 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
747 mnt->mnt_parent = mnt; 747 mnt->mnt_parent = mnt;
748 br_write_lock(vfsmount_lock); 748 br_write_lock(&vfsmount_lock);
749 list_add_tail(&mnt->mnt_instance, &sb->s_mounts); 749 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
750 br_write_unlock(vfsmount_lock); 750 br_write_unlock(&vfsmount_lock);
751 751
752 if (flag & CL_SLAVE) { 752 if (flag & CL_SLAVE) {
753 list_add(&mnt->mnt_slave, &old->mnt_slave_list); 753 list_add(&mnt->mnt_slave, &old->mnt_slave_list);
@@ -803,35 +803,36 @@ static void mntput_no_expire(struct mount *mnt)
803{ 803{
804put_again: 804put_again:
805#ifdef CONFIG_SMP 805#ifdef CONFIG_SMP
806 br_read_lock(vfsmount_lock); 806 br_read_lock(&vfsmount_lock);
807 if (likely(atomic_read(&mnt->mnt_longterm))) { 807 if (likely(atomic_read(&mnt->mnt_longterm))) {
808 mnt_add_count(mnt, -1); 808 mnt_add_count(mnt, -1);
809 br_read_unlock(vfsmount_lock); 809 br_read_unlock(&vfsmount_lock);
810 return; 810 return;
811 } 811 }
812 br_read_unlock(vfsmount_lock); 812 br_read_unlock(&vfsmount_lock);
813 813
814 br_write_lock(vfsmount_lock); 814 br_write_lock(&vfsmount_lock);
815 mnt_add_count(mnt, -1); 815 mnt_add_count(mnt, -1);
816 if (mnt_get_count(mnt)) { 816 if (mnt_get_count(mnt)) {
817 br_write_unlock(vfsmount_lock); 817 br_write_unlock(&vfsmount_lock);
818 return; 818 return;
819 } 819 }
820#else 820#else
821 mnt_add_count(mnt, -1); 821 mnt_add_count(mnt, -1);
822 if (likely(mnt_get_count(mnt))) 822 if (likely(mnt_get_count(mnt)))
823 return; 823 return;
824 br_write_lock(vfsmount_lock); 824 br_write_lock(&vfsmount_lock);
825#endif 825#endif
826 if (unlikely(mnt->mnt_pinned)) { 826 if (unlikely(mnt->mnt_pinned)) {
827 mnt_add_count(mnt, mnt->mnt_pinned + 1); 827 mnt_add_count(mnt, mnt->mnt_pinned + 1);
828 mnt->mnt_pinned = 0; 828 mnt->mnt_pinned = 0;
829 br_write_unlock(vfsmount_lock); 829 br_write_unlock(&vfsmount_lock);
830 acct_auto_close_mnt(&mnt->mnt); 830 acct_auto_close_mnt(&mnt->mnt);
831 goto put_again; 831 goto put_again;
832 } 832 }
833
833 list_del(&mnt->mnt_instance); 834 list_del(&mnt->mnt_instance);
834 br_write_unlock(vfsmount_lock); 835 br_write_unlock(&vfsmount_lock);
835 mntfree(mnt); 836 mntfree(mnt);
836} 837}
837 838
@@ -857,21 +858,21 @@ EXPORT_SYMBOL(mntget);
857 858
858void mnt_pin(struct vfsmount *mnt) 859void mnt_pin(struct vfsmount *mnt)
859{ 860{
860 br_write_lock(vfsmount_lock); 861 br_write_lock(&vfsmount_lock);
861 real_mount(mnt)->mnt_pinned++; 862 real_mount(mnt)->mnt_pinned++;
862 br_write_unlock(vfsmount_lock); 863 br_write_unlock(&vfsmount_lock);
863} 864}
864EXPORT_SYMBOL(mnt_pin); 865EXPORT_SYMBOL(mnt_pin);
865 866
866void mnt_unpin(struct vfsmount *m) 867void mnt_unpin(struct vfsmount *m)
867{ 868{
868 struct mount *mnt = real_mount(m); 869 struct mount *mnt = real_mount(m);
869 br_write_lock(vfsmount_lock); 870 br_write_lock(&vfsmount_lock);
870 if (mnt->mnt_pinned) { 871 if (mnt->mnt_pinned) {
871 mnt_add_count(mnt, 1); 872 mnt_add_count(mnt, 1);
872 mnt->mnt_pinned--; 873 mnt->mnt_pinned--;
873 } 874 }
874 br_write_unlock(vfsmount_lock); 875 br_write_unlock(&vfsmount_lock);
875} 876}
876EXPORT_SYMBOL(mnt_unpin); 877EXPORT_SYMBOL(mnt_unpin);
877 878
@@ -988,12 +989,12 @@ int may_umount_tree(struct vfsmount *m)
988 BUG_ON(!m); 989 BUG_ON(!m);
989 990
990 /* write lock needed for mnt_get_count */ 991 /* write lock needed for mnt_get_count */
991 br_write_lock(vfsmount_lock); 992 br_write_lock(&vfsmount_lock);
992 for (p = mnt; p; p = next_mnt(p, mnt)) { 993 for (p = mnt; p; p = next_mnt(p, mnt)) {
993 actual_refs += mnt_get_count(p); 994 actual_refs += mnt_get_count(p);
994 minimum_refs += 2; 995 minimum_refs += 2;
995 } 996 }
996 br_write_unlock(vfsmount_lock); 997 br_write_unlock(&vfsmount_lock);
997 998
998 if (actual_refs > minimum_refs) 999 if (actual_refs > minimum_refs)
999 return 0; 1000 return 0;
@@ -1020,10 +1021,10 @@ int may_umount(struct vfsmount *mnt)
1020{ 1021{
1021 int ret = 1; 1022 int ret = 1;
1022 down_read(&namespace_sem); 1023 down_read(&namespace_sem);
1023 br_write_lock(vfsmount_lock); 1024 br_write_lock(&vfsmount_lock);
1024 if (propagate_mount_busy(real_mount(mnt), 2)) 1025 if (propagate_mount_busy(real_mount(mnt), 2))
1025 ret = 0; 1026 ret = 0;
1026 br_write_unlock(vfsmount_lock); 1027 br_write_unlock(&vfsmount_lock);
1027 up_read(&namespace_sem); 1028 up_read(&namespace_sem);
1028 return ret; 1029 return ret;
1029} 1030}
@@ -1040,13 +1041,13 @@ void release_mounts(struct list_head *head)
1040 struct dentry *dentry; 1041 struct dentry *dentry;
1041 struct mount *m; 1042 struct mount *m;
1042 1043
1043 br_write_lock(vfsmount_lock); 1044 br_write_lock(&vfsmount_lock);
1044 dentry = mnt->mnt_mountpoint; 1045 dentry = mnt->mnt_mountpoint;
1045 m = mnt->mnt_parent; 1046 m = mnt->mnt_parent;
1046 mnt->mnt_mountpoint = mnt->mnt.mnt_root; 1047 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
1047 mnt->mnt_parent = mnt; 1048 mnt->mnt_parent = mnt;
1048 m->mnt_ghosts--; 1049 m->mnt_ghosts--;
1049 br_write_unlock(vfsmount_lock); 1050 br_write_unlock(&vfsmount_lock);
1050 dput(dentry); 1051 dput(dentry);
1051 mntput(&m->mnt); 1052 mntput(&m->mnt);
1052 } 1053 }
@@ -1073,8 +1074,9 @@ void umount_tree(struct mount *mnt, int propagate, struct list_head *kill)
1073 list_del_init(&p->mnt_expire); 1074 list_del_init(&p->mnt_expire);
1074 list_del_init(&p->mnt_list); 1075 list_del_init(&p->mnt_list);
1075 __touch_mnt_namespace(p->mnt_ns); 1076 __touch_mnt_namespace(p->mnt_ns);
1077 if (p->mnt_ns)
1078 __mnt_make_shortterm(p);
1076 p->mnt_ns = NULL; 1079 p->mnt_ns = NULL;
1077 __mnt_make_shortterm(p);
1078 list_del_init(&p->mnt_child); 1080 list_del_init(&p->mnt_child);
1079 if (mnt_has_parent(p)) { 1081 if (mnt_has_parent(p)) {
1080 p->mnt_parent->mnt_ghosts++; 1082 p->mnt_parent->mnt_ghosts++;
@@ -1112,12 +1114,12 @@ static int do_umount(struct mount *mnt, int flags)
1112 * probably don't strictly need the lock here if we examined 1114 * probably don't strictly need the lock here if we examined
1113 * all race cases, but it's a slowpath. 1115 * all race cases, but it's a slowpath.
1114 */ 1116 */
1115 br_write_lock(vfsmount_lock); 1117 br_write_lock(&vfsmount_lock);
1116 if (mnt_get_count(mnt) != 2) { 1118 if (mnt_get_count(mnt) != 2) {
1117 br_write_unlock(vfsmount_lock); 1119 br_write_unlock(&vfsmount_lock);
1118 return -EBUSY; 1120 return -EBUSY;
1119 } 1121 }
1120 br_write_unlock(vfsmount_lock); 1122 br_write_unlock(&vfsmount_lock);
1121 1123
1122 if (!xchg(&mnt->mnt_expiry_mark, 1)) 1124 if (!xchg(&mnt->mnt_expiry_mark, 1))
1123 return -EAGAIN; 1125 return -EAGAIN;
@@ -1159,7 +1161,7 @@ static int do_umount(struct mount *mnt, int flags)
1159 } 1161 }
1160 1162
1161 down_write(&namespace_sem); 1163 down_write(&namespace_sem);
1162 br_write_lock(vfsmount_lock); 1164 br_write_lock(&vfsmount_lock);
1163 event++; 1165 event++;
1164 1166
1165 if (!(flags & MNT_DETACH)) 1167 if (!(flags & MNT_DETACH))
@@ -1171,7 +1173,7 @@ static int do_umount(struct mount *mnt, int flags)
1171 umount_tree(mnt, 1, &umount_list); 1173 umount_tree(mnt, 1, &umount_list);
1172 retval = 0; 1174 retval = 0;
1173 } 1175 }
1174 br_write_unlock(vfsmount_lock); 1176 br_write_unlock(&vfsmount_lock);
1175 up_write(&namespace_sem); 1177 up_write(&namespace_sem);
1176 release_mounts(&umount_list); 1178 release_mounts(&umount_list);
1177 return retval; 1179 return retval;
@@ -1286,19 +1288,19 @@ struct mount *copy_tree(struct mount *mnt, struct dentry *dentry,
1286 q = clone_mnt(p, p->mnt.mnt_root, flag); 1288 q = clone_mnt(p, p->mnt.mnt_root, flag);
1287 if (!q) 1289 if (!q)
1288 goto Enomem; 1290 goto Enomem;
1289 br_write_lock(vfsmount_lock); 1291 br_write_lock(&vfsmount_lock);
1290 list_add_tail(&q->mnt_list, &res->mnt_list); 1292 list_add_tail(&q->mnt_list, &res->mnt_list);
1291 attach_mnt(q, &path); 1293 attach_mnt(q, &path);
1292 br_write_unlock(vfsmount_lock); 1294 br_write_unlock(&vfsmount_lock);
1293 } 1295 }
1294 } 1296 }
1295 return res; 1297 return res;
1296Enomem: 1298Enomem:
1297 if (res) { 1299 if (res) {
1298 LIST_HEAD(umount_list); 1300 LIST_HEAD(umount_list);
1299 br_write_lock(vfsmount_lock); 1301 br_write_lock(&vfsmount_lock);
1300 umount_tree(res, 0, &umount_list); 1302 umount_tree(res, 0, &umount_list);
1301 br_write_unlock(vfsmount_lock); 1303 br_write_unlock(&vfsmount_lock);
1302 release_mounts(&umount_list); 1304 release_mounts(&umount_list);
1303 } 1305 }
1304 return NULL; 1306 return NULL;
@@ -1318,9 +1320,9 @@ void drop_collected_mounts(struct vfsmount *mnt)
1318{ 1320{
1319 LIST_HEAD(umount_list); 1321 LIST_HEAD(umount_list);
1320 down_write(&namespace_sem); 1322 down_write(&namespace_sem);
1321 br_write_lock(vfsmount_lock); 1323 br_write_lock(&vfsmount_lock);
1322 umount_tree(real_mount(mnt), 0, &umount_list); 1324 umount_tree(real_mount(mnt), 0, &umount_list);
1323 br_write_unlock(vfsmount_lock); 1325 br_write_unlock(&vfsmount_lock);
1324 up_write(&namespace_sem); 1326 up_write(&namespace_sem);
1325 release_mounts(&umount_list); 1327 release_mounts(&umount_list);
1326} 1328}
@@ -1448,7 +1450,7 @@ static int attach_recursive_mnt(struct mount *source_mnt,
1448 if (err) 1450 if (err)
1449 goto out_cleanup_ids; 1451 goto out_cleanup_ids;
1450 1452
1451 br_write_lock(vfsmount_lock); 1453 br_write_lock(&vfsmount_lock);
1452 1454
1453 if (IS_MNT_SHARED(dest_mnt)) { 1455 if (IS_MNT_SHARED(dest_mnt)) {
1454 for (p = source_mnt; p; p = next_mnt(p, source_mnt)) 1456 for (p = source_mnt; p; p = next_mnt(p, source_mnt))
@@ -1467,7 +1469,7 @@ static int attach_recursive_mnt(struct mount *source_mnt,
1467 list_del_init(&child->mnt_hash); 1469 list_del_init(&child->mnt_hash);
1468 commit_tree(child); 1470 commit_tree(child);
1469 } 1471 }
1470 br_write_unlock(vfsmount_lock); 1472 br_write_unlock(&vfsmount_lock);
1471 1473
1472 return 0; 1474 return 0;
1473 1475
@@ -1565,10 +1567,10 @@ static int do_change_type(struct path *path, int flag)
1565 goto out_unlock; 1567 goto out_unlock;
1566 } 1568 }
1567 1569
1568 br_write_lock(vfsmount_lock); 1570 br_write_lock(&vfsmount_lock);
1569 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL)) 1571 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
1570 change_mnt_propagation(m, type); 1572 change_mnt_propagation(m, type);
1571 br_write_unlock(vfsmount_lock); 1573 br_write_unlock(&vfsmount_lock);
1572 1574
1573 out_unlock: 1575 out_unlock:
1574 up_write(&namespace_sem); 1576 up_write(&namespace_sem);
@@ -1617,9 +1619,9 @@ static int do_loopback(struct path *path, char *old_name,
1617 1619
1618 err = graft_tree(mnt, path); 1620 err = graft_tree(mnt, path);
1619 if (err) { 1621 if (err) {
1620 br_write_lock(vfsmount_lock); 1622 br_write_lock(&vfsmount_lock);
1621 umount_tree(mnt, 0, &umount_list); 1623 umount_tree(mnt, 0, &umount_list);
1622 br_write_unlock(vfsmount_lock); 1624 br_write_unlock(&vfsmount_lock);
1623 } 1625 }
1624out2: 1626out2:
1625 unlock_mount(path); 1627 unlock_mount(path);
@@ -1677,16 +1679,16 @@ static int do_remount(struct path *path, int flags, int mnt_flags,
1677 else 1679 else
1678 err = do_remount_sb(sb, flags, data, 0); 1680 err = do_remount_sb(sb, flags, data, 0);
1679 if (!err) { 1681 if (!err) {
1680 br_write_lock(vfsmount_lock); 1682 br_write_lock(&vfsmount_lock);
1681 mnt_flags |= mnt->mnt.mnt_flags & MNT_PROPAGATION_MASK; 1683 mnt_flags |= mnt->mnt.mnt_flags & MNT_PROPAGATION_MASK;
1682 mnt->mnt.mnt_flags = mnt_flags; 1684 mnt->mnt.mnt_flags = mnt_flags;
1683 br_write_unlock(vfsmount_lock); 1685 br_write_unlock(&vfsmount_lock);
1684 } 1686 }
1685 up_write(&sb->s_umount); 1687 up_write(&sb->s_umount);
1686 if (!err) { 1688 if (!err) {
1687 br_write_lock(vfsmount_lock); 1689 br_write_lock(&vfsmount_lock);
1688 touch_mnt_namespace(mnt->mnt_ns); 1690 touch_mnt_namespace(mnt->mnt_ns);
1689 br_write_unlock(vfsmount_lock); 1691 br_write_unlock(&vfsmount_lock);
1690 } 1692 }
1691 return err; 1693 return err;
1692} 1694}
@@ -1893,9 +1895,9 @@ fail:
1893 /* remove m from any expiration list it may be on */ 1895 /* remove m from any expiration list it may be on */
1894 if (!list_empty(&mnt->mnt_expire)) { 1896 if (!list_empty(&mnt->mnt_expire)) {
1895 down_write(&namespace_sem); 1897 down_write(&namespace_sem);
1896 br_write_lock(vfsmount_lock); 1898 br_write_lock(&vfsmount_lock);
1897 list_del_init(&mnt->mnt_expire); 1899 list_del_init(&mnt->mnt_expire);
1898 br_write_unlock(vfsmount_lock); 1900 br_write_unlock(&vfsmount_lock);
1899 up_write(&namespace_sem); 1901 up_write(&namespace_sem);
1900 } 1902 }
1901 mntput(m); 1903 mntput(m);
@@ -1911,11 +1913,11 @@ fail:
1911void mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list) 1913void mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list)
1912{ 1914{
1913 down_write(&namespace_sem); 1915 down_write(&namespace_sem);
1914 br_write_lock(vfsmount_lock); 1916 br_write_lock(&vfsmount_lock);
1915 1917
1916 list_add_tail(&real_mount(mnt)->mnt_expire, expiry_list); 1918 list_add_tail(&real_mount(mnt)->mnt_expire, expiry_list);
1917 1919
1918 br_write_unlock(vfsmount_lock); 1920 br_write_unlock(&vfsmount_lock);
1919 up_write(&namespace_sem); 1921 up_write(&namespace_sem);
1920} 1922}
1921EXPORT_SYMBOL(mnt_set_expiry); 1923EXPORT_SYMBOL(mnt_set_expiry);
@@ -1935,7 +1937,7 @@ void mark_mounts_for_expiry(struct list_head *mounts)
1935 return; 1937 return;
1936 1938
1937 down_write(&namespace_sem); 1939 down_write(&namespace_sem);
1938 br_write_lock(vfsmount_lock); 1940 br_write_lock(&vfsmount_lock);
1939 1941
1940 /* extract from the expiration list every vfsmount that matches the 1942 /* extract from the expiration list every vfsmount that matches the
1941 * following criteria: 1943 * following criteria:
@@ -1954,7 +1956,7 @@ void mark_mounts_for_expiry(struct list_head *mounts)
1954 touch_mnt_namespace(mnt->mnt_ns); 1956 touch_mnt_namespace(mnt->mnt_ns);
1955 umount_tree(mnt, 1, &umounts); 1957 umount_tree(mnt, 1, &umounts);
1956 } 1958 }
1957 br_write_unlock(vfsmount_lock); 1959 br_write_unlock(&vfsmount_lock);
1958 up_write(&namespace_sem); 1960 up_write(&namespace_sem);
1959 1961
1960 release_mounts(&umounts); 1962 release_mounts(&umounts);
@@ -2218,9 +2220,9 @@ void mnt_make_shortterm(struct vfsmount *m)
2218 struct mount *mnt = real_mount(m); 2220 struct mount *mnt = real_mount(m);
2219 if (atomic_add_unless(&mnt->mnt_longterm, -1, 1)) 2221 if (atomic_add_unless(&mnt->mnt_longterm, -1, 1))
2220 return; 2222 return;
2221 br_write_lock(vfsmount_lock); 2223 br_write_lock(&vfsmount_lock);
2222 atomic_dec(&mnt->mnt_longterm); 2224 atomic_dec(&mnt->mnt_longterm);
2223 br_write_unlock(vfsmount_lock); 2225 br_write_unlock(&vfsmount_lock);
2224#endif 2226#endif
2225} 2227}
2226 2228
@@ -2250,9 +2252,9 @@ static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
2250 return ERR_PTR(-ENOMEM); 2252 return ERR_PTR(-ENOMEM);
2251 } 2253 }
2252 new_ns->root = new; 2254 new_ns->root = new;
2253 br_write_lock(vfsmount_lock); 2255 br_write_lock(&vfsmount_lock);
2254 list_add_tail(&new_ns->list, &new->mnt_list); 2256 list_add_tail(&new_ns->list, &new->mnt_list);
2255 br_write_unlock(vfsmount_lock); 2257 br_write_unlock(&vfsmount_lock);
2256 2258
2257 /* 2259 /*
2258 * Second pass: switch the tsk->fs->* elements and mark new vfsmounts 2260 * Second pass: switch the tsk->fs->* elements and mark new vfsmounts
@@ -2416,9 +2418,9 @@ bool is_path_reachable(struct mount *mnt, struct dentry *dentry,
2416int path_is_under(struct path *path1, struct path *path2) 2418int path_is_under(struct path *path1, struct path *path2)
2417{ 2419{
2418 int res; 2420 int res;
2419 br_read_lock(vfsmount_lock); 2421 br_read_lock(&vfsmount_lock);
2420 res = is_path_reachable(real_mount(path1->mnt), path1->dentry, path2); 2422 res = is_path_reachable(real_mount(path1->mnt), path1->dentry, path2);
2421 br_read_unlock(vfsmount_lock); 2423 br_read_unlock(&vfsmount_lock);
2422 return res; 2424 return res;
2423} 2425}
2424EXPORT_SYMBOL(path_is_under); 2426EXPORT_SYMBOL(path_is_under);
@@ -2505,7 +2507,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
2505 /* make sure we can reach put_old from new_root */ 2507 /* make sure we can reach put_old from new_root */
2506 if (!is_path_reachable(real_mount(old.mnt), old.dentry, &new)) 2508 if (!is_path_reachable(real_mount(old.mnt), old.dentry, &new))
2507 goto out4; 2509 goto out4;
2508 br_write_lock(vfsmount_lock); 2510 br_write_lock(&vfsmount_lock);
2509 detach_mnt(new_mnt, &parent_path); 2511 detach_mnt(new_mnt, &parent_path);
2510 detach_mnt(root_mnt, &root_parent); 2512 detach_mnt(root_mnt, &root_parent);
2511 /* mount old root on put_old */ 2513 /* mount old root on put_old */
@@ -2513,7 +2515,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
2513 /* mount new_root on / */ 2515 /* mount new_root on / */
2514 attach_mnt(new_mnt, &root_parent); 2516 attach_mnt(new_mnt, &root_parent);
2515 touch_mnt_namespace(current->nsproxy->mnt_ns); 2517 touch_mnt_namespace(current->nsproxy->mnt_ns);
2516 br_write_unlock(vfsmount_lock); 2518 br_write_unlock(&vfsmount_lock);
2517 chroot_fs_refs(&root, &new); 2519 chroot_fs_refs(&root, &new);
2518 error = 0; 2520 error = 0;
2519out4: 2521out4:
@@ -2576,7 +2578,7 @@ void __init mnt_init(void)
2576 for (u = 0; u < HASH_SIZE; u++) 2578 for (u = 0; u < HASH_SIZE; u++)
2577 INIT_LIST_HEAD(&mount_hashtable[u]); 2579 INIT_LIST_HEAD(&mount_hashtable[u]);
2578 2580
2579 br_lock_init(vfsmount_lock); 2581 br_lock_init(&vfsmount_lock);
2580 2582
2581 err = sysfs_init(); 2583 err = sysfs_init();
2582 if (err) 2584 if (err)
@@ -2596,9 +2598,9 @@ void put_mnt_ns(struct mnt_namespace *ns)
2596 if (!atomic_dec_and_test(&ns->count)) 2598 if (!atomic_dec_and_test(&ns->count))
2597 return; 2599 return;
2598 down_write(&namespace_sem); 2600 down_write(&namespace_sem);
2599 br_write_lock(vfsmount_lock); 2601 br_write_lock(&vfsmount_lock);
2600 umount_tree(ns->root, 0, &umount_list); 2602 umount_tree(ns->root, 0, &umount_list);
2601 br_write_unlock(vfsmount_lock); 2603 br_write_unlock(&vfsmount_lock);
2602 up_write(&namespace_sem); 2604 up_write(&namespace_sem);
2603 release_mounts(&umount_list); 2605 release_mounts(&umount_list);
2604 kfree(ns); 2606 kfree(ns);
diff --git a/fs/ncpfs/file.c b/fs/ncpfs/file.c
index 3ff5fcc1528f..122e260247f5 100644
--- a/fs/ncpfs/file.c
+++ b/fs/ncpfs/file.c
@@ -221,6 +221,10 @@ ncp_file_write(struct file *file, const char __user *buf, size_t count, loff_t *
221 221
222 already_written = 0; 222 already_written = 0;
223 223
224 errno = file_update_time(file);
225 if (errno)
226 goto outrel;
227
224 bouncebuffer = vmalloc(bufsize); 228 bouncebuffer = vmalloc(bufsize);
225 if (!bouncebuffer) { 229 if (!bouncebuffer) {
226 errno = -EIO; /* -ENOMEM */ 230 errno = -EIO; /* -ENOMEM */
@@ -252,8 +256,6 @@ ncp_file_write(struct file *file, const char __user *buf, size_t count, loff_t *
252 } 256 }
253 vfree(bouncebuffer); 257 vfree(bouncebuffer);
254 258
255 file_update_time(file);
256
257 *ppos = pos; 259 *ppos = pos;
258 260
259 if (pos > i_size_read(inode)) { 261 if (pos > i_size_read(inode)) {
diff --git a/fs/ncpfs/ncp_fs_sb.h b/fs/ncpfs/ncp_fs_sb.h
index 4af803f13516..54cc0cdb3dcb 100644
--- a/fs/ncpfs/ncp_fs_sb.h
+++ b/fs/ncpfs/ncp_fs_sb.h
@@ -23,17 +23,17 @@ struct ncp_mount_data_kernel {
23 unsigned long flags; /* NCP_MOUNT_* flags */ 23 unsigned long flags; /* NCP_MOUNT_* flags */
24 unsigned int int_flags; /* internal flags */ 24 unsigned int int_flags; /* internal flags */
25#define NCP_IMOUNT_LOGGEDIN_POSSIBLE 0x0001 25#define NCP_IMOUNT_LOGGEDIN_POSSIBLE 0x0001
26 __kernel_uid32_t mounted_uid; /* Who may umount() this filesystem? */ 26 uid_t mounted_uid; /* Who may umount() this filesystem? */
27 struct pid *wdog_pid; /* Who cares for our watchdog packets? */ 27 struct pid *wdog_pid; /* Who cares for our watchdog packets? */
28 unsigned int ncp_fd; /* The socket to the ncp port */ 28 unsigned int ncp_fd; /* The socket to the ncp port */
29 unsigned int time_out; /* How long should I wait after 29 unsigned int time_out; /* How long should I wait after
30 sending a NCP request? */ 30 sending a NCP request? */
31 unsigned int retry_count; /* And how often should I retry? */ 31 unsigned int retry_count; /* And how often should I retry? */
32 unsigned char mounted_vol[NCP_VOLNAME_LEN + 1]; 32 unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
33 __kernel_uid32_t uid; 33 uid_t uid;
34 __kernel_gid32_t gid; 34 gid_t gid;
35 __kernel_mode_t file_mode; 35 umode_t file_mode;
36 __kernel_mode_t dir_mode; 36 umode_t dir_mode;
37 int info_fd; 37 int info_fd;
38}; 38};
39 39
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index eb95f5091c1a..970659daa323 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -17,6 +17,7 @@
17#include <linux/kthread.h> 17#include <linux/kthread.h>
18#include <linux/sunrpc/svcauth_gss.h> 18#include <linux/sunrpc/svcauth_gss.h>
19#include <linux/sunrpc/bc_xprt.h> 19#include <linux/sunrpc/bc_xprt.h>
20#include <linux/nsproxy.h>
20 21
21#include <net/inet_sock.h> 22#include <net/inet_sock.h>
22 23
@@ -253,6 +254,7 @@ int nfs_callback_up(u32 minorversion, struct rpc_xprt *xprt)
253 char svc_name[12]; 254 char svc_name[12];
254 int ret = 0; 255 int ret = 0;
255 int minorversion_setup; 256 int minorversion_setup;
257 struct net *net = current->nsproxy->net_ns;
256 258
257 mutex_lock(&nfs_callback_mutex); 259 mutex_lock(&nfs_callback_mutex);
258 if (cb_info->users++ || cb_info->task != NULL) { 260 if (cb_info->users++ || cb_info->task != NULL) {
@@ -265,6 +267,12 @@ int nfs_callback_up(u32 minorversion, struct rpc_xprt *xprt)
265 goto out_err; 267 goto out_err;
266 } 268 }
267 269
270 ret = svc_bind(serv, net);
271 if (ret < 0) {
272 printk(KERN_WARNING "NFS: bind callback service failed\n");
273 goto out_err;
274 }
275
268 minorversion_setup = nfs_minorversion_callback_svc_setup(minorversion, 276 minorversion_setup = nfs_minorversion_callback_svc_setup(minorversion,
269 serv, xprt, &rqstp, &callback_svc); 277 serv, xprt, &rqstp, &callback_svc);
270 if (!minorversion_setup) { 278 if (!minorversion_setup) {
@@ -306,6 +314,8 @@ out_err:
306 dprintk("NFS: Couldn't create callback socket or server thread; " 314 dprintk("NFS: Couldn't create callback socket or server thread; "
307 "err = %d\n", ret); 315 "err = %d\n", ret);
308 cb_info->users--; 316 cb_info->users--;
317 if (serv)
318 svc_shutdown_net(serv, net);
309 goto out; 319 goto out;
310} 320}
311 321
@@ -320,6 +330,7 @@ void nfs_callback_down(int minorversion)
320 cb_info->users--; 330 cb_info->users--;
321 if (cb_info->users == 0 && cb_info->task != NULL) { 331 if (cb_info->users == 0 && cb_info->task != NULL) {
322 kthread_stop(cb_info->task); 332 kthread_stop(cb_info->task);
333 svc_shutdown_net(cb_info->serv, current->nsproxy->net_ns);
323 svc_exit_thread(cb_info->rqst); 334 svc_exit_thread(cb_info->rqst);
324 cb_info->serv = NULL; 335 cb_info->serv = NULL;
325 cb_info->rqst = NULL; 336 cb_info->rqst = NULL;
@@ -332,7 +343,7 @@ void nfs_callback_down(int minorversion)
332int 343int
333check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp) 344check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
334{ 345{
335 char *p = svc_gss_principal(rqstp); 346 char *p = rqstp->rq_cred.cr_principal;
336 347
337 if (rqstp->rq_authop->flavour != RPC_AUTH_GSS) 348 if (rqstp->rq_authop->flavour != RPC_AUTH_GSS)
338 return 1; 349 return 1;
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 0989a2099688..f430057ff3b3 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1354,10 +1354,10 @@ out:
1354} 1354}
1355 1355
1356#ifdef CONFIG_NFS_V4 1356#ifdef CONFIG_NFS_V4
1357static int nfs_open_revalidate(struct dentry *, struct nameidata *); 1357static int nfs4_lookup_revalidate(struct dentry *, struct nameidata *);
1358 1358
1359const struct dentry_operations nfs4_dentry_operations = { 1359const struct dentry_operations nfs4_dentry_operations = {
1360 .d_revalidate = nfs_open_revalidate, 1360 .d_revalidate = nfs4_lookup_revalidate,
1361 .d_delete = nfs_dentry_delete, 1361 .d_delete = nfs_dentry_delete,
1362 .d_iput = nfs_dentry_iput, 1362 .d_iput = nfs_dentry_iput,
1363 .d_automount = nfs_d_automount, 1363 .d_automount = nfs_d_automount,
@@ -1519,13 +1519,11 @@ no_open:
1519 return nfs_lookup(dir, dentry, nd); 1519 return nfs_lookup(dir, dentry, nd);
1520} 1520}
1521 1521
1522static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd) 1522static int nfs4_lookup_revalidate(struct dentry *dentry, struct nameidata *nd)
1523{ 1523{
1524 struct dentry *parent = NULL; 1524 struct dentry *parent = NULL;
1525 struct inode *inode; 1525 struct inode *inode;
1526 struct inode *dir; 1526 struct inode *dir;
1527 struct nfs_open_context *ctx;
1528 struct iattr attr;
1529 int openflags, ret = 0; 1527 int openflags, ret = 0;
1530 1528
1531 if (nd->flags & LOOKUP_RCU) 1529 if (nd->flags & LOOKUP_RCU)
@@ -1554,57 +1552,13 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1554 /* We cannot do exclusive creation on a positive dentry */ 1552 /* We cannot do exclusive creation on a positive dentry */
1555 if ((openflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) 1553 if ((openflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL))
1556 goto no_open_dput; 1554 goto no_open_dput;
1557 /* We can't create new files here */
1558 openflags &= ~(O_CREAT|O_EXCL);
1559
1560 ctx = create_nfs_open_context(dentry, openflags);
1561 ret = PTR_ERR(ctx);
1562 if (IS_ERR(ctx))
1563 goto out;
1564 1555
1565 attr.ia_valid = ATTR_OPEN; 1556 /* Let f_op->open() actually open (and revalidate) the file */
1566 if (openflags & O_TRUNC) { 1557 ret = 1;
1567 attr.ia_valid |= ATTR_SIZE;
1568 attr.ia_size = 0;
1569 nfs_wb_all(inode);
1570 }
1571
1572 /*
1573 * Note: we're not holding inode->i_mutex and so may be racing with
1574 * operations that change the directory. We therefore save the
1575 * change attribute *before* we do the RPC call.
1576 */
1577 inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, &attr);
1578 if (IS_ERR(inode)) {
1579 ret = PTR_ERR(inode);
1580 switch (ret) {
1581 case -EPERM:
1582 case -EACCES:
1583 case -EDQUOT:
1584 case -ENOSPC:
1585 case -EROFS:
1586 goto out_put_ctx;
1587 default:
1588 goto out_drop;
1589 }
1590 }
1591 iput(inode);
1592 if (inode != dentry->d_inode)
1593 goto out_drop;
1594 1558
1595 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1596 ret = nfs_intent_set_file(nd, ctx);
1597 if (ret >= 0)
1598 ret = 1;
1599out: 1559out:
1600 dput(parent); 1560 dput(parent);
1601 return ret; 1561 return ret;
1602out_drop:
1603 d_drop(dentry);
1604 ret = 0;
1605out_put_ctx:
1606 put_nfs_open_context(ctx);
1607 goto out;
1608 1562
1609no_open_dput: 1563no_open_dput:
1610 dput(parent); 1564 dput(parent);
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 56311ca5f9f8..a6708e6b438d 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -879,12 +879,81 @@ const struct file_operations nfs_file_operations = {
879static int 879static int
880nfs4_file_open(struct inode *inode, struct file *filp) 880nfs4_file_open(struct inode *inode, struct file *filp)
881{ 881{
882 struct nfs_open_context *ctx;
883 struct dentry *dentry = filp->f_path.dentry;
884 struct dentry *parent = NULL;
885 struct inode *dir;
886 unsigned openflags = filp->f_flags;
887 struct iattr attr;
888 int err;
889
890 BUG_ON(inode != dentry->d_inode);
882 /* 891 /*
883 * NFSv4 opens are handled in d_lookup and d_revalidate. If we get to 892 * If no cached dentry exists or if it's negative, NFSv4 handled the
884 * this point, then something is very wrong 893 * opens in ->lookup() or ->create().
894 *
895 * We only get this far for a cached positive dentry. We skipped
896 * revalidation, so handle it here by dropping the dentry and returning
897 * -EOPENSTALE. The VFS will retry the lookup/create/open.
885 */ 898 */
886 dprintk("NFS: %s called! inode=%p filp=%p\n", __func__, inode, filp); 899
887 return -ENOTDIR; 900 dprintk("NFS: open file(%s/%s)\n",
901 dentry->d_parent->d_name.name,
902 dentry->d_name.name);
903
904 if ((openflags & O_ACCMODE) == 3)
905 openflags--;
906
907 /* We can't create new files here */
908 openflags &= ~(O_CREAT|O_EXCL);
909
910 parent = dget_parent(dentry);
911 dir = parent->d_inode;
912
913 ctx = alloc_nfs_open_context(filp->f_path.dentry, filp->f_mode);
914 err = PTR_ERR(ctx);
915 if (IS_ERR(ctx))
916 goto out;
917
918 attr.ia_valid = ATTR_OPEN;
919 if (openflags & O_TRUNC) {
920 attr.ia_valid |= ATTR_SIZE;
921 attr.ia_size = 0;
922 nfs_wb_all(inode);
923 }
924
925 inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, &attr);
926 if (IS_ERR(inode)) {
927 err = PTR_ERR(inode);
928 switch (err) {
929 case -EPERM:
930 case -EACCES:
931 case -EDQUOT:
932 case -ENOSPC:
933 case -EROFS:
934 goto out_put_ctx;
935 default:
936 goto out_drop;
937 }
938 }
939 iput(inode);
940 if (inode != dentry->d_inode)
941 goto out_drop;
942
943 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
944 nfs_file_set_open_context(filp, ctx);
945 err = 0;
946
947out_put_ctx:
948 put_nfs_open_context(ctx);
949out:
950 dput(parent);
951 return err;
952
953out_drop:
954 d_drop(dentry);
955 err = -EOPENSTALE;
956 goto out_put_ctx;
888} 957}
889 958
890const struct file_operations nfs4_file_operations = { 959const struct file_operations nfs4_file_operations = {
diff --git a/fs/nfsd/auth.c b/fs/nfsd/auth.c
index 204438cc914e..34a10d78b839 100644
--- a/fs/nfsd/auth.c
+++ b/fs/nfsd/auth.c
@@ -11,7 +11,7 @@ int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
11 struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors; 11 struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
12 12
13 for (f = exp->ex_flavors; f < end; f++) { 13 for (f = exp->ex_flavors; f < end; f++) {
14 if (f->pseudoflavor == rqstp->rq_flavor) 14 if (f->pseudoflavor == rqstp->rq_cred.cr_flavor)
15 return f->flags; 15 return f->flags;
16 } 16 }
17 return exp->ex_flags; 17 return exp->ex_flags;
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 8e9689abbc0c..ba233499b9a5 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -15,11 +15,13 @@
15#include <linux/namei.h> 15#include <linux/namei.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/exportfs.h> 17#include <linux/exportfs.h>
18#include <linux/sunrpc/svc_xprt.h>
18 19
19#include <net/ipv6.h> 20#include <net/ipv6.h>
20 21
21#include "nfsd.h" 22#include "nfsd.h"
22#include "nfsfh.h" 23#include "nfsfh.h"
24#include "netns.h"
23 25
24#define NFSDDBG_FACILITY NFSDDBG_EXPORT 26#define NFSDDBG_FACILITY NFSDDBG_EXPORT
25 27
@@ -38,7 +40,6 @@ typedef struct svc_export svc_export;
38#define EXPKEY_HASHBITS 8 40#define EXPKEY_HASHBITS 8
39#define EXPKEY_HASHMAX (1 << EXPKEY_HASHBITS) 41#define EXPKEY_HASHMAX (1 << EXPKEY_HASHBITS)
40#define EXPKEY_HASHMASK (EXPKEY_HASHMAX -1) 42#define EXPKEY_HASHMASK (EXPKEY_HASHMAX -1)
41static struct cache_head *expkey_table[EXPKEY_HASHMAX];
42 43
43static void expkey_put(struct kref *ref) 44static void expkey_put(struct kref *ref)
44{ 45{
@@ -71,9 +72,9 @@ static int expkey_upcall(struct cache_detail *cd, struct cache_head *h)
71 return sunrpc_cache_pipe_upcall(cd, h, expkey_request); 72 return sunrpc_cache_pipe_upcall(cd, h, expkey_request);
72} 73}
73 74
74static struct svc_expkey *svc_expkey_update(struct svc_expkey *new, struct svc_expkey *old); 75static struct svc_expkey *svc_expkey_update(struct cache_detail *cd, struct svc_expkey *new,
75static struct svc_expkey *svc_expkey_lookup(struct svc_expkey *); 76 struct svc_expkey *old);
76static struct cache_detail svc_expkey_cache; 77static struct svc_expkey *svc_expkey_lookup(struct cache_detail *cd, struct svc_expkey *);
77 78
78static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen) 79static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
79{ 80{
@@ -131,7 +132,7 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
131 key.ek_fsidtype = fsidtype; 132 key.ek_fsidtype = fsidtype;
132 memcpy(key.ek_fsid, buf, len); 133 memcpy(key.ek_fsid, buf, len);
133 134
134 ek = svc_expkey_lookup(&key); 135 ek = svc_expkey_lookup(cd, &key);
135 err = -ENOMEM; 136 err = -ENOMEM;
136 if (!ek) 137 if (!ek)
137 goto out; 138 goto out;
@@ -145,7 +146,7 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
145 err = 0; 146 err = 0;
146 if (len == 0) { 147 if (len == 0) {
147 set_bit(CACHE_NEGATIVE, &key.h.flags); 148 set_bit(CACHE_NEGATIVE, &key.h.flags);
148 ek = svc_expkey_update(&key, ek); 149 ek = svc_expkey_update(cd, &key, ek);
149 if (!ek) 150 if (!ek)
150 err = -ENOMEM; 151 err = -ENOMEM;
151 } else { 152 } else {
@@ -155,7 +156,7 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
155 156
156 dprintk("Found the path %s\n", buf); 157 dprintk("Found the path %s\n", buf);
157 158
158 ek = svc_expkey_update(&key, ek); 159 ek = svc_expkey_update(cd, &key, ek);
159 if (!ek) 160 if (!ek)
160 err = -ENOMEM; 161 err = -ENOMEM;
161 path_put(&key.ek_path); 162 path_put(&key.ek_path);
@@ -163,7 +164,7 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
163 cache_flush(); 164 cache_flush();
164 out: 165 out:
165 if (ek) 166 if (ek)
166 cache_put(&ek->h, &svc_expkey_cache); 167 cache_put(&ek->h, cd);
167 if (dom) 168 if (dom)
168 auth_domain_put(dom); 169 auth_domain_put(dom);
169 kfree(buf); 170 kfree(buf);
@@ -239,10 +240,9 @@ static struct cache_head *expkey_alloc(void)
239 return NULL; 240 return NULL;
240} 241}
241 242
242static struct cache_detail svc_expkey_cache = { 243static struct cache_detail svc_expkey_cache_template = {
243 .owner = THIS_MODULE, 244 .owner = THIS_MODULE,
244 .hash_size = EXPKEY_HASHMAX, 245 .hash_size = EXPKEY_HASHMAX,
245 .hash_table = expkey_table,
246 .name = "nfsd.fh", 246 .name = "nfsd.fh",
247 .cache_put = expkey_put, 247 .cache_put = expkey_put,
248 .cache_upcall = expkey_upcall, 248 .cache_upcall = expkey_upcall,
@@ -268,13 +268,12 @@ svc_expkey_hash(struct svc_expkey *item)
268} 268}
269 269
270static struct svc_expkey * 270static struct svc_expkey *
271svc_expkey_lookup(struct svc_expkey *item) 271svc_expkey_lookup(struct cache_detail *cd, struct svc_expkey *item)
272{ 272{
273 struct cache_head *ch; 273 struct cache_head *ch;
274 int hash = svc_expkey_hash(item); 274 int hash = svc_expkey_hash(item);
275 275
276 ch = sunrpc_cache_lookup(&svc_expkey_cache, &item->h, 276 ch = sunrpc_cache_lookup(cd, &item->h, hash);
277 hash);
278 if (ch) 277 if (ch)
279 return container_of(ch, struct svc_expkey, h); 278 return container_of(ch, struct svc_expkey, h);
280 else 279 else
@@ -282,13 +281,13 @@ svc_expkey_lookup(struct svc_expkey *item)
282} 281}
283 282
284static struct svc_expkey * 283static struct svc_expkey *
285svc_expkey_update(struct svc_expkey *new, struct svc_expkey *old) 284svc_expkey_update(struct cache_detail *cd, struct svc_expkey *new,
285 struct svc_expkey *old)
286{ 286{
287 struct cache_head *ch; 287 struct cache_head *ch;
288 int hash = svc_expkey_hash(new); 288 int hash = svc_expkey_hash(new);
289 289
290 ch = sunrpc_cache_update(&svc_expkey_cache, &new->h, 290 ch = sunrpc_cache_update(cd, &new->h, &old->h, hash);
291 &old->h, hash);
292 if (ch) 291 if (ch)
293 return container_of(ch, struct svc_expkey, h); 292 return container_of(ch, struct svc_expkey, h);
294 else 293 else
@@ -299,8 +298,6 @@ svc_expkey_update(struct svc_expkey *new, struct svc_expkey *old)
299#define EXPORT_HASHBITS 8 298#define EXPORT_HASHBITS 8
300#define EXPORT_HASHMAX (1<< EXPORT_HASHBITS) 299#define EXPORT_HASHMAX (1<< EXPORT_HASHBITS)
301 300
302static struct cache_head *export_table[EXPORT_HASHMAX];
303
304static void nfsd4_fslocs_free(struct nfsd4_fs_locations *fsloc) 301static void nfsd4_fslocs_free(struct nfsd4_fs_locations *fsloc)
305{ 302{
306 int i; 303 int i;
@@ -525,6 +522,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
525 goto out1; 522 goto out1;
526 523
527 exp.ex_client = dom; 524 exp.ex_client = dom;
525 exp.cd = cd;
528 526
529 /* expiry */ 527 /* expiry */
530 err = -EINVAL; 528 err = -EINVAL;
@@ -672,6 +670,7 @@ static void svc_export_init(struct cache_head *cnew, struct cache_head *citem)
672 new->ex_fslocs.locations = NULL; 670 new->ex_fslocs.locations = NULL;
673 new->ex_fslocs.locations_count = 0; 671 new->ex_fslocs.locations_count = 0;
674 new->ex_fslocs.migrated = 0; 672 new->ex_fslocs.migrated = 0;
673 new->cd = item->cd;
675} 674}
676 675
677static void export_update(struct cache_head *cnew, struct cache_head *citem) 676static void export_update(struct cache_head *cnew, struct cache_head *citem)
@@ -707,10 +706,9 @@ static struct cache_head *svc_export_alloc(void)
707 return NULL; 706 return NULL;
708} 707}
709 708
710struct cache_detail svc_export_cache = { 709static struct cache_detail svc_export_cache_template = {
711 .owner = THIS_MODULE, 710 .owner = THIS_MODULE,
712 .hash_size = EXPORT_HASHMAX, 711 .hash_size = EXPORT_HASHMAX,
713 .hash_table = export_table,
714 .name = "nfsd.export", 712 .name = "nfsd.export",
715 .cache_put = svc_export_put, 713 .cache_put = svc_export_put,
716 .cache_upcall = svc_export_upcall, 714 .cache_upcall = svc_export_upcall,
@@ -739,8 +737,7 @@ svc_export_lookup(struct svc_export *exp)
739 struct cache_head *ch; 737 struct cache_head *ch;
740 int hash = svc_export_hash(exp); 738 int hash = svc_export_hash(exp);
741 739
742 ch = sunrpc_cache_lookup(&svc_export_cache, &exp->h, 740 ch = sunrpc_cache_lookup(exp->cd, &exp->h, hash);
743 hash);
744 if (ch) 741 if (ch)
745 return container_of(ch, struct svc_export, h); 742 return container_of(ch, struct svc_export, h);
746 else 743 else
@@ -753,9 +750,7 @@ svc_export_update(struct svc_export *new, struct svc_export *old)
753 struct cache_head *ch; 750 struct cache_head *ch;
754 int hash = svc_export_hash(old); 751 int hash = svc_export_hash(old);
755 752
756 ch = sunrpc_cache_update(&svc_export_cache, &new->h, 753 ch = sunrpc_cache_update(old->cd, &new->h, &old->h, hash);
757 &old->h,
758 hash);
759 if (ch) 754 if (ch)
760 return container_of(ch, struct svc_export, h); 755 return container_of(ch, struct svc_export, h);
761 else 756 else
@@ -764,7 +759,8 @@ svc_export_update(struct svc_export *new, struct svc_export *old)
764 759
765 760
766static struct svc_expkey * 761static struct svc_expkey *
767exp_find_key(svc_client *clp, int fsid_type, u32 *fsidv, struct cache_req *reqp) 762exp_find_key(struct cache_detail *cd, svc_client *clp, int fsid_type,
763 u32 *fsidv, struct cache_req *reqp)
768{ 764{
769 struct svc_expkey key, *ek; 765 struct svc_expkey key, *ek;
770 int err; 766 int err;
@@ -776,18 +772,18 @@ exp_find_key(svc_client *clp, int fsid_type, u32 *fsidv, struct cache_req *reqp)
776 key.ek_fsidtype = fsid_type; 772 key.ek_fsidtype = fsid_type;
777 memcpy(key.ek_fsid, fsidv, key_len(fsid_type)); 773 memcpy(key.ek_fsid, fsidv, key_len(fsid_type));
778 774
779 ek = svc_expkey_lookup(&key); 775 ek = svc_expkey_lookup(cd, &key);
780 if (ek == NULL) 776 if (ek == NULL)
781 return ERR_PTR(-ENOMEM); 777 return ERR_PTR(-ENOMEM);
782 err = cache_check(&svc_expkey_cache, &ek->h, reqp); 778 err = cache_check(cd, &ek->h, reqp);
783 if (err) 779 if (err)
784 return ERR_PTR(err); 780 return ERR_PTR(err);
785 return ek; 781 return ek;
786} 782}
787 783
788 784
789static svc_export *exp_get_by_name(svc_client *clp, const struct path *path, 785static svc_export *exp_get_by_name(struct cache_detail *cd, svc_client *clp,
790 struct cache_req *reqp) 786 const struct path *path, struct cache_req *reqp)
791{ 787{
792 struct svc_export *exp, key; 788 struct svc_export *exp, key;
793 int err; 789 int err;
@@ -797,11 +793,12 @@ static svc_export *exp_get_by_name(svc_client *clp, const struct path *path,
797 793
798 key.ex_client = clp; 794 key.ex_client = clp;
799 key.ex_path = *path; 795 key.ex_path = *path;
796 key.cd = cd;
800 797
801 exp = svc_export_lookup(&key); 798 exp = svc_export_lookup(&key);
802 if (exp == NULL) 799 if (exp == NULL)
803 return ERR_PTR(-ENOMEM); 800 return ERR_PTR(-ENOMEM);
804 err = cache_check(&svc_export_cache, &exp->h, reqp); 801 err = cache_check(cd, &exp->h, reqp);
805 if (err) 802 if (err)
806 return ERR_PTR(err); 803 return ERR_PTR(err);
807 return exp; 804 return exp;
@@ -810,16 +807,17 @@ static svc_export *exp_get_by_name(svc_client *clp, const struct path *path,
810/* 807/*
811 * Find the export entry for a given dentry. 808 * Find the export entry for a given dentry.
812 */ 809 */
813static struct svc_export *exp_parent(svc_client *clp, struct path *path) 810static struct svc_export *exp_parent(struct cache_detail *cd, svc_client *clp,
811 struct path *path)
814{ 812{
815 struct dentry *saved = dget(path->dentry); 813 struct dentry *saved = dget(path->dentry);
816 svc_export *exp = exp_get_by_name(clp, path, NULL); 814 svc_export *exp = exp_get_by_name(cd, clp, path, NULL);
817 815
818 while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) { 816 while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) {
819 struct dentry *parent = dget_parent(path->dentry); 817 struct dentry *parent = dget_parent(path->dentry);
820 dput(path->dentry); 818 dput(path->dentry);
821 path->dentry = parent; 819 path->dentry = parent;
822 exp = exp_get_by_name(clp, path, NULL); 820 exp = exp_get_by_name(cd, clp, path, NULL);
823 } 821 }
824 dput(path->dentry); 822 dput(path->dentry);
825 path->dentry = saved; 823 path->dentry = saved;
@@ -834,13 +832,16 @@ static struct svc_export *exp_parent(svc_client *clp, struct path *path)
834 * since its harder to fool a kernel module than a user space program. 832 * since its harder to fool a kernel module than a user space program.
835 */ 833 */
836int 834int
837exp_rootfh(svc_client *clp, char *name, struct knfsd_fh *f, int maxsize) 835exp_rootfh(struct net *net, svc_client *clp, char *name,
836 struct knfsd_fh *f, int maxsize)
838{ 837{
839 struct svc_export *exp; 838 struct svc_export *exp;
840 struct path path; 839 struct path path;
841 struct inode *inode; 840 struct inode *inode;
842 struct svc_fh fh; 841 struct svc_fh fh;
843 int err; 842 int err;
843 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
844 struct cache_detail *cd = nn->svc_export_cache;
844 845
845 err = -EPERM; 846 err = -EPERM;
846 /* NB: we probably ought to check that it's NUL-terminated */ 847 /* NB: we probably ought to check that it's NUL-terminated */
@@ -853,7 +854,7 @@ exp_rootfh(svc_client *clp, char *name, struct knfsd_fh *f, int maxsize)
853 dprintk("nfsd: exp_rootfh(%s [%p] %s:%s/%ld)\n", 854 dprintk("nfsd: exp_rootfh(%s [%p] %s:%s/%ld)\n",
854 name, path.dentry, clp->name, 855 name, path.dentry, clp->name,
855 inode->i_sb->s_id, inode->i_ino); 856 inode->i_sb->s_id, inode->i_ino);
856 exp = exp_parent(clp, &path); 857 exp = exp_parent(cd, clp, &path);
857 if (IS_ERR(exp)) { 858 if (IS_ERR(exp)) {
858 err = PTR_ERR(exp); 859 err = PTR_ERR(exp);
859 goto out; 860 goto out;
@@ -875,16 +876,18 @@ out:
875 return err; 876 return err;
876} 877}
877 878
878static struct svc_export *exp_find(struct auth_domain *clp, int fsid_type, 879static struct svc_export *exp_find(struct cache_detail *cd,
880 struct auth_domain *clp, int fsid_type,
879 u32 *fsidv, struct cache_req *reqp) 881 u32 *fsidv, struct cache_req *reqp)
880{ 882{
881 struct svc_export *exp; 883 struct svc_export *exp;
882 struct svc_expkey *ek = exp_find_key(clp, fsid_type, fsidv, reqp); 884 struct nfsd_net *nn = net_generic(cd->net, nfsd_net_id);
885 struct svc_expkey *ek = exp_find_key(nn->svc_expkey_cache, clp, fsid_type, fsidv, reqp);
883 if (IS_ERR(ek)) 886 if (IS_ERR(ek))
884 return ERR_CAST(ek); 887 return ERR_CAST(ek);
885 888
886 exp = exp_get_by_name(clp, &ek->ek_path, reqp); 889 exp = exp_get_by_name(cd, clp, &ek->ek_path, reqp);
887 cache_put(&ek->h, &svc_expkey_cache); 890 cache_put(&ek->h, nn->svc_expkey_cache);
888 891
889 if (IS_ERR(exp)) 892 if (IS_ERR(exp))
890 return ERR_CAST(exp); 893 return ERR_CAST(exp);
@@ -901,13 +904,13 @@ __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
901 return 0; 904 return 0;
902 /* ip-address based client; check sec= export option: */ 905 /* ip-address based client; check sec= export option: */
903 for (f = exp->ex_flavors; f < end; f++) { 906 for (f = exp->ex_flavors; f < end; f++) {
904 if (f->pseudoflavor == rqstp->rq_flavor) 907 if (f->pseudoflavor == rqstp->rq_cred.cr_flavor)
905 return 0; 908 return 0;
906 } 909 }
907 /* defaults in absence of sec= options: */ 910 /* defaults in absence of sec= options: */
908 if (exp->ex_nflavors == 0) { 911 if (exp->ex_nflavors == 0) {
909 if (rqstp->rq_flavor == RPC_AUTH_NULL || 912 if (rqstp->rq_cred.cr_flavor == RPC_AUTH_NULL ||
910 rqstp->rq_flavor == RPC_AUTH_UNIX) 913 rqstp->rq_cred.cr_flavor == RPC_AUTH_UNIX)
911 return 0; 914 return 0;
912 } 915 }
913 return nfserr_wrongsec; 916 return nfserr_wrongsec;
@@ -926,12 +929,14 @@ struct svc_export *
926rqst_exp_get_by_name(struct svc_rqst *rqstp, struct path *path) 929rqst_exp_get_by_name(struct svc_rqst *rqstp, struct path *path)
927{ 930{
928 struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT); 931 struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
932 struct nfsd_net *nn = net_generic(rqstp->rq_xprt->xpt_net, nfsd_net_id);
933 struct cache_detail *cd = nn->svc_export_cache;
929 934
930 if (rqstp->rq_client == NULL) 935 if (rqstp->rq_client == NULL)
931 goto gss; 936 goto gss;
932 937
933 /* First try the auth_unix client: */ 938 /* First try the auth_unix client: */
934 exp = exp_get_by_name(rqstp->rq_client, path, &rqstp->rq_chandle); 939 exp = exp_get_by_name(cd, rqstp->rq_client, path, &rqstp->rq_chandle);
935 if (PTR_ERR(exp) == -ENOENT) 940 if (PTR_ERR(exp) == -ENOENT)
936 goto gss; 941 goto gss;
937 if (IS_ERR(exp)) 942 if (IS_ERR(exp))
@@ -943,7 +948,7 @@ gss:
943 /* Otherwise, try falling back on gss client */ 948 /* Otherwise, try falling back on gss client */
944 if (rqstp->rq_gssclient == NULL) 949 if (rqstp->rq_gssclient == NULL)
945 return exp; 950 return exp;
946 gssexp = exp_get_by_name(rqstp->rq_gssclient, path, &rqstp->rq_chandle); 951 gssexp = exp_get_by_name(cd, rqstp->rq_gssclient, path, &rqstp->rq_chandle);
947 if (PTR_ERR(gssexp) == -ENOENT) 952 if (PTR_ERR(gssexp) == -ENOENT)
948 return exp; 953 return exp;
949 if (!IS_ERR(exp)) 954 if (!IS_ERR(exp))
@@ -955,12 +960,15 @@ struct svc_export *
955rqst_exp_find(struct svc_rqst *rqstp, int fsid_type, u32 *fsidv) 960rqst_exp_find(struct svc_rqst *rqstp, int fsid_type, u32 *fsidv)
956{ 961{
957 struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT); 962 struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
963 struct nfsd_net *nn = net_generic(rqstp->rq_xprt->xpt_net, nfsd_net_id);
964 struct cache_detail *cd = nn->svc_export_cache;
958 965
959 if (rqstp->rq_client == NULL) 966 if (rqstp->rq_client == NULL)
960 goto gss; 967 goto gss;
961 968
962 /* First try the auth_unix client: */ 969 /* First try the auth_unix client: */
963 exp = exp_find(rqstp->rq_client, fsid_type, fsidv, &rqstp->rq_chandle); 970 exp = exp_find(cd, rqstp->rq_client, fsid_type,
971 fsidv, &rqstp->rq_chandle);
964 if (PTR_ERR(exp) == -ENOENT) 972 if (PTR_ERR(exp) == -ENOENT)
965 goto gss; 973 goto gss;
966 if (IS_ERR(exp)) 974 if (IS_ERR(exp))
@@ -972,7 +980,7 @@ gss:
972 /* Otherwise, try falling back on gss client */ 980 /* Otherwise, try falling back on gss client */
973 if (rqstp->rq_gssclient == NULL) 981 if (rqstp->rq_gssclient == NULL)
974 return exp; 982 return exp;
975 gssexp = exp_find(rqstp->rq_gssclient, fsid_type, fsidv, 983 gssexp = exp_find(cd, rqstp->rq_gssclient, fsid_type, fsidv,
976 &rqstp->rq_chandle); 984 &rqstp->rq_chandle);
977 if (PTR_ERR(gssexp) == -ENOENT) 985 if (PTR_ERR(gssexp) == -ENOENT)
978 return exp; 986 return exp;
@@ -1029,13 +1037,15 @@ exp_pseudoroot(struct svc_rqst *rqstp, struct svc_fh *fhp)
1029/* Iterator */ 1037/* Iterator */
1030 1038
1031static void *e_start(struct seq_file *m, loff_t *pos) 1039static void *e_start(struct seq_file *m, loff_t *pos)
1032 __acquires(svc_export_cache.hash_lock) 1040 __acquires(((struct cache_detail *)m->private)->hash_lock)
1033{ 1041{
1034 loff_t n = *pos; 1042 loff_t n = *pos;
1035 unsigned hash, export; 1043 unsigned hash, export;
1036 struct cache_head *ch; 1044 struct cache_head *ch;
1037 1045 struct cache_detail *cd = m->private;
1038 read_lock(&svc_export_cache.hash_lock); 1046 struct cache_head **export_table = cd->hash_table;
1047
1048 read_lock(&cd->hash_lock);
1039 if (!n--) 1049 if (!n--)
1040 return SEQ_START_TOKEN; 1050 return SEQ_START_TOKEN;
1041 hash = n >> 32; 1051 hash = n >> 32;
@@ -1060,6 +1070,8 @@ static void *e_next(struct seq_file *m, void *p, loff_t *pos)
1060{ 1070{
1061 struct cache_head *ch = p; 1071 struct cache_head *ch = p;
1062 int hash = (*pos >> 32); 1072 int hash = (*pos >> 32);
1073 struct cache_detail *cd = m->private;
1074 struct cache_head **export_table = cd->hash_table;
1063 1075
1064 if (p == SEQ_START_TOKEN) 1076 if (p == SEQ_START_TOKEN)
1065 hash = 0; 1077 hash = 0;
@@ -1082,9 +1094,11 @@ static void *e_next(struct seq_file *m, void *p, loff_t *pos)
1082} 1094}
1083 1095
1084static void e_stop(struct seq_file *m, void *p) 1096static void e_stop(struct seq_file *m, void *p)
1085 __releases(svc_export_cache.hash_lock) 1097 __releases(((struct cache_detail *)m->private)->hash_lock)
1086{ 1098{
1087 read_unlock(&svc_export_cache.hash_lock); 1099 struct cache_detail *cd = m->private;
1100
1101 read_unlock(&cd->hash_lock);
1088} 1102}
1089 1103
1090static struct flags { 1104static struct flags {
@@ -1195,6 +1209,7 @@ static int e_show(struct seq_file *m, void *p)
1195{ 1209{
1196 struct cache_head *cp = p; 1210 struct cache_head *cp = p;
1197 struct svc_export *exp = container_of(cp, struct svc_export, h); 1211 struct svc_export *exp = container_of(cp, struct svc_export, h);
1212 struct cache_detail *cd = m->private;
1198 1213
1199 if (p == SEQ_START_TOKEN) { 1214 if (p == SEQ_START_TOKEN) {
1200 seq_puts(m, "# Version 1.1\n"); 1215 seq_puts(m, "# Version 1.1\n");
@@ -1203,10 +1218,10 @@ static int e_show(struct seq_file *m, void *p)
1203 } 1218 }
1204 1219
1205 cache_get(&exp->h); 1220 cache_get(&exp->h);
1206 if (cache_check(&svc_export_cache, &exp->h, NULL)) 1221 if (cache_check(cd, &exp->h, NULL))
1207 return 0; 1222 return 0;
1208 cache_put(&exp->h, &svc_export_cache); 1223 exp_put(exp);
1209 return svc_export_show(m, &svc_export_cache, cp); 1224 return svc_export_show(m, cd, cp);
1210} 1225}
1211 1226
1212const struct seq_operations nfs_exports_op = { 1227const struct seq_operations nfs_exports_op = {
@@ -1216,48 +1231,70 @@ const struct seq_operations nfs_exports_op = {
1216 .show = e_show, 1231 .show = e_show,
1217}; 1232};
1218 1233
1219
1220/* 1234/*
1221 * Initialize the exports module. 1235 * Initialize the exports module.
1222 */ 1236 */
1223int 1237int
1224nfsd_export_init(void) 1238nfsd_export_init(struct net *net)
1225{ 1239{
1226 int rv; 1240 int rv;
1227 dprintk("nfsd: initializing export module.\n"); 1241 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1242
1243 dprintk("nfsd: initializing export module (net: %p).\n", net);
1228 1244
1229 rv = cache_register_net(&svc_export_cache, &init_net); 1245 nn->svc_export_cache = cache_create_net(&svc_export_cache_template, net);
1246 if (IS_ERR(nn->svc_export_cache))
1247 return PTR_ERR(nn->svc_export_cache);
1248 rv = cache_register_net(nn->svc_export_cache, net);
1230 if (rv) 1249 if (rv)
1231 return rv; 1250 goto destroy_export_cache;
1232 rv = cache_register_net(&svc_expkey_cache, &init_net); 1251
1252 nn->svc_expkey_cache = cache_create_net(&svc_expkey_cache_template, net);
1253 if (IS_ERR(nn->svc_expkey_cache)) {
1254 rv = PTR_ERR(nn->svc_expkey_cache);
1255 goto unregister_export_cache;
1256 }
1257 rv = cache_register_net(nn->svc_expkey_cache, net);
1233 if (rv) 1258 if (rv)
1234 cache_unregister_net(&svc_export_cache, &init_net); 1259 goto destroy_expkey_cache;
1235 return rv; 1260 return 0;
1236 1261
1262destroy_expkey_cache:
1263 cache_destroy_net(nn->svc_expkey_cache, net);
1264unregister_export_cache:
1265 cache_unregister_net(nn->svc_export_cache, net);
1266destroy_export_cache:
1267 cache_destroy_net(nn->svc_export_cache, net);
1268 return rv;
1237} 1269}
1238 1270
1239/* 1271/*
1240 * Flush exports table - called when last nfsd thread is killed 1272 * Flush exports table - called when last nfsd thread is killed
1241 */ 1273 */
1242void 1274void
1243nfsd_export_flush(void) 1275nfsd_export_flush(struct net *net)
1244{ 1276{
1245 cache_purge(&svc_expkey_cache); 1277 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1246 cache_purge(&svc_export_cache); 1278
1279 cache_purge(nn->svc_expkey_cache);
1280 cache_purge(nn->svc_export_cache);
1247} 1281}
1248 1282
1249/* 1283/*
1250 * Shutdown the exports module. 1284 * Shutdown the exports module.
1251 */ 1285 */
1252void 1286void
1253nfsd_export_shutdown(void) 1287nfsd_export_shutdown(struct net *net)
1254{ 1288{
1289 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1255 1290
1256 dprintk("nfsd: shutting down export module.\n"); 1291 dprintk("nfsd: shutting down export module (net: %p).\n", net);
1257 1292
1258 cache_unregister_net(&svc_expkey_cache, &init_net); 1293 cache_unregister_net(nn->svc_expkey_cache, net);
1259 cache_unregister_net(&svc_export_cache, &init_net); 1294 cache_unregister_net(nn->svc_export_cache, net);
1260 svcauth_unix_purge(); 1295 cache_destroy_net(nn->svc_expkey_cache, net);
1296 cache_destroy_net(nn->svc_export_cache, net);
1297 svcauth_unix_purge(net);
1261 1298
1262 dprintk("nfsd: export shutdown complete.\n"); 1299 dprintk("nfsd: export shutdown complete (net: %p).\n", net);
1263} 1300}
diff --git a/fs/nfsd/fault_inject.c b/fs/nfsd/fault_inject.c
index 9559ce468732..e6c38159622f 100644
--- a/fs/nfsd/fault_inject.c
+++ b/fs/nfsd/fault_inject.c
@@ -58,6 +58,7 @@ static int nfsd_inject_set(void *op_ptr, u64 val)
58 58
59static int nfsd_inject_get(void *data, u64 *val) 59static int nfsd_inject_get(void *data, u64 *val)
60{ 60{
61 *val = 0;
61 return 0; 62 return 0;
62} 63}
63 64
diff --git a/fs/nfsd/idmap.h b/fs/nfsd/idmap.h
index 2f3be1321534..9d513efc01ba 100644
--- a/fs/nfsd/idmap.h
+++ b/fs/nfsd/idmap.h
@@ -42,14 +42,14 @@
42#define IDMAP_NAMESZ 128 42#define IDMAP_NAMESZ 128
43 43
44#ifdef CONFIG_NFSD_V4 44#ifdef CONFIG_NFSD_V4
45int nfsd_idmap_init(void); 45int nfsd_idmap_init(struct net *);
46void nfsd_idmap_shutdown(void); 46void nfsd_idmap_shutdown(struct net *);
47#else 47#else
48static inline int nfsd_idmap_init(void) 48static inline int nfsd_idmap_init(struct net *net)
49{ 49{
50 return 0; 50 return 0;
51} 51}
52static inline void nfsd_idmap_shutdown(void) 52static inline void nfsd_idmap_shutdown(struct net *net)
53{ 53{
54} 54}
55#endif 55#endif
diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h
index 12e0cff435b4..39365636b244 100644
--- a/fs/nfsd/netns.h
+++ b/fs/nfsd/netns.h
@@ -28,6 +28,12 @@ struct cld_net;
28 28
29struct nfsd_net { 29struct nfsd_net {
30 struct cld_net *cld_net; 30 struct cld_net *cld_net;
31
32 struct cache_detail *svc_expkey_cache;
33 struct cache_detail *svc_export_cache;
34
35 struct cache_detail *idtoname_cache;
36 struct cache_detail *nametoid_cache;
31}; 37};
32 38
33extern int nfsd_net_id; 39extern int nfsd_net_id;
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index c8e9f637153a..a5fd6b982f27 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -650,9 +650,10 @@ static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *c
650 struct rpc_clnt *client; 650 struct rpc_clnt *client;
651 651
652 if (clp->cl_minorversion == 0) { 652 if (clp->cl_minorversion == 0) {
653 if (!clp->cl_principal && (clp->cl_flavor >= RPC_AUTH_GSS_KRB5)) 653 if (!clp->cl_cred.cr_principal &&
654 (clp->cl_flavor >= RPC_AUTH_GSS_KRB5))
654 return -EINVAL; 655 return -EINVAL;
655 args.client_name = clp->cl_principal; 656 args.client_name = clp->cl_cred.cr_principal;
656 args.prognumber = conn->cb_prog, 657 args.prognumber = conn->cb_prog,
657 args.protocol = XPRT_TRANSPORT_TCP; 658 args.protocol = XPRT_TRANSPORT_TCP;
658 args.authflavor = clp->cl_flavor; 659 args.authflavor = clp->cl_flavor;
diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c
index 322d11ce06a4..dae36f1dee95 100644
--- a/fs/nfsd/nfs4idmap.c
+++ b/fs/nfsd/nfs4idmap.c
@@ -36,9 +36,11 @@
36#include <linux/seq_file.h> 36#include <linux/seq_file.h>
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/sunrpc/svc_xprt.h>
39#include <net/net_namespace.h> 40#include <net/net_namespace.h>
40#include "idmap.h" 41#include "idmap.h"
41#include "nfsd.h" 42#include "nfsd.h"
43#include "netns.h"
42 44
43/* 45/*
44 * Turn off idmapping when using AUTH_SYS. 46 * Turn off idmapping when using AUTH_SYS.
@@ -107,8 +109,6 @@ ent_alloc(void)
107 * ID -> Name cache 109 * ID -> Name cache
108 */ 110 */
109 111
110static struct cache_head *idtoname_table[ENT_HASHMAX];
111
112static uint32_t 112static uint32_t
113idtoname_hash(struct ent *ent) 113idtoname_hash(struct ent *ent)
114{ 114{
@@ -183,13 +183,13 @@ warn_no_idmapd(struct cache_detail *detail, int has_died)
183 183
184 184
185static int idtoname_parse(struct cache_detail *, char *, int); 185static int idtoname_parse(struct cache_detail *, char *, int);
186static struct ent *idtoname_lookup(struct ent *); 186static struct ent *idtoname_lookup(struct cache_detail *, struct ent *);
187static struct ent *idtoname_update(struct ent *, struct ent *); 187static struct ent *idtoname_update(struct cache_detail *, struct ent *,
188 struct ent *);
188 189
189static struct cache_detail idtoname_cache = { 190static struct cache_detail idtoname_cache_template = {
190 .owner = THIS_MODULE, 191 .owner = THIS_MODULE,
191 .hash_size = ENT_HASHMAX, 192 .hash_size = ENT_HASHMAX,
192 .hash_table = idtoname_table,
193 .name = "nfs4.idtoname", 193 .name = "nfs4.idtoname",
194 .cache_put = ent_put, 194 .cache_put = ent_put,
195 .cache_upcall = idtoname_upcall, 195 .cache_upcall = idtoname_upcall,
@@ -244,7 +244,7 @@ idtoname_parse(struct cache_detail *cd, char *buf, int buflen)
244 goto out; 244 goto out;
245 245
246 error = -ENOMEM; 246 error = -ENOMEM;
247 res = idtoname_lookup(&ent); 247 res = idtoname_lookup(cd, &ent);
248 if (!res) 248 if (!res)
249 goto out; 249 goto out;
250 250
@@ -260,11 +260,11 @@ idtoname_parse(struct cache_detail *cd, char *buf, int buflen)
260 else 260 else
261 memcpy(ent.name, buf1, sizeof(ent.name)); 261 memcpy(ent.name, buf1, sizeof(ent.name));
262 error = -ENOMEM; 262 error = -ENOMEM;
263 res = idtoname_update(&ent, res); 263 res = idtoname_update(cd, &ent, res);
264 if (res == NULL) 264 if (res == NULL)
265 goto out; 265 goto out;
266 266
267 cache_put(&res->h, &idtoname_cache); 267 cache_put(&res->h, cd);
268 268
269 error = 0; 269 error = 0;
270out: 270out:
@@ -275,10 +275,9 @@ out:
275 275
276 276
277static struct ent * 277static struct ent *
278idtoname_lookup(struct ent *item) 278idtoname_lookup(struct cache_detail *cd, struct ent *item)
279{ 279{
280 struct cache_head *ch = sunrpc_cache_lookup(&idtoname_cache, 280 struct cache_head *ch = sunrpc_cache_lookup(cd, &item->h,
281 &item->h,
282 idtoname_hash(item)); 281 idtoname_hash(item));
283 if (ch) 282 if (ch)
284 return container_of(ch, struct ent, h); 283 return container_of(ch, struct ent, h);
@@ -287,10 +286,9 @@ idtoname_lookup(struct ent *item)
287} 286}
288 287
289static struct ent * 288static struct ent *
290idtoname_update(struct ent *new, struct ent *old) 289idtoname_update(struct cache_detail *cd, struct ent *new, struct ent *old)
291{ 290{
292 struct cache_head *ch = sunrpc_cache_update(&idtoname_cache, 291 struct cache_head *ch = sunrpc_cache_update(cd, &new->h, &old->h,
293 &new->h, &old->h,
294 idtoname_hash(new)); 292 idtoname_hash(new));
295 if (ch) 293 if (ch)
296 return container_of(ch, struct ent, h); 294 return container_of(ch, struct ent, h);
@@ -303,8 +301,6 @@ idtoname_update(struct ent *new, struct ent *old)
303 * Name -> ID cache 301 * Name -> ID cache
304 */ 302 */
305 303
306static struct cache_head *nametoid_table[ENT_HASHMAX];
307
308static inline int 304static inline int
309nametoid_hash(struct ent *ent) 305nametoid_hash(struct ent *ent)
310{ 306{
@@ -359,14 +355,14 @@ nametoid_show(struct seq_file *m, struct cache_detail *cd, struct cache_head *h)
359 return 0; 355 return 0;
360} 356}
361 357
362static struct ent *nametoid_lookup(struct ent *); 358static struct ent *nametoid_lookup(struct cache_detail *, struct ent *);
363static struct ent *nametoid_update(struct ent *, struct ent *); 359static struct ent *nametoid_update(struct cache_detail *, struct ent *,
360 struct ent *);
364static int nametoid_parse(struct cache_detail *, char *, int); 361static int nametoid_parse(struct cache_detail *, char *, int);
365 362
366static struct cache_detail nametoid_cache = { 363static struct cache_detail nametoid_cache_template = {
367 .owner = THIS_MODULE, 364 .owner = THIS_MODULE,
368 .hash_size = ENT_HASHMAX, 365 .hash_size = ENT_HASHMAX,
369 .hash_table = nametoid_table,
370 .name = "nfs4.nametoid", 366 .name = "nfs4.nametoid",
371 .cache_put = ent_put, 367 .cache_put = ent_put,
372 .cache_upcall = nametoid_upcall, 368 .cache_upcall = nametoid_upcall,
@@ -426,14 +422,14 @@ nametoid_parse(struct cache_detail *cd, char *buf, int buflen)
426 set_bit(CACHE_NEGATIVE, &ent.h.flags); 422 set_bit(CACHE_NEGATIVE, &ent.h.flags);
427 423
428 error = -ENOMEM; 424 error = -ENOMEM;
429 res = nametoid_lookup(&ent); 425 res = nametoid_lookup(cd, &ent);
430 if (res == NULL) 426 if (res == NULL)
431 goto out; 427 goto out;
432 res = nametoid_update(&ent, res); 428 res = nametoid_update(cd, &ent, res);
433 if (res == NULL) 429 if (res == NULL)
434 goto out; 430 goto out;
435 431
436 cache_put(&res->h, &nametoid_cache); 432 cache_put(&res->h, cd);
437 error = 0; 433 error = 0;
438out: 434out:
439 kfree(buf1); 435 kfree(buf1);
@@ -443,10 +439,9 @@ out:
443 439
444 440
445static struct ent * 441static struct ent *
446nametoid_lookup(struct ent *item) 442nametoid_lookup(struct cache_detail *cd, struct ent *item)
447{ 443{
448 struct cache_head *ch = sunrpc_cache_lookup(&nametoid_cache, 444 struct cache_head *ch = sunrpc_cache_lookup(cd, &item->h,
449 &item->h,
450 nametoid_hash(item)); 445 nametoid_hash(item));
451 if (ch) 446 if (ch)
452 return container_of(ch, struct ent, h); 447 return container_of(ch, struct ent, h);
@@ -455,10 +450,9 @@ nametoid_lookup(struct ent *item)
455} 450}
456 451
457static struct ent * 452static struct ent *
458nametoid_update(struct ent *new, struct ent *old) 453nametoid_update(struct cache_detail *cd, struct ent *new, struct ent *old)
459{ 454{
460 struct cache_head *ch = sunrpc_cache_update(&nametoid_cache, 455 struct cache_head *ch = sunrpc_cache_update(cd, &new->h, &old->h,
461 &new->h, &old->h,
462 nametoid_hash(new)); 456 nametoid_hash(new));
463 if (ch) 457 if (ch)
464 return container_of(ch, struct ent, h); 458 return container_of(ch, struct ent, h);
@@ -471,34 +465,55 @@ nametoid_update(struct ent *new, struct ent *old)
471 */ 465 */
472 466
473int 467int
474nfsd_idmap_init(void) 468nfsd_idmap_init(struct net *net)
475{ 469{
476 int rv; 470 int rv;
471 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
477 472
478 rv = cache_register_net(&idtoname_cache, &init_net); 473 nn->idtoname_cache = cache_create_net(&idtoname_cache_template, net);
474 if (IS_ERR(nn->idtoname_cache))
475 return PTR_ERR(nn->idtoname_cache);
476 rv = cache_register_net(nn->idtoname_cache, net);
479 if (rv) 477 if (rv)
480 return rv; 478 goto destroy_idtoname_cache;
481 rv = cache_register_net(&nametoid_cache, &init_net); 479 nn->nametoid_cache = cache_create_net(&nametoid_cache_template, net);
480 if (IS_ERR(nn->nametoid_cache)) {
481 rv = PTR_ERR(nn->idtoname_cache);
482 goto unregister_idtoname_cache;
483 }
484 rv = cache_register_net(nn->nametoid_cache, net);
482 if (rv) 485 if (rv)
483 cache_unregister_net(&idtoname_cache, &init_net); 486 goto destroy_nametoid_cache;
487 return 0;
488
489destroy_nametoid_cache:
490 cache_destroy_net(nn->nametoid_cache, net);
491unregister_idtoname_cache:
492 cache_unregister_net(nn->idtoname_cache, net);
493destroy_idtoname_cache:
494 cache_destroy_net(nn->idtoname_cache, net);
484 return rv; 495 return rv;
485} 496}
486 497
487void 498void
488nfsd_idmap_shutdown(void) 499nfsd_idmap_shutdown(struct net *net)
489{ 500{
490 cache_unregister_net(&idtoname_cache, &init_net); 501 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
491 cache_unregister_net(&nametoid_cache, &init_net); 502
503 cache_unregister_net(nn->idtoname_cache, net);
504 cache_unregister_net(nn->nametoid_cache, net);
505 cache_destroy_net(nn->idtoname_cache, net);
506 cache_destroy_net(nn->nametoid_cache, net);
492} 507}
493 508
494static int 509static int
495idmap_lookup(struct svc_rqst *rqstp, 510idmap_lookup(struct svc_rqst *rqstp,
496 struct ent *(*lookup_fn)(struct ent *), struct ent *key, 511 struct ent *(*lookup_fn)(struct cache_detail *, struct ent *),
497 struct cache_detail *detail, struct ent **item) 512 struct ent *key, struct cache_detail *detail, struct ent **item)
498{ 513{
499 int ret; 514 int ret;
500 515
501 *item = lookup_fn(key); 516 *item = lookup_fn(detail, key);
502 if (!*item) 517 if (!*item)
503 return -ENOMEM; 518 return -ENOMEM;
504 retry: 519 retry:
@@ -506,7 +521,7 @@ idmap_lookup(struct svc_rqst *rqstp,
506 521
507 if (ret == -ETIMEDOUT) { 522 if (ret == -ETIMEDOUT) {
508 struct ent *prev_item = *item; 523 struct ent *prev_item = *item;
509 *item = lookup_fn(key); 524 *item = lookup_fn(detail, key);
510 if (*item != prev_item) 525 if (*item != prev_item)
511 goto retry; 526 goto retry;
512 cache_put(&(*item)->h, detail); 527 cache_put(&(*item)->h, detail);
@@ -531,19 +546,20 @@ idmap_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen
531 .type = type, 546 .type = type,
532 }; 547 };
533 int ret; 548 int ret;
549 struct nfsd_net *nn = net_generic(rqstp->rq_xprt->xpt_net, nfsd_net_id);
534 550
535 if (namelen + 1 > sizeof(key.name)) 551 if (namelen + 1 > sizeof(key.name))
536 return nfserr_badowner; 552 return nfserr_badowner;
537 memcpy(key.name, name, namelen); 553 memcpy(key.name, name, namelen);
538 key.name[namelen] = '\0'; 554 key.name[namelen] = '\0';
539 strlcpy(key.authname, rqst_authname(rqstp), sizeof(key.authname)); 555 strlcpy(key.authname, rqst_authname(rqstp), sizeof(key.authname));
540 ret = idmap_lookup(rqstp, nametoid_lookup, &key, &nametoid_cache, &item); 556 ret = idmap_lookup(rqstp, nametoid_lookup, &key, nn->nametoid_cache, &item);
541 if (ret == -ENOENT) 557 if (ret == -ENOENT)
542 return nfserr_badowner; 558 return nfserr_badowner;
543 if (ret) 559 if (ret)
544 return nfserrno(ret); 560 return nfserrno(ret);
545 *id = item->id; 561 *id = item->id;
546 cache_put(&item->h, &nametoid_cache); 562 cache_put(&item->h, nn->nametoid_cache);
547 return 0; 563 return 0;
548} 564}
549 565
@@ -555,9 +571,10 @@ idmap_id_to_name(struct svc_rqst *rqstp, int type, uid_t id, char *name)
555 .type = type, 571 .type = type,
556 }; 572 };
557 int ret; 573 int ret;
574 struct nfsd_net *nn = net_generic(rqstp->rq_xprt->xpt_net, nfsd_net_id);
558 575
559 strlcpy(key.authname, rqst_authname(rqstp), sizeof(key.authname)); 576 strlcpy(key.authname, rqst_authname(rqstp), sizeof(key.authname));
560 ret = idmap_lookup(rqstp, idtoname_lookup, &key, &idtoname_cache, &item); 577 ret = idmap_lookup(rqstp, idtoname_lookup, &key, nn->idtoname_cache, &item);
561 if (ret == -ENOENT) 578 if (ret == -ENOENT)
562 return sprintf(name, "%u", id); 579 return sprintf(name, "%u", id);
563 if (ret) 580 if (ret)
@@ -565,7 +582,7 @@ idmap_id_to_name(struct svc_rqst *rqstp, int type, uid_t id, char *name)
565 ret = strlen(item->name); 582 ret = strlen(item->name);
566 BUG_ON(ret > IDMAP_NAMESZ); 583 BUG_ON(ret > IDMAP_NAMESZ);
567 memcpy(name, item->name, ret); 584 memcpy(name, item->name, ret);
568 cache_put(&item->h, &idtoname_cache); 585 cache_put(&item->h, nn->idtoname_cache);
569 return ret; 586 return ret;
570} 587}
571 588
@@ -588,7 +605,7 @@ numeric_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namel
588static __be32 605static __be32
589do_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, uid_t *id) 606do_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, uid_t *id)
590{ 607{
591 if (nfs4_disable_idmapping && rqstp->rq_flavor < RPC_AUTH_GSS) 608 if (nfs4_disable_idmapping && rqstp->rq_cred.cr_flavor < RPC_AUTH_GSS)
592 if (numeric_name_to_id(rqstp, type, name, namelen, id)) 609 if (numeric_name_to_id(rqstp, type, name, namelen, id))
593 return 0; 610 return 0;
594 /* 611 /*
@@ -601,7 +618,7 @@ do_name_to_id(struct svc_rqst *rqstp, int type, const char *name, u32 namelen, u
601static int 618static int
602do_id_to_name(struct svc_rqst *rqstp, int type, uid_t id, char *name) 619do_id_to_name(struct svc_rqst *rqstp, int type, uid_t id, char *name)
603{ 620{
604 if (nfs4_disable_idmapping && rqstp->rq_flavor < RPC_AUTH_GSS) 621 if (nfs4_disable_idmapping && rqstp->rq_cred.cr_flavor < RPC_AUTH_GSS)
605 return sprintf(name, "%u", id); 622 return sprintf(name, "%u", id);
606 return idmap_id_to_name(rqstp, type, id, name); 623 return idmap_id_to_name(rqstp, type, id, name);
607} 624}
diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
index ed3f9206a0ee..5ff0b7b9fc08 100644
--- a/fs/nfsd/nfs4recover.c
+++ b/fs/nfsd/nfs4recover.c
@@ -570,7 +570,7 @@ static ssize_t
570cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) 570cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
571{ 571{
572 struct cld_upcall *tmp, *cup; 572 struct cld_upcall *tmp, *cup;
573 struct cld_msg *cmsg = (struct cld_msg *)src; 573 struct cld_msg __user *cmsg = (struct cld_msg __user *)src;
574 uint32_t xid; 574 uint32_t xid;
575 struct nfsd_net *nn = net_generic(filp->f_dentry->d_sb->s_fs_info, 575 struct nfsd_net *nn = net_generic(filp->f_dentry->d_sb->s_fs_info,
576 nfsd_net_id); 576 nfsd_net_id);
@@ -1029,7 +1029,7 @@ rpc_pipefs_event(struct notifier_block *nb, unsigned long event, void *ptr)
1029 return ret; 1029 return ret;
1030} 1030}
1031 1031
1032struct notifier_block nfsd4_cld_block = { 1032static struct notifier_block nfsd4_cld_block = {
1033 .notifier_call = rpc_pipefs_event, 1033 .notifier_call = rpc_pipefs_event,
1034}; 1034};
1035 1035
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 7f71c69cdcdf..8fdc9ec5c5d3 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -42,6 +42,7 @@
42#include <linux/sunrpc/clnt.h> 42#include <linux/sunrpc/clnt.h>
43#include "xdr4.h" 43#include "xdr4.h"
44#include "vfs.h" 44#include "vfs.h"
45#include "current_stateid.h"
45 46
46#define NFSDDBG_FACILITY NFSDDBG_PROC 47#define NFSDDBG_FACILITY NFSDDBG_PROC
47 48
@@ -447,37 +448,69 @@ static struct list_head close_lru;
447 * 448 *
448 * which we should reject. 449 * which we should reject.
449 */ 450 */
450static void 451static unsigned int
451set_access(unsigned int *access, unsigned long bmap) { 452bmap_to_share_mode(unsigned long bmap) {
452 int i; 453 int i;
454 unsigned int access = 0;
453 455
454 *access = 0;
455 for (i = 1; i < 4; i++) { 456 for (i = 1; i < 4; i++) {
456 if (test_bit(i, &bmap)) 457 if (test_bit(i, &bmap))
457 *access |= i; 458 access |= i;
458 }
459}
460
461static void
462set_deny(unsigned int *deny, unsigned long bmap) {
463 int i;
464
465 *deny = 0;
466 for (i = 0; i < 4; i++) {
467 if (test_bit(i, &bmap))
468 *deny |= i ;
469 } 459 }
460 return access;
470} 461}
471 462
472static int 463static bool
473test_share(struct nfs4_ol_stateid *stp, struct nfsd4_open *open) { 464test_share(struct nfs4_ol_stateid *stp, struct nfsd4_open *open) {
474 unsigned int access, deny; 465 unsigned int access, deny;
475 466
476 set_access(&access, stp->st_access_bmap); 467 access = bmap_to_share_mode(stp->st_access_bmap);
477 set_deny(&deny, stp->st_deny_bmap); 468 deny = bmap_to_share_mode(stp->st_deny_bmap);
478 if ((access & open->op_share_deny) || (deny & open->op_share_access)) 469 if ((access & open->op_share_deny) || (deny & open->op_share_access))
479 return 0; 470 return false;
480 return 1; 471 return true;
472}
473
474/* set share access for a given stateid */
475static inline void
476set_access(u32 access, struct nfs4_ol_stateid *stp)
477{
478 __set_bit(access, &stp->st_access_bmap);
479}
480
481/* clear share access for a given stateid */
482static inline void
483clear_access(u32 access, struct nfs4_ol_stateid *stp)
484{
485 __clear_bit(access, &stp->st_access_bmap);
486}
487
488/* test whether a given stateid has access */
489static inline bool
490test_access(u32 access, struct nfs4_ol_stateid *stp)
491{
492 return test_bit(access, &stp->st_access_bmap);
493}
494
495/* set share deny for a given stateid */
496static inline void
497set_deny(u32 access, struct nfs4_ol_stateid *stp)
498{
499 __set_bit(access, &stp->st_deny_bmap);
500}
501
502/* clear share deny for a given stateid */
503static inline void
504clear_deny(u32 access, struct nfs4_ol_stateid *stp)
505{
506 __clear_bit(access, &stp->st_deny_bmap);
507}
508
509/* test whether a given stateid is denying specific access */
510static inline bool
511test_deny(u32 access, struct nfs4_ol_stateid *stp)
512{
513 return test_bit(access, &stp->st_deny_bmap);
481} 514}
482 515
483static int nfs4_access_to_omode(u32 access) 516static int nfs4_access_to_omode(u32 access)
@@ -493,6 +526,20 @@ static int nfs4_access_to_omode(u32 access)
493 BUG(); 526 BUG();
494} 527}
495 528
529/* release all access and file references for a given stateid */
530static void
531release_all_access(struct nfs4_ol_stateid *stp)
532{
533 int i;
534
535 for (i = 1; i < 4; i++) {
536 if (test_access(i, stp))
537 nfs4_file_put_access(stp->st_file,
538 nfs4_access_to_omode(i));
539 clear_access(i, stp);
540 }
541}
542
496static void unhash_generic_stateid(struct nfs4_ol_stateid *stp) 543static void unhash_generic_stateid(struct nfs4_ol_stateid *stp)
497{ 544{
498 list_del(&stp->st_perfile); 545 list_del(&stp->st_perfile);
@@ -501,16 +548,7 @@ static void unhash_generic_stateid(struct nfs4_ol_stateid *stp)
501 548
502static void close_generic_stateid(struct nfs4_ol_stateid *stp) 549static void close_generic_stateid(struct nfs4_ol_stateid *stp)
503{ 550{
504 int i; 551 release_all_access(stp);
505
506 if (stp->st_access_bmap) {
507 for (i = 1; i < 4; i++) {
508 if (test_bit(i, &stp->st_access_bmap))
509 nfs4_file_put_access(stp->st_file,
510 nfs4_access_to_omode(i));
511 __clear_bit(i, &stp->st_access_bmap);
512 }
513 }
514 put_nfs4_file(stp->st_file); 552 put_nfs4_file(stp->st_file);
515 stp->st_file = NULL; 553 stp->st_file = NULL;
516} 554}
@@ -885,7 +923,7 @@ static struct nfsd4_session *alloc_init_session(struct svc_rqst *rqstp, struct n
885 struct nfsd4_session *new; 923 struct nfsd4_session *new;
886 struct nfsd4_channel_attrs *fchan = &cses->fore_channel; 924 struct nfsd4_channel_attrs *fchan = &cses->fore_channel;
887 int numslots, slotsize; 925 int numslots, slotsize;
888 int status; 926 __be32 status;
889 int idx; 927 int idx;
890 928
891 /* 929 /*
@@ -984,7 +1022,8 @@ static inline void
984renew_client_locked(struct nfs4_client *clp) 1022renew_client_locked(struct nfs4_client *clp)
985{ 1023{
986 if (is_client_expired(clp)) { 1024 if (is_client_expired(clp)) {
987 dprintk("%s: client (clientid %08x/%08x) already expired\n", 1025 WARN_ON(1);
1026 printk("%s: client (clientid %08x/%08x) already expired\n",
988 __func__, 1027 __func__,
989 clp->cl_clientid.cl_boot, 1028 clp->cl_clientid.cl_boot,
990 clp->cl_clientid.cl_id); 1029 clp->cl_clientid.cl_id);
@@ -1049,9 +1088,7 @@ free_client(struct nfs4_client *clp)
1049 list_del(&ses->se_perclnt); 1088 list_del(&ses->se_perclnt);
1050 nfsd4_put_session_locked(ses); 1089 nfsd4_put_session_locked(ses);
1051 } 1090 }
1052 if (clp->cl_cred.cr_group_info) 1091 free_svc_cred(&clp->cl_cred);
1053 put_group_info(clp->cl_cred.cr_group_info);
1054 kfree(clp->cl_principal);
1055 kfree(clp->cl_name.data); 1092 kfree(clp->cl_name.data);
1056 kfree(clp); 1093 kfree(clp);
1057} 1094}
@@ -1132,12 +1169,21 @@ static void copy_clid(struct nfs4_client *target, struct nfs4_client *source)
1132 target->cl_clientid.cl_id = source->cl_clientid.cl_id; 1169 target->cl_clientid.cl_id = source->cl_clientid.cl_id;
1133} 1170}
1134 1171
1135static void copy_cred(struct svc_cred *target, struct svc_cred *source) 1172static int copy_cred(struct svc_cred *target, struct svc_cred *source)
1136{ 1173{
1174 if (source->cr_principal) {
1175 target->cr_principal =
1176 kstrdup(source->cr_principal, GFP_KERNEL);
1177 if (target->cr_principal == NULL)
1178 return -ENOMEM;
1179 } else
1180 target->cr_principal = NULL;
1181 target->cr_flavor = source->cr_flavor;
1137 target->cr_uid = source->cr_uid; 1182 target->cr_uid = source->cr_uid;
1138 target->cr_gid = source->cr_gid; 1183 target->cr_gid = source->cr_gid;
1139 target->cr_group_info = source->cr_group_info; 1184 target->cr_group_info = source->cr_group_info;
1140 get_group_info(target->cr_group_info); 1185 get_group_info(target->cr_group_info);
1186 return 0;
1141} 1187}
1142 1188
1143static int same_name(const char *n1, const char *n2) 1189static int same_name(const char *n1, const char *n2)
@@ -1157,11 +1203,31 @@ same_clid(clientid_t *cl1, clientid_t *cl2)
1157 return (cl1->cl_boot == cl2->cl_boot) && (cl1->cl_id == cl2->cl_id); 1203 return (cl1->cl_boot == cl2->cl_boot) && (cl1->cl_id == cl2->cl_id);
1158} 1204}
1159 1205
1160/* XXX what about NGROUP */ 1206static bool groups_equal(struct group_info *g1, struct group_info *g2)
1207{
1208 int i;
1209
1210 if (g1->ngroups != g2->ngroups)
1211 return false;
1212 for (i=0; i<g1->ngroups; i++)
1213 if (GROUP_AT(g1, i) != GROUP_AT(g2, i))
1214 return false;
1215 return true;
1216}
1217
1161static int 1218static int
1162same_creds(struct svc_cred *cr1, struct svc_cred *cr2) 1219same_creds(struct svc_cred *cr1, struct svc_cred *cr2)
1163{ 1220{
1164 return cr1->cr_uid == cr2->cr_uid; 1221 if ((cr1->cr_flavor != cr2->cr_flavor)
1222 || (cr1->cr_uid != cr2->cr_uid)
1223 || (cr1->cr_gid != cr2->cr_gid)
1224 || !groups_equal(cr1->cr_group_info, cr2->cr_group_info))
1225 return false;
1226 if (cr1->cr_principal == cr2->cr_principal)
1227 return true;
1228 if (!cr1->cr_principal || !cr2->cr_principal)
1229 return false;
1230 return 0 == strcmp(cr1->cr_principal, cr1->cr_principal);
1165} 1231}
1166 1232
1167static void gen_clid(struct nfs4_client *clp) 1233static void gen_clid(struct nfs4_client *clp)
@@ -1204,25 +1270,20 @@ static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir,
1204{ 1270{
1205 struct nfs4_client *clp; 1271 struct nfs4_client *clp;
1206 struct sockaddr *sa = svc_addr(rqstp); 1272 struct sockaddr *sa = svc_addr(rqstp);
1207 char *princ; 1273 int ret;
1208 1274
1209 clp = alloc_client(name); 1275 clp = alloc_client(name);
1210 if (clp == NULL) 1276 if (clp == NULL)
1211 return NULL; 1277 return NULL;
1212 1278
1213 INIT_LIST_HEAD(&clp->cl_sessions); 1279 INIT_LIST_HEAD(&clp->cl_sessions);
1214 1280 ret = copy_cred(&clp->cl_cred, &rqstp->rq_cred);
1215 princ = svc_gss_principal(rqstp); 1281 if (ret) {
1216 if (princ) { 1282 spin_lock(&client_lock);
1217 clp->cl_principal = kstrdup(princ, GFP_KERNEL); 1283 free_client(clp);
1218 if (clp->cl_principal == NULL) { 1284 spin_unlock(&client_lock);
1219 spin_lock(&client_lock); 1285 return NULL;
1220 free_client(clp);
1221 spin_unlock(&client_lock);
1222 return NULL;
1223 }
1224 } 1286 }
1225
1226 idr_init(&clp->cl_stateids); 1287 idr_init(&clp->cl_stateids);
1227 memcpy(clp->cl_recdir, recdir, HEXDIR_LEN); 1288 memcpy(clp->cl_recdir, recdir, HEXDIR_LEN);
1228 atomic_set(&clp->cl_refcount, 0); 1289 atomic_set(&clp->cl_refcount, 0);
@@ -1240,8 +1301,6 @@ static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir,
1240 rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table"); 1301 rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
1241 copy_verf(clp, verf); 1302 copy_verf(clp, verf);
1242 rpc_copy_addr((struct sockaddr *) &clp->cl_addr, sa); 1303 rpc_copy_addr((struct sockaddr *) &clp->cl_addr, sa);
1243 clp->cl_flavor = rqstp->rq_flavor;
1244 copy_cred(&clp->cl_cred, &rqstp->rq_cred);
1245 gen_confirm(clp); 1304 gen_confirm(clp);
1246 clp->cl_cb_session = NULL; 1305 clp->cl_cb_session = NULL;
1247 return clp; 1306 return clp;
@@ -1470,18 +1529,32 @@ nfsd4_set_ex_flags(struct nfs4_client *new, struct nfsd4_exchange_id *clid)
1470 clid->flags = new->cl_exchange_flags; 1529 clid->flags = new->cl_exchange_flags;
1471} 1530}
1472 1531
1532static bool client_has_state(struct nfs4_client *clp)
1533{
1534 /*
1535 * Note clp->cl_openowners check isn't quite right: there's no
1536 * need to count owners without stateid's.
1537 *
1538 * Also note we should probably be using this in 4.0 case too.
1539 */
1540 return !list_empty(&clp->cl_openowners)
1541 || !list_empty(&clp->cl_delegations)
1542 || !list_empty(&clp->cl_sessions);
1543}
1544
1473__be32 1545__be32
1474nfsd4_exchange_id(struct svc_rqst *rqstp, 1546nfsd4_exchange_id(struct svc_rqst *rqstp,
1475 struct nfsd4_compound_state *cstate, 1547 struct nfsd4_compound_state *cstate,
1476 struct nfsd4_exchange_id *exid) 1548 struct nfsd4_exchange_id *exid)
1477{ 1549{
1478 struct nfs4_client *unconf, *conf, *new; 1550 struct nfs4_client *unconf, *conf, *new;
1479 int status; 1551 __be32 status;
1480 unsigned int strhashval; 1552 unsigned int strhashval;
1481 char dname[HEXDIR_LEN]; 1553 char dname[HEXDIR_LEN];
1482 char addr_str[INET6_ADDRSTRLEN]; 1554 char addr_str[INET6_ADDRSTRLEN];
1483 nfs4_verifier verf = exid->verifier; 1555 nfs4_verifier verf = exid->verifier;
1484 struct sockaddr *sa = svc_addr(rqstp); 1556 struct sockaddr *sa = svc_addr(rqstp);
1557 bool update = exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A;
1485 1558
1486 rpc_ntop(sa, addr_str, sizeof(addr_str)); 1559 rpc_ntop(sa, addr_str, sizeof(addr_str));
1487 dprintk("%s rqstp=%p exid=%p clname.len=%u clname.data=%p " 1560 dprintk("%s rqstp=%p exid=%p clname.len=%u clname.data=%p "
@@ -1507,71 +1580,63 @@ nfsd4_exchange_id(struct svc_rqst *rqstp,
1507 status = nfs4_make_rec_clidname(dname, &exid->clname); 1580 status = nfs4_make_rec_clidname(dname, &exid->clname);
1508 1581
1509 if (status) 1582 if (status)
1510 goto error; 1583 return status;
1511 1584
1512 strhashval = clientstr_hashval(dname); 1585 strhashval = clientstr_hashval(dname);
1513 1586
1587 /* Cases below refer to rfc 5661 section 18.35.4: */
1514 nfs4_lock_state(); 1588 nfs4_lock_state();
1515 status = nfs_ok;
1516
1517 conf = find_confirmed_client_by_str(dname, strhashval); 1589 conf = find_confirmed_client_by_str(dname, strhashval);
1518 if (conf) { 1590 if (conf) {
1519 if (!clp_used_exchangeid(conf)) { 1591 bool creds_match = same_creds(&conf->cl_cred, &rqstp->rq_cred);
1520 status = nfserr_clid_inuse; /* XXX: ? */ 1592 bool verfs_match = same_verf(&verf, &conf->cl_verifier);
1521 goto out; 1593
1522 } 1594 if (update) {
1523 if (!same_verf(&verf, &conf->cl_verifier)) { 1595 if (!clp_used_exchangeid(conf)) { /* buggy client */
1524 /* 18.35.4 case 8 */ 1596 status = nfserr_inval;
1525 if (exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) { 1597 goto out;
1598 }
1599 if (!creds_match) { /* case 9 */
1600 status = nfserr_perm;
1601 goto out;
1602 }
1603 if (!verfs_match) { /* case 8 */
1526 status = nfserr_not_same; 1604 status = nfserr_not_same;
1527 goto out; 1605 goto out;
1528 } 1606 }
1529 /* Client reboot: destroy old state */ 1607 /* case 6 */
1530 expire_client(conf); 1608 exid->flags |= EXCHGID4_FLAG_CONFIRMED_R;
1531 goto out_new; 1609 new = conf;
1610 goto out_copy;
1532 } 1611 }
1533 if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) { 1612 if (!creds_match) { /* case 3 */
1534 /* 18.35.4 case 9 */ 1613 if (client_has_state(conf)) {
1535 if (exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) { 1614 status = nfserr_clid_inuse;
1536 status = nfserr_perm;
1537 goto out; 1615 goto out;
1538 } 1616 }
1539 expire_client(conf); 1617 expire_client(conf);
1540 goto out_new; 1618 goto out_new;
1541 } 1619 }
1542 /* 1620 if (verfs_match) { /* case 2 */
1543 * Set bit when the owner id and verifier map to an already 1621 conf->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R;
1544 * confirmed client id (18.35.3). 1622 new = conf;
1545 */ 1623 goto out_copy;
1546 exid->flags |= EXCHGID4_FLAG_CONFIRMED_R; 1624 }
1547 1625 /* case 5, client reboot */
1548 /* 1626 goto out_new;
1549 * Falling into 18.35.4 case 2, possible router replay.
1550 * Leave confirmed record intact and return same result.
1551 */
1552 copy_verf(conf, &verf);
1553 new = conf;
1554 goto out_copy;
1555 } 1627 }
1556 1628
1557 /* 18.35.4 case 7 */ 1629 if (update) { /* case 7 */
1558 if (exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) {
1559 status = nfserr_noent; 1630 status = nfserr_noent;
1560 goto out; 1631 goto out;
1561 } 1632 }
1562 1633
1563 unconf = find_unconfirmed_client_by_str(dname, strhashval); 1634 unconf = find_unconfirmed_client_by_str(dname, strhashval);
1564 if (unconf) { 1635 if (unconf) /* case 4, possible retry or client restart */
1565 /*
1566 * Possible retry or client restart. Per 18.35.4 case 4,
1567 * a new unconfirmed record should be generated regardless
1568 * of whether any properties have changed.
1569 */
1570 expire_client(unconf); 1636 expire_client(unconf);
1571 }
1572 1637
1638 /* case 1 (normal case) */
1573out_new: 1639out_new:
1574 /* Normal case */
1575 new = create_client(exid->clname, dname, rqstp, &verf); 1640 new = create_client(exid->clname, dname, rqstp, &verf);
1576 if (new == NULL) { 1641 if (new == NULL) {
1577 status = nfserr_jukebox; 1642 status = nfserr_jukebox;
@@ -1584,7 +1649,7 @@ out_copy:
1584 exid->clientid.cl_boot = new->cl_clientid.cl_boot; 1649 exid->clientid.cl_boot = new->cl_clientid.cl_boot;
1585 exid->clientid.cl_id = new->cl_clientid.cl_id; 1650 exid->clientid.cl_id = new->cl_clientid.cl_id;
1586 1651
1587 exid->seqid = 1; 1652 exid->seqid = new->cl_cs_slot.sl_seqid + 1;
1588 nfsd4_set_ex_flags(new, exid); 1653 nfsd4_set_ex_flags(new, exid);
1589 1654
1590 dprintk("nfsd4_exchange_id seqid %d flags %x\n", 1655 dprintk("nfsd4_exchange_id seqid %d flags %x\n",
@@ -1593,12 +1658,10 @@ out_copy:
1593 1658
1594out: 1659out:
1595 nfs4_unlock_state(); 1660 nfs4_unlock_state();
1596error:
1597 dprintk("nfsd4_exchange_id returns %d\n", ntohl(status));
1598 return status; 1661 return status;
1599} 1662}
1600 1663
1601static int 1664static __be32
1602check_slot_seqid(u32 seqid, u32 slot_seqid, int slot_inuse) 1665check_slot_seqid(u32 seqid, u32 slot_seqid, int slot_inuse)
1603{ 1666{
1604 dprintk("%s enter. seqid %d slot_seqid %d\n", __func__, seqid, 1667 dprintk("%s enter. seqid %d slot_seqid %d\n", __func__, seqid,
@@ -1626,7 +1689,7 @@ check_slot_seqid(u32 seqid, u32 slot_seqid, int slot_inuse)
1626 */ 1689 */
1627static void 1690static void
1628nfsd4_cache_create_session(struct nfsd4_create_session *cr_ses, 1691nfsd4_cache_create_session(struct nfsd4_create_session *cr_ses,
1629 struct nfsd4_clid_slot *slot, int nfserr) 1692 struct nfsd4_clid_slot *slot, __be32 nfserr)
1630{ 1693{
1631 slot->sl_status = nfserr; 1694 slot->sl_status = nfserr;
1632 memcpy(&slot->sl_cr_ses, cr_ses, sizeof(*cr_ses)); 1695 memcpy(&slot->sl_cr_ses, cr_ses, sizeof(*cr_ses));
@@ -1657,7 +1720,7 @@ nfsd4_replay_create_session(struct nfsd4_create_session *cr_ses,
1657 /* seqid, slotID, slotID, slotID, status */ \ 1720 /* seqid, slotID, slotID, slotID, status */ \
1658 5 ) * sizeof(__be32)) 1721 5 ) * sizeof(__be32))
1659 1722
1660static __be32 check_forechannel_attrs(struct nfsd4_channel_attrs fchannel) 1723static bool check_forechannel_attrs(struct nfsd4_channel_attrs fchannel)
1661{ 1724{
1662 return fchannel.maxreq_sz < NFSD_MIN_REQ_HDR_SEQ_SZ 1725 return fchannel.maxreq_sz < NFSD_MIN_REQ_HDR_SEQ_SZ
1663 || fchannel.maxresp_sz < NFSD_MIN_RESP_HDR_SEQ_SZ; 1726 || fchannel.maxresp_sz < NFSD_MIN_RESP_HDR_SEQ_SZ;
@@ -1673,7 +1736,7 @@ nfsd4_create_session(struct svc_rqst *rqstp,
1673 struct nfsd4_session *new; 1736 struct nfsd4_session *new;
1674 struct nfsd4_clid_slot *cs_slot = NULL; 1737 struct nfsd4_clid_slot *cs_slot = NULL;
1675 bool confirm_me = false; 1738 bool confirm_me = false;
1676 int status = 0; 1739 __be32 status = 0;
1677 1740
1678 if (cr_ses->flags & ~SESSION4_FLAG_MASK_A) 1741 if (cr_ses->flags & ~SESSION4_FLAG_MASK_A)
1679 return nfserr_inval; 1742 return nfserr_inval;
@@ -1686,16 +1749,10 @@ nfsd4_create_session(struct svc_rqst *rqstp,
1686 cs_slot = &conf->cl_cs_slot; 1749 cs_slot = &conf->cl_cs_slot;
1687 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); 1750 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0);
1688 if (status == nfserr_replay_cache) { 1751 if (status == nfserr_replay_cache) {
1689 dprintk("Got a create_session replay! seqid= %d\n",
1690 cs_slot->sl_seqid);
1691 /* Return the cached reply status */
1692 status = nfsd4_replay_create_session(cr_ses, cs_slot); 1752 status = nfsd4_replay_create_session(cr_ses, cs_slot);
1693 goto out; 1753 goto out;
1694 } else if (cr_ses->seqid != cs_slot->sl_seqid + 1) { 1754 } else if (cr_ses->seqid != cs_slot->sl_seqid + 1) {
1695 status = nfserr_seq_misordered; 1755 status = nfserr_seq_misordered;
1696 dprintk("Sequence misordered!\n");
1697 dprintk("Expected seqid= %d but got seqid= %d\n",
1698 cs_slot->sl_seqid, cr_ses->seqid);
1699 goto out; 1756 goto out;
1700 } 1757 }
1701 } else if (unconf) { 1758 } else if (unconf) {
@@ -1704,7 +1761,6 @@ nfsd4_create_session(struct svc_rqst *rqstp,
1704 status = nfserr_clid_inuse; 1761 status = nfserr_clid_inuse;
1705 goto out; 1762 goto out;
1706 } 1763 }
1707
1708 cs_slot = &unconf->cl_cs_slot; 1764 cs_slot = &unconf->cl_cs_slot;
1709 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0); 1765 status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0);
1710 if (status) { 1766 if (status) {
@@ -1712,7 +1768,6 @@ nfsd4_create_session(struct svc_rqst *rqstp,
1712 status = nfserr_seq_misordered; 1768 status = nfserr_seq_misordered;
1713 goto out; 1769 goto out;
1714 } 1770 }
1715
1716 confirm_me = true; 1771 confirm_me = true;
1717 conf = unconf; 1772 conf = unconf;
1718 } else { 1773 } else {
@@ -1749,8 +1804,14 @@ nfsd4_create_session(struct svc_rqst *rqstp,
1749 1804
1750 /* cache solo and embedded create sessions under the state lock */ 1805 /* cache solo and embedded create sessions under the state lock */
1751 nfsd4_cache_create_session(cr_ses, cs_slot, status); 1806 nfsd4_cache_create_session(cr_ses, cs_slot, status);
1752 if (confirm_me) 1807 if (confirm_me) {
1808 unsigned int hash = clientstr_hashval(unconf->cl_recdir);
1809 struct nfs4_client *old =
1810 find_confirmed_client_by_str(conf->cl_recdir, hash);
1811 if (old)
1812 expire_client(old);
1753 move_to_confirmed(conf); 1813 move_to_confirmed(conf);
1814 }
1754out: 1815out:
1755 nfs4_unlock_state(); 1816 nfs4_unlock_state();
1756 dprintk("%s returns %d\n", __func__, ntohl(status)); 1817 dprintk("%s returns %d\n", __func__, ntohl(status));
@@ -1818,7 +1879,7 @@ nfsd4_destroy_session(struct svc_rqst *r,
1818 struct nfsd4_destroy_session *sessionid) 1879 struct nfsd4_destroy_session *sessionid)
1819{ 1880{
1820 struct nfsd4_session *ses; 1881 struct nfsd4_session *ses;
1821 u32 status = nfserr_badsession; 1882 __be32 status = nfserr_badsession;
1822 1883
1823 /* Notes: 1884 /* Notes:
1824 * - The confirmed nfs4_client->cl_sessionid holds destroyed sessinid 1885 * - The confirmed nfs4_client->cl_sessionid holds destroyed sessinid
@@ -1914,7 +1975,7 @@ nfsd4_sequence(struct svc_rqst *rqstp,
1914 struct nfsd4_session *session; 1975 struct nfsd4_session *session;
1915 struct nfsd4_slot *slot; 1976 struct nfsd4_slot *slot;
1916 struct nfsd4_conn *conn; 1977 struct nfsd4_conn *conn;
1917 int status; 1978 __be32 status;
1918 1979
1919 if (resp->opcnt != 1) 1980 if (resp->opcnt != 1)
1920 return nfserr_sequence_pos; 1981 return nfserr_sequence_pos;
@@ -2008,18 +2069,11 @@ out:
2008 return status; 2069 return status;
2009} 2070}
2010 2071
2011static inline bool has_resources(struct nfs4_client *clp)
2012{
2013 return !list_empty(&clp->cl_openowners)
2014 || !list_empty(&clp->cl_delegations)
2015 || !list_empty(&clp->cl_sessions);
2016}
2017
2018__be32 2072__be32
2019nfsd4_destroy_clientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_destroy_clientid *dc) 2073nfsd4_destroy_clientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_destroy_clientid *dc)
2020{ 2074{
2021 struct nfs4_client *conf, *unconf, *clp; 2075 struct nfs4_client *conf, *unconf, *clp;
2022 int status = 0; 2076 __be32 status = 0;
2023 2077
2024 nfs4_lock_state(); 2078 nfs4_lock_state();
2025 unconf = find_unconfirmed_client(&dc->clientid); 2079 unconf = find_unconfirmed_client(&dc->clientid);
@@ -2028,7 +2082,7 @@ nfsd4_destroy_clientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *csta
2028 if (conf) { 2082 if (conf) {
2029 clp = conf; 2083 clp = conf;
2030 2084
2031 if (!is_client_expired(conf) && has_resources(conf)) { 2085 if (!is_client_expired(conf) && client_has_state(conf)) {
2032 status = nfserr_clientid_busy; 2086 status = nfserr_clientid_busy;
2033 goto out; 2087 goto out;
2034 } 2088 }
@@ -2055,7 +2109,7 @@ out:
2055__be32 2109__be32
2056nfsd4_reclaim_complete(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_reclaim_complete *rc) 2110nfsd4_reclaim_complete(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_reclaim_complete *rc)
2057{ 2111{
2058 int status = 0; 2112 __be32 status = 0;
2059 2113
2060 if (rc->rca_one_fs) { 2114 if (rc->rca_one_fs) {
2061 if (!cstate->current_fh.fh_dentry) 2115 if (!cstate->current_fh.fh_dentry)
@@ -2106,17 +2160,13 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2106 if (status) 2160 if (status)
2107 return status; 2161 return status;
2108 2162
2109 /*
2110 * XXX The Duplicate Request Cache (DRC) has been checked (??)
2111 * We get here on a DRC miss.
2112 */
2113
2114 strhashval = clientstr_hashval(dname); 2163 strhashval = clientstr_hashval(dname);
2115 2164
2165 /* Cases below refer to rfc 3530 section 14.2.33: */
2116 nfs4_lock_state(); 2166 nfs4_lock_state();
2117 conf = find_confirmed_client_by_str(dname, strhashval); 2167 conf = find_confirmed_client_by_str(dname, strhashval);
2118 if (conf) { 2168 if (conf) {
2119 /* RFC 3530 14.2.33 CASE 0: */ 2169 /* case 0: */
2120 status = nfserr_clid_inuse; 2170 status = nfserr_clid_inuse;
2121 if (clp_used_exchangeid(conf)) 2171 if (clp_used_exchangeid(conf))
2122 goto out; 2172 goto out;
@@ -2129,63 +2179,18 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2129 goto out; 2179 goto out;
2130 } 2180 }
2131 } 2181 }
2132 /*
2133 * section 14.2.33 of RFC 3530 (under the heading "IMPLEMENTATION")
2134 * has a description of SETCLIENTID request processing consisting
2135 * of 5 bullet points, labeled as CASE0 - CASE4 below.
2136 */
2137 unconf = find_unconfirmed_client_by_str(dname, strhashval); 2182 unconf = find_unconfirmed_client_by_str(dname, strhashval);
2183 if (unconf)
2184 expire_client(unconf);
2138 status = nfserr_jukebox; 2185 status = nfserr_jukebox;
2139 if (!conf) { 2186 new = create_client(clname, dname, rqstp, &clverifier);
2140 /* 2187 if (new == NULL)
2141 * RFC 3530 14.2.33 CASE 4: 2188 goto out;
2142 * placed first, because it is the normal case 2189 if (conf && same_verf(&conf->cl_verifier, &clverifier))
2143 */ 2190 /* case 1: probable callback update */
2144 if (unconf)
2145 expire_client(unconf);
2146 new = create_client(clname, dname, rqstp, &clverifier);
2147 if (new == NULL)
2148 goto out;
2149 gen_clid(new);
2150 } else if (same_verf(&conf->cl_verifier, &clverifier)) {
2151 /*
2152 * RFC 3530 14.2.33 CASE 1:
2153 * probable callback update
2154 */
2155 if (unconf) {
2156 /* Note this is removing unconfirmed {*x***},
2157 * which is stronger than RFC recommended {vxc**}.
2158 * This has the advantage that there is at most
2159 * one {*x***} in either list at any time.
2160 */
2161 expire_client(unconf);
2162 }
2163 new = create_client(clname, dname, rqstp, &clverifier);
2164 if (new == NULL)
2165 goto out;
2166 copy_clid(new, conf); 2191 copy_clid(new, conf);
2167 } else if (!unconf) { 2192 else /* case 4 (new client) or cases 2, 3 (client reboot): */
2168 /*
2169 * RFC 3530 14.2.33 CASE 2:
2170 * probable client reboot; state will be removed if
2171 * confirmed.
2172 */
2173 new = create_client(clname, dname, rqstp, &clverifier);
2174 if (new == NULL)
2175 goto out;
2176 gen_clid(new);
2177 } else {
2178 /*
2179 * RFC 3530 14.2.33 CASE 3:
2180 * probable client reboot; state will be removed if
2181 * confirmed.
2182 */
2183 expire_client(unconf);
2184 new = create_client(clname, dname, rqstp, &clverifier);
2185 if (new == NULL)
2186 goto out;
2187 gen_clid(new); 2193 gen_clid(new);
2188 }
2189 /* 2194 /*
2190 * XXX: we should probably set this at creation time, and check 2195 * XXX: we should probably set this at creation time, and check
2191 * for consistent minorversion use throughout: 2196 * for consistent minorversion use throughout:
@@ -2203,17 +2208,11 @@ out:
2203} 2208}
2204 2209
2205 2210
2206/*
2207 * Section 14.2.34 of RFC 3530 (under the heading "IMPLEMENTATION") has
2208 * a description of SETCLIENTID_CONFIRM request processing consisting of 4
2209 * bullets, labeled as CASE1 - CASE4 below.
2210 */
2211__be32 2211__be32
2212nfsd4_setclientid_confirm(struct svc_rqst *rqstp, 2212nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
2213 struct nfsd4_compound_state *cstate, 2213 struct nfsd4_compound_state *cstate,
2214 struct nfsd4_setclientid_confirm *setclientid_confirm) 2214 struct nfsd4_setclientid_confirm *setclientid_confirm)
2215{ 2215{
2216 struct sockaddr *sa = svc_addr(rqstp);
2217 struct nfs4_client *conf, *unconf; 2216 struct nfs4_client *conf, *unconf;
2218 nfs4_verifier confirm = setclientid_confirm->sc_confirm; 2217 nfs4_verifier confirm = setclientid_confirm->sc_confirm;
2219 clientid_t * clid = &setclientid_confirm->sc_clientid; 2218 clientid_t * clid = &setclientid_confirm->sc_clientid;
@@ -2221,84 +2220,44 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
2221 2220
2222 if (STALE_CLIENTID(clid)) 2221 if (STALE_CLIENTID(clid))
2223 return nfserr_stale_clientid; 2222 return nfserr_stale_clientid;
2224 /*
2225 * XXX The Duplicate Request Cache (DRC) has been checked (??)
2226 * We get here on a DRC miss.
2227 */
2228
2229 nfs4_lock_state(); 2223 nfs4_lock_state();
2230 2224
2231 conf = find_confirmed_client(clid); 2225 conf = find_confirmed_client(clid);
2232 unconf = find_unconfirmed_client(clid); 2226 unconf = find_unconfirmed_client(clid);
2233
2234 status = nfserr_clid_inuse;
2235 if (conf && !rpc_cmp_addr((struct sockaddr *) &conf->cl_addr, sa))
2236 goto out;
2237 if (unconf && !rpc_cmp_addr((struct sockaddr *) &unconf->cl_addr, sa))
2238 goto out;
2239
2240 /* 2227 /*
2241 * section 14.2.34 of RFC 3530 has a description of 2228 * We try hard to give out unique clientid's, so if we get an
2242 * SETCLIENTID_CONFIRM request processing consisting 2229 * attempt to confirm the same clientid with a different cred,
2243 * of 4 bullet points, labeled as CASE1 - CASE4 below. 2230 * there's a bug somewhere. Let's charitably assume it's our
2231 * bug.
2244 */ 2232 */
2245 if (conf && unconf && same_verf(&confirm, &unconf->cl_confirm)) { 2233 status = nfserr_serverfault;
2246 /* 2234 if (unconf && !same_creds(&unconf->cl_cred, &rqstp->rq_cred))
2247 * RFC 3530 14.2.34 CASE 1: 2235 goto out;
2248 * callback update 2236 if (conf && !same_creds(&conf->cl_cred, &rqstp->rq_cred))
2249 */ 2237 goto out;
2250 if (!same_creds(&conf->cl_cred, &unconf->cl_cred)) 2238 /* cases below refer to rfc 3530 section 14.2.34: */
2251 status = nfserr_clid_inuse; 2239 if (!unconf || !same_verf(&confirm, &unconf->cl_confirm)) {
2252 else { 2240 if (conf && !unconf) /* case 2: probable retransmit */
2253 nfsd4_change_callback(conf, &unconf->cl_cb_conn);
2254 nfsd4_probe_callback(conf);
2255 expire_client(unconf);
2256 status = nfs_ok; 2241 status = nfs_ok;
2242 else /* case 4: client hasn't noticed we rebooted yet? */
2243 status = nfserr_stale_clientid;
2244 goto out;
2245 }
2246 status = nfs_ok;
2247 if (conf) { /* case 1: callback update */
2248 nfsd4_change_callback(conf, &unconf->cl_cb_conn);
2249 nfsd4_probe_callback(conf);
2250 expire_client(unconf);
2251 } else { /* case 3: normal case; new or rebooted client */
2252 unsigned int hash = clientstr_hashval(unconf->cl_recdir);
2257 2253
2254 conf = find_confirmed_client_by_str(unconf->cl_recdir, hash);
2255 if (conf) {
2256 nfsd4_client_record_remove(conf);
2257 expire_client(conf);
2258 } 2258 }
2259 } else if (conf && !unconf) { 2259 move_to_confirmed(unconf);
2260 /* 2260 nfsd4_probe_callback(unconf);
2261 * RFC 3530 14.2.34 CASE 2:
2262 * probable retransmitted request; play it safe and
2263 * do nothing.
2264 */
2265 if (!same_creds(&conf->cl_cred, &rqstp->rq_cred))
2266 status = nfserr_clid_inuse;
2267 else
2268 status = nfs_ok;
2269 } else if (!conf && unconf
2270 && same_verf(&unconf->cl_confirm, &confirm)) {
2271 /*
2272 * RFC 3530 14.2.34 CASE 3:
2273 * Normal case; new or rebooted client:
2274 */
2275 if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred)) {
2276 status = nfserr_clid_inuse;
2277 } else {
2278 unsigned int hash =
2279 clientstr_hashval(unconf->cl_recdir);
2280 conf = find_confirmed_client_by_str(unconf->cl_recdir,
2281 hash);
2282 if (conf) {
2283 nfsd4_client_record_remove(conf);
2284 expire_client(conf);
2285 }
2286 move_to_confirmed(unconf);
2287 conf = unconf;
2288 nfsd4_probe_callback(conf);
2289 status = nfs_ok;
2290 }
2291 } else if ((!conf || (conf && !same_verf(&conf->cl_confirm, &confirm)))
2292 && (!unconf || (unconf && !same_verf(&unconf->cl_confirm,
2293 &confirm)))) {
2294 /*
2295 * RFC 3530 14.2.34 CASE 4:
2296 * Client probably hasn't noticed that we rebooted yet.
2297 */
2298 status = nfserr_stale_clientid;
2299 } else {
2300 /* check that we have hit one of the cases...*/
2301 status = nfserr_clid_inuse;
2302 } 2261 }
2303out: 2262out:
2304 nfs4_unlock_state(); 2263 nfs4_unlock_state();
@@ -2454,8 +2413,8 @@ static void init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp,
2454 stp->st_file = fp; 2413 stp->st_file = fp;
2455 stp->st_access_bmap = 0; 2414 stp->st_access_bmap = 0;
2456 stp->st_deny_bmap = 0; 2415 stp->st_deny_bmap = 0;
2457 __set_bit(open->op_share_access, &stp->st_access_bmap); 2416 set_access(open->op_share_access, stp);
2458 __set_bit(open->op_share_deny, &stp->st_deny_bmap); 2417 set_deny(open->op_share_deny, stp);
2459 stp->st_openstp = NULL; 2418 stp->st_openstp = NULL;
2460} 2419}
2461 2420
@@ -2534,8 +2493,8 @@ nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type)
2534 ret = nfserr_locked; 2493 ret = nfserr_locked;
2535 /* Search for conflicting share reservations */ 2494 /* Search for conflicting share reservations */
2536 list_for_each_entry(stp, &fp->fi_stateids, st_perfile) { 2495 list_for_each_entry(stp, &fp->fi_stateids, st_perfile) {
2537 if (test_bit(deny_type, &stp->st_deny_bmap) || 2496 if (test_deny(deny_type, stp) ||
2538 test_bit(NFS4_SHARE_DENY_BOTH, &stp->st_deny_bmap)) 2497 test_deny(NFS4_SHARE_DENY_BOTH, stp))
2539 goto out; 2498 goto out;
2540 } 2499 }
2541 ret = nfs_ok; 2500 ret = nfs_ok;
@@ -2791,7 +2750,7 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *c
2791 bool new_access; 2750 bool new_access;
2792 __be32 status; 2751 __be32 status;
2793 2752
2794 new_access = !test_bit(op_share_access, &stp->st_access_bmap); 2753 new_access = !test_access(op_share_access, stp);
2795 if (new_access) { 2754 if (new_access) {
2796 status = nfs4_get_vfs_file(rqstp, fp, cur_fh, open); 2755 status = nfs4_get_vfs_file(rqstp, fp, cur_fh, open);
2797 if (status) 2756 if (status)
@@ -2806,8 +2765,8 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *c
2806 return status; 2765 return status;
2807 } 2766 }
2808 /* remember the open */ 2767 /* remember the open */
2809 __set_bit(op_share_access, &stp->st_access_bmap); 2768 set_access(op_share_access, stp);
2810 __set_bit(open->op_share_deny, &stp->st_deny_bmap); 2769 set_deny(open->op_share_deny, stp);
2811 2770
2812 return nfs_ok; 2771 return nfs_ok;
2813} 2772}
@@ -3155,10 +3114,17 @@ out:
3155static struct lock_manager nfsd4_manager = { 3114static struct lock_manager nfsd4_manager = {
3156}; 3115};
3157 3116
3117static bool grace_ended;
3118
3158static void 3119static void
3159nfsd4_end_grace(void) 3120nfsd4_end_grace(void)
3160{ 3121{
3122 /* do nothing if grace period already ended */
3123 if (grace_ended)
3124 return;
3125
3161 dprintk("NFSD: end of grace period\n"); 3126 dprintk("NFSD: end of grace period\n");
3127 grace_ended = true;
3162 nfsd4_record_grace_done(&init_net, boot_time); 3128 nfsd4_record_grace_done(&init_net, boot_time);
3163 locks_end_grace(&nfsd4_manager); 3129 locks_end_grace(&nfsd4_manager);
3164 /* 3130 /*
@@ -3183,8 +3149,7 @@ nfs4_laundromat(void)
3183 nfs4_lock_state(); 3149 nfs4_lock_state();
3184 3150
3185 dprintk("NFSD: laundromat service - starting\n"); 3151 dprintk("NFSD: laundromat service - starting\n");
3186 if (locks_in_grace()) 3152 nfsd4_end_grace();
3187 nfsd4_end_grace();
3188 INIT_LIST_HEAD(&reaplist); 3153 INIT_LIST_HEAD(&reaplist);
3189 spin_lock(&client_lock); 3154 spin_lock(&client_lock);
3190 list_for_each_safe(pos, next, &client_lru) { 3155 list_for_each_safe(pos, next, &client_lru) {
@@ -3276,18 +3241,18 @@ STALE_STATEID(stateid_t *stateid)
3276} 3241}
3277 3242
3278static inline int 3243static inline int
3279access_permit_read(unsigned long access_bmap) 3244access_permit_read(struct nfs4_ol_stateid *stp)
3280{ 3245{
3281 return test_bit(NFS4_SHARE_ACCESS_READ, &access_bmap) || 3246 return test_access(NFS4_SHARE_ACCESS_READ, stp) ||
3282 test_bit(NFS4_SHARE_ACCESS_BOTH, &access_bmap) || 3247 test_access(NFS4_SHARE_ACCESS_BOTH, stp) ||
3283 test_bit(NFS4_SHARE_ACCESS_WRITE, &access_bmap); 3248 test_access(NFS4_SHARE_ACCESS_WRITE, stp);
3284} 3249}
3285 3250
3286static inline int 3251static inline int
3287access_permit_write(unsigned long access_bmap) 3252access_permit_write(struct nfs4_ol_stateid *stp)
3288{ 3253{
3289 return test_bit(NFS4_SHARE_ACCESS_WRITE, &access_bmap) || 3254 return test_access(NFS4_SHARE_ACCESS_WRITE, stp) ||
3290 test_bit(NFS4_SHARE_ACCESS_BOTH, &access_bmap); 3255 test_access(NFS4_SHARE_ACCESS_BOTH, stp);
3291} 3256}
3292 3257
3293static 3258static
@@ -3298,9 +3263,9 @@ __be32 nfs4_check_openmode(struct nfs4_ol_stateid *stp, int flags)
3298 /* For lock stateid's, we test the parent open, not the lock: */ 3263 /* For lock stateid's, we test the parent open, not the lock: */
3299 if (stp->st_openstp) 3264 if (stp->st_openstp)
3300 stp = stp->st_openstp; 3265 stp = stp->st_openstp;
3301 if ((flags & WR_STATE) && (!access_permit_write(stp->st_access_bmap))) 3266 if ((flags & WR_STATE) && !access_permit_write(stp))
3302 goto out; 3267 goto out;
3303 if ((flags & RD_STATE) && (!access_permit_read(stp->st_access_bmap))) 3268 if ((flags & RD_STATE) && !access_permit_read(stp))
3304 goto out; 3269 goto out;
3305 status = nfs_ok; 3270 status = nfs_ok;
3306out: 3271out:
@@ -3340,7 +3305,7 @@ static bool stateid_generation_after(stateid_t *a, stateid_t *b)
3340 return (s32)a->si_generation - (s32)b->si_generation > 0; 3305 return (s32)a->si_generation - (s32)b->si_generation > 0;
3341} 3306}
3342 3307
3343static int check_stateid_generation(stateid_t *in, stateid_t *ref, bool has_session) 3308static __be32 check_stateid_generation(stateid_t *in, stateid_t *ref, bool has_session)
3344{ 3309{
3345 /* 3310 /*
3346 * When sessions are used the stateid generation number is ignored 3311 * When sessions are used the stateid generation number is ignored
@@ -3649,10 +3614,10 @@ out:
3649 3614
3650static inline void nfs4_stateid_downgrade_bit(struct nfs4_ol_stateid *stp, u32 access) 3615static inline void nfs4_stateid_downgrade_bit(struct nfs4_ol_stateid *stp, u32 access)
3651{ 3616{
3652 if (!test_bit(access, &stp->st_access_bmap)) 3617 if (!test_access(access, stp))
3653 return; 3618 return;
3654 nfs4_file_put_access(stp->st_file, nfs4_access_to_omode(access)); 3619 nfs4_file_put_access(stp->st_file, nfs4_access_to_omode(access));
3655 __clear_bit(access, &stp->st_access_bmap); 3620 clear_access(access, stp);
3656} 3621}
3657 3622
3658static inline void nfs4_stateid_downgrade(struct nfs4_ol_stateid *stp, u32 to_access) 3623static inline void nfs4_stateid_downgrade(struct nfs4_ol_stateid *stp, u32 to_access)
@@ -3674,12 +3639,12 @@ static inline void nfs4_stateid_downgrade(struct nfs4_ol_stateid *stp, u32 to_ac
3674} 3639}
3675 3640
3676static void 3641static void
3677reset_union_bmap_deny(unsigned long deny, unsigned long *bmap) 3642reset_union_bmap_deny(unsigned long deny, struct nfs4_ol_stateid *stp)
3678{ 3643{
3679 int i; 3644 int i;
3680 for (i = 0; i < 4; i++) { 3645 for (i = 0; i < 4; i++) {
3681 if ((i & deny) != i) 3646 if ((i & deny) != i)
3682 __clear_bit(i, bmap); 3647 clear_deny(i, stp);
3683 } 3648 }
3684} 3649}
3685 3650
@@ -3706,19 +3671,19 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
3706 if (status) 3671 if (status)
3707 goto out; 3672 goto out;
3708 status = nfserr_inval; 3673 status = nfserr_inval;
3709 if (!test_bit(od->od_share_access, &stp->st_access_bmap)) { 3674 if (!test_access(od->od_share_access, stp)) {
3710 dprintk("NFSD:access not a subset current bitmap: 0x%lx, input access=%08x\n", 3675 dprintk("NFSD: access not a subset current bitmap: 0x%lx, input access=%08x\n",
3711 stp->st_access_bmap, od->od_share_access); 3676 stp->st_access_bmap, od->od_share_access);
3712 goto out; 3677 goto out;
3713 } 3678 }
3714 if (!test_bit(od->od_share_deny, &stp->st_deny_bmap)) { 3679 if (!test_deny(od->od_share_deny, stp)) {
3715 dprintk("NFSD:deny not a subset current bitmap: 0x%lx, input deny=%08x\n", 3680 dprintk("NFSD:deny not a subset current bitmap: 0x%lx, input deny=%08x\n",
3716 stp->st_deny_bmap, od->od_share_deny); 3681 stp->st_deny_bmap, od->od_share_deny);
3717 goto out; 3682 goto out;
3718 } 3683 }
3719 nfs4_stateid_downgrade(stp, od->od_share_access); 3684 nfs4_stateid_downgrade(stp, od->od_share_access);
3720 3685
3721 reset_union_bmap_deny(od->od_share_deny, &stp->st_deny_bmap); 3686 reset_union_bmap_deny(od->od_share_deny, stp);
3722 3687
3723 update_stateid(&stp->st_stid.sc_stateid); 3688 update_stateid(&stp->st_stid.sc_stateid);
3724 memcpy(&od->od_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t)); 3689 memcpy(&od->od_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t));
@@ -4008,13 +3973,13 @@ static void get_lock_access(struct nfs4_ol_stateid *lock_stp, u32 access)
4008 struct nfs4_file *fp = lock_stp->st_file; 3973 struct nfs4_file *fp = lock_stp->st_file;
4009 int oflag = nfs4_access_to_omode(access); 3974 int oflag = nfs4_access_to_omode(access);
4010 3975
4011 if (test_bit(access, &lock_stp->st_access_bmap)) 3976 if (test_access(access, lock_stp))
4012 return; 3977 return;
4013 nfs4_file_get_access(fp, oflag); 3978 nfs4_file_get_access(fp, oflag);
4014 __set_bit(access, &lock_stp->st_access_bmap); 3979 set_access(access, lock_stp);
4015} 3980}
4016 3981
4017__be32 lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, struct nfs4_ol_stateid *ost, struct nfsd4_lock *lock, struct nfs4_ol_stateid **lst, bool *new) 3982static __be32 lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, struct nfs4_ol_stateid *ost, struct nfsd4_lock *lock, struct nfs4_ol_stateid **lst, bool *new)
4018{ 3983{
4019 struct nfs4_file *fi = ost->st_file; 3984 struct nfs4_file *fi = ost->st_file;
4020 struct nfs4_openowner *oo = openowner(ost->st_stateowner); 3985 struct nfs4_openowner *oo = openowner(ost->st_stateowner);
@@ -4055,7 +4020,6 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4055 struct nfs4_openowner *open_sop = NULL; 4020 struct nfs4_openowner *open_sop = NULL;
4056 struct nfs4_lockowner *lock_sop = NULL; 4021 struct nfs4_lockowner *lock_sop = NULL;
4057 struct nfs4_ol_stateid *lock_stp; 4022 struct nfs4_ol_stateid *lock_stp;
4058 struct nfs4_file *fp;
4059 struct file *filp = NULL; 4023 struct file *filp = NULL;
4060 struct file_lock file_lock; 4024 struct file_lock file_lock;
4061 struct file_lock conflock; 4025 struct file_lock conflock;
@@ -4123,7 +4087,6 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
4123 goto out; 4087 goto out;
4124 } 4088 }
4125 lock_sop = lockowner(lock_stp->st_stateowner); 4089 lock_sop = lockowner(lock_stp->st_stateowner);
4126 fp = lock_stp->st_file;
4127 4090
4128 lkflg = setlkflg(lock->lk_type); 4091 lkflg = setlkflg(lock->lk_type);
4129 status = nfs4_check_openmode(lock_stp, lkflg); 4092 status = nfs4_check_openmode(lock_stp, lkflg);
@@ -4715,6 +4678,7 @@ nfs4_state_start(void)
4715 nfsd4_client_tracking_init(&init_net); 4678 nfsd4_client_tracking_init(&init_net);
4716 boot_time = get_seconds(); 4679 boot_time = get_seconds();
4717 locks_start_grace(&nfsd4_manager); 4680 locks_start_grace(&nfsd4_manager);
4681 grace_ended = false;
4718 printk(KERN_INFO "NFSD: starting %ld-second grace period\n", 4682 printk(KERN_INFO "NFSD: starting %ld-second grace period\n",
4719 nfsd4_grace); 4683 nfsd4_grace);
4720 ret = set_callback_cred(); 4684 ret = set_callback_cred();
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 74c00bc92b9a..4949667c84ea 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -1674,12 +1674,12 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
1674 1674
1675static void write32(__be32 **p, u32 n) 1675static void write32(__be32 **p, u32 n)
1676{ 1676{
1677 *(*p)++ = n; 1677 *(*p)++ = htonl(n);
1678} 1678}
1679 1679
1680static void write64(__be32 **p, u64 n) 1680static void write64(__be32 **p, u64 n)
1681{ 1681{
1682 write32(p, (u32)(n >> 32)); 1682 write32(p, (n >> 32));
1683 write32(p, (u32)n); 1683 write32(p, (u32)n);
1684} 1684}
1685 1685
@@ -1744,15 +1744,16 @@ static void encode_seqid_op_tail(struct nfsd4_compoundres *resp, __be32 *save, _
1744} 1744}
1745 1745
1746/* Encode as an array of strings the string given with components 1746/* Encode as an array of strings the string given with components
1747 * separated @sep. 1747 * separated @sep, escaped with esc_enter and esc_exit.
1748 */ 1748 */
1749static __be32 nfsd4_encode_components(char sep, char *components, 1749static __be32 nfsd4_encode_components_esc(char sep, char *components,
1750 __be32 **pp, int *buflen) 1750 __be32 **pp, int *buflen,
1751 char esc_enter, char esc_exit)
1751{ 1752{
1752 __be32 *p = *pp; 1753 __be32 *p = *pp;
1753 __be32 *countp = p; 1754 __be32 *countp = p;
1754 int strlen, count=0; 1755 int strlen, count=0;
1755 char *str, *end; 1756 char *str, *end, *next;
1756 1757
1757 dprintk("nfsd4_encode_components(%s)\n", components); 1758 dprintk("nfsd4_encode_components(%s)\n", components);
1758 if ((*buflen -= 4) < 0) 1759 if ((*buflen -= 4) < 0)
@@ -1760,8 +1761,23 @@ static __be32 nfsd4_encode_components(char sep, char *components,
1760 WRITE32(0); /* We will fill this in with @count later */ 1761 WRITE32(0); /* We will fill this in with @count later */
1761 end = str = components; 1762 end = str = components;
1762 while (*end) { 1763 while (*end) {
1763 for (; *end && (*end != sep); end++) 1764 bool found_esc = false;
1764 ; /* Point to end of component */ 1765
1766 /* try to parse as esc_start, ..., esc_end, sep */
1767 if (*str == esc_enter) {
1768 for (; *end && (*end != esc_exit); end++)
1769 /* find esc_exit or end of string */;
1770 next = end + 1;
1771 if (*end && (!*next || *next == sep)) {
1772 str++;
1773 found_esc = true;
1774 }
1775 }
1776
1777 if (!found_esc)
1778 for (; *end && (*end != sep); end++)
1779 /* find sep or end of string */;
1780
1765 strlen = end - str; 1781 strlen = end - str;
1766 if (strlen) { 1782 if (strlen) {
1767 if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0) 1783 if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0)
@@ -1780,6 +1796,15 @@ static __be32 nfsd4_encode_components(char sep, char *components,
1780 return 0; 1796 return 0;
1781} 1797}
1782 1798
1799/* Encode as an array of strings the string given with components
1800 * separated @sep.
1801 */
1802static __be32 nfsd4_encode_components(char sep, char *components,
1803 __be32 **pp, int *buflen)
1804{
1805 return nfsd4_encode_components_esc(sep, components, pp, buflen, 0, 0);
1806}
1807
1783/* 1808/*
1784 * encode a location element of a fs_locations structure 1809 * encode a location element of a fs_locations structure
1785 */ 1810 */
@@ -1789,7 +1814,8 @@ static __be32 nfsd4_encode_fs_location4(struct nfsd4_fs_location *location,
1789 __be32 status; 1814 __be32 status;
1790 __be32 *p = *pp; 1815 __be32 *p = *pp;
1791 1816
1792 status = nfsd4_encode_components(':', location->hosts, &p, buflen); 1817 status = nfsd4_encode_components_esc(':', location->hosts, &p, buflen,
1818 '[', ']');
1793 if (status) 1819 if (status)
1794 return status; 1820 return status;
1795 status = nfsd4_encode_components('/', location->path, &p, buflen); 1821 status = nfsd4_encode_components('/', location->path, &p, buflen);
@@ -3251,7 +3277,7 @@ nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_w
3251} 3277}
3252 3278
3253static __be32 3279static __be32
3254nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, int nfserr, 3280nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
3255 struct nfsd4_exchange_id *exid) 3281 struct nfsd4_exchange_id *exid)
3256{ 3282{
3257 __be32 *p; 3283 __be32 *p;
@@ -3306,7 +3332,7 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, int nfserr,
3306} 3332}
3307 3333
3308static __be32 3334static __be32
3309nfsd4_encode_create_session(struct nfsd4_compoundres *resp, int nfserr, 3335nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr,
3310 struct nfsd4_create_session *sess) 3336 struct nfsd4_create_session *sess)
3311{ 3337{
3312 __be32 *p; 3338 __be32 *p;
@@ -3355,14 +3381,14 @@ nfsd4_encode_create_session(struct nfsd4_compoundres *resp, int nfserr,
3355} 3381}
3356 3382
3357static __be32 3383static __be32
3358nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, int nfserr, 3384nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, __be32 nfserr,
3359 struct nfsd4_destroy_session *destroy_session) 3385 struct nfsd4_destroy_session *destroy_session)
3360{ 3386{
3361 return nfserr; 3387 return nfserr;
3362} 3388}
3363 3389
3364static __be32 3390static __be32
3365nfsd4_encode_free_stateid(struct nfsd4_compoundres *resp, int nfserr, 3391nfsd4_encode_free_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
3366 struct nfsd4_free_stateid *free_stateid) 3392 struct nfsd4_free_stateid *free_stateid)
3367{ 3393{
3368 __be32 *p; 3394 __be32 *p;
@@ -3371,13 +3397,13 @@ nfsd4_encode_free_stateid(struct nfsd4_compoundres *resp, int nfserr,
3371 return nfserr; 3397 return nfserr;
3372 3398
3373 RESERVE_SPACE(4); 3399 RESERVE_SPACE(4);
3374 WRITE32(nfserr); 3400 *p++ = nfserr;
3375 ADJUST_ARGS(); 3401 ADJUST_ARGS();
3376 return nfserr; 3402 return nfserr;
3377} 3403}
3378 3404
3379static __be32 3405static __be32
3380nfsd4_encode_sequence(struct nfsd4_compoundres *resp, int nfserr, 3406nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr,
3381 struct nfsd4_sequence *seq) 3407 struct nfsd4_sequence *seq)
3382{ 3408{
3383 __be32 *p; 3409 __be32 *p;
@@ -3399,8 +3425,8 @@ nfsd4_encode_sequence(struct nfsd4_compoundres *resp, int nfserr,
3399 return 0; 3425 return 0;
3400} 3426}
3401 3427
3402__be32 3428static __be32
3403nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, int nfserr, 3429nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
3404 struct nfsd4_test_stateid *test_stateid) 3430 struct nfsd4_test_stateid *test_stateid)
3405{ 3431{
3406 struct nfsd4_test_stateid_id *stateid, *next; 3432 struct nfsd4_test_stateid_id *stateid, *next;
@@ -3503,7 +3529,7 @@ static nfsd4_enc nfsd4_enc_ops[] = {
3503 * Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so 3529 * Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so
3504 * will be at least a page and will therefore hold the xdr_buf head. 3530 * will be at least a page and will therefore hold the xdr_buf head.
3505 */ 3531 */
3506int nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 pad) 3532__be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 pad)
3507{ 3533{
3508 struct xdr_buf *xb = &resp->rqstp->rq_res; 3534 struct xdr_buf *xb = &resp->rqstp->rq_res;
3509 struct nfsd4_session *session = NULL; 3535 struct nfsd4_session *session = NULL;
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 2c53be6d3579..c55298ed5772 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -127,7 +127,17 @@ static const struct file_operations transaction_ops = {
127 127
128static int exports_open(struct inode *inode, struct file *file) 128static int exports_open(struct inode *inode, struct file *file)
129{ 129{
130 return seq_open(file, &nfs_exports_op); 130 int err;
131 struct seq_file *seq;
132 struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
133
134 err = seq_open(file, &nfs_exports_op);
135 if (err)
136 return err;
137
138 seq = file->private_data;
139 seq->private = nn->svc_export_cache;
140 return 0;
131} 141}
132 142
133static const struct file_operations exports_operations = { 143static const struct file_operations exports_operations = {
@@ -345,7 +355,7 @@ static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
345 if (!dom) 355 if (!dom)
346 return -ENOMEM; 356 return -ENOMEM;
347 357
348 len = exp_rootfh(dom, path, &fh, maxsize); 358 len = exp_rootfh(&init_net, dom, path, &fh, maxsize);
349 auth_domain_put(dom); 359 auth_domain_put(dom);
350 if (len) 360 if (len)
351 return len; 361 return len;
@@ -651,6 +661,7 @@ static ssize_t __write_ports_addfd(char *buf)
651{ 661{
652 char *mesg = buf; 662 char *mesg = buf;
653 int fd, err; 663 int fd, err;
664 struct net *net = &init_net;
654 665
655 err = get_int(&mesg, &fd); 666 err = get_int(&mesg, &fd);
656 if (err != 0 || fd < 0) 667 if (err != 0 || fd < 0)
@@ -662,6 +673,8 @@ static ssize_t __write_ports_addfd(char *buf)
662 673
663 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT); 674 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
664 if (err < 0) { 675 if (err < 0) {
676 if (nfsd_serv->sv_nrthreads == 1)
677 svc_shutdown_net(nfsd_serv, net);
665 svc_destroy(nfsd_serv); 678 svc_destroy(nfsd_serv);
666 return err; 679 return err;
667 } 680 }
@@ -699,6 +712,7 @@ static ssize_t __write_ports_addxprt(char *buf)
699 char transport[16]; 712 char transport[16];
700 struct svc_xprt *xprt; 713 struct svc_xprt *xprt;
701 int port, err; 714 int port, err;
715 struct net *net = &init_net;
702 716
703 if (sscanf(buf, "%15s %4u", transport, &port) != 2) 717 if (sscanf(buf, "%15s %4u", transport, &port) != 2)
704 return -EINVAL; 718 return -EINVAL;
@@ -710,12 +724,12 @@ static ssize_t __write_ports_addxprt(char *buf)
710 if (err != 0) 724 if (err != 0)
711 return err; 725 return err;
712 726
713 err = svc_create_xprt(nfsd_serv, transport, &init_net, 727 err = svc_create_xprt(nfsd_serv, transport, net,
714 PF_INET, port, SVC_SOCK_ANONYMOUS); 728 PF_INET, port, SVC_SOCK_ANONYMOUS);
715 if (err < 0) 729 if (err < 0)
716 goto out_err; 730 goto out_err;
717 731
718 err = svc_create_xprt(nfsd_serv, transport, &init_net, 732 err = svc_create_xprt(nfsd_serv, transport, net,
719 PF_INET6, port, SVC_SOCK_ANONYMOUS); 733 PF_INET6, port, SVC_SOCK_ANONYMOUS);
720 if (err < 0 && err != -EAFNOSUPPORT) 734 if (err < 0 && err != -EAFNOSUPPORT)
721 goto out_close; 735 goto out_close;
@@ -724,12 +738,14 @@ static ssize_t __write_ports_addxprt(char *buf)
724 nfsd_serv->sv_nrthreads--; 738 nfsd_serv->sv_nrthreads--;
725 return 0; 739 return 0;
726out_close: 740out_close:
727 xprt = svc_find_xprt(nfsd_serv, transport, &init_net, PF_INET, port); 741 xprt = svc_find_xprt(nfsd_serv, transport, net, PF_INET, port);
728 if (xprt != NULL) { 742 if (xprt != NULL) {
729 svc_close_xprt(xprt); 743 svc_close_xprt(xprt);
730 svc_xprt_put(xprt); 744 svc_xprt_put(xprt);
731 } 745 }
732out_err: 746out_err:
747 if (nfsd_serv->sv_nrthreads == 1)
748 svc_shutdown_net(nfsd_serv, net);
733 svc_destroy(nfsd_serv); 749 svc_destroy(nfsd_serv);
734 return err; 750 return err;
735} 751}
@@ -1127,7 +1143,34 @@ static int create_proc_exports_entry(void)
1127#endif 1143#endif
1128 1144
1129int nfsd_net_id; 1145int nfsd_net_id;
1146
1147static __net_init int nfsd_init_net(struct net *net)
1148{
1149 int retval;
1150
1151 retval = nfsd_export_init(net);
1152 if (retval)
1153 goto out_export_error;
1154 retval = nfsd_idmap_init(net);
1155 if (retval)
1156 goto out_idmap_error;
1157 return 0;
1158
1159out_idmap_error:
1160 nfsd_export_shutdown(net);
1161out_export_error:
1162 return retval;
1163}
1164
1165static __net_exit void nfsd_exit_net(struct net *net)
1166{
1167 nfsd_idmap_shutdown(net);
1168 nfsd_export_shutdown(net);
1169}
1170
1130static struct pernet_operations nfsd_net_ops = { 1171static struct pernet_operations nfsd_net_ops = {
1172 .init = nfsd_init_net,
1173 .exit = nfsd_exit_net,
1131 .id = &nfsd_net_id, 1174 .id = &nfsd_net_id,
1132 .size = sizeof(struct nfsd_net), 1175 .size = sizeof(struct nfsd_net),
1133}; 1176};
@@ -1154,16 +1197,10 @@ static int __init init_nfsd(void)
1154 retval = nfsd_reply_cache_init(); 1197 retval = nfsd_reply_cache_init();
1155 if (retval) 1198 if (retval)
1156 goto out_free_stat; 1199 goto out_free_stat;
1157 retval = nfsd_export_init();
1158 if (retval)
1159 goto out_free_cache;
1160 nfsd_lockd_init(); /* lockd->nfsd callbacks */ 1200 nfsd_lockd_init(); /* lockd->nfsd callbacks */
1161 retval = nfsd_idmap_init();
1162 if (retval)
1163 goto out_free_lockd;
1164 retval = create_proc_exports_entry(); 1201 retval = create_proc_exports_entry();
1165 if (retval) 1202 if (retval)
1166 goto out_free_idmap; 1203 goto out_free_lockd;
1167 retval = register_filesystem(&nfsd_fs_type); 1204 retval = register_filesystem(&nfsd_fs_type);
1168 if (retval) 1205 if (retval)
1169 goto out_free_all; 1206 goto out_free_all;
@@ -1171,12 +1208,8 @@ static int __init init_nfsd(void)
1171out_free_all: 1208out_free_all:
1172 remove_proc_entry("fs/nfs/exports", NULL); 1209 remove_proc_entry("fs/nfs/exports", NULL);
1173 remove_proc_entry("fs/nfs", NULL); 1210 remove_proc_entry("fs/nfs", NULL);
1174out_free_idmap:
1175 nfsd_idmap_shutdown();
1176out_free_lockd: 1211out_free_lockd:
1177 nfsd_lockd_shutdown(); 1212 nfsd_lockd_shutdown();
1178 nfsd_export_shutdown();
1179out_free_cache:
1180 nfsd_reply_cache_shutdown(); 1213 nfsd_reply_cache_shutdown();
1181out_free_stat: 1214out_free_stat:
1182 nfsd_stat_shutdown(); 1215 nfsd_stat_shutdown();
@@ -1192,13 +1225,11 @@ out_unregister_notifier:
1192 1225
1193static void __exit exit_nfsd(void) 1226static void __exit exit_nfsd(void)
1194{ 1227{
1195 nfsd_export_shutdown();
1196 nfsd_reply_cache_shutdown(); 1228 nfsd_reply_cache_shutdown();
1197 remove_proc_entry("fs/nfs/exports", NULL); 1229 remove_proc_entry("fs/nfs/exports", NULL);
1198 remove_proc_entry("fs/nfs", NULL); 1230 remove_proc_entry("fs/nfs", NULL);
1199 nfsd_stat_shutdown(); 1231 nfsd_stat_shutdown();
1200 nfsd_lockd_shutdown(); 1232 nfsd_lockd_shutdown();
1201 nfsd_idmap_shutdown();
1202 nfsd4_free_slabs(); 1233 nfsd4_free_slabs();
1203 nfsd_fault_inject_cleanup(); 1234 nfsd_fault_inject_cleanup();
1204 unregister_filesystem(&nfsd_fs_type); 1235 unregister_filesystem(&nfsd_fs_type);
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
index 68454e75fce9..cc793005a87c 100644
--- a/fs/nfsd/nfsfh.c
+++ b/fs/nfsd/nfsfh.c
@@ -636,7 +636,7 @@ fh_put(struct svc_fh *fhp)
636#endif 636#endif
637 } 637 }
638 if (exp) { 638 if (exp) {
639 cache_put(&exp->h, &svc_export_cache); 639 exp_put(exp);
640 fhp->fh_export = NULL; 640 fhp->fh_export = NULL;
641 } 641 }
642 return; 642 return;
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index 28dfad39f0c5..ee709fc8f58b 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -11,6 +11,7 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/fs_struct.h> 12#include <linux/fs_struct.h>
13#include <linux/swap.h> 13#include <linux/swap.h>
14#include <linux/nsproxy.h>
14 15
15#include <linux/sunrpc/stats.h> 16#include <linux/sunrpc/stats.h>
16#include <linux/sunrpc/svcsock.h> 17#include <linux/sunrpc/svcsock.h>
@@ -220,7 +221,7 @@ static int nfsd_startup(unsigned short port, int nrservs)
220 ret = nfsd_init_socks(port); 221 ret = nfsd_init_socks(port);
221 if (ret) 222 if (ret)
222 goto out_racache; 223 goto out_racache;
223 ret = lockd_up(); 224 ret = lockd_up(&init_net);
224 if (ret) 225 if (ret)
225 goto out_racache; 226 goto out_racache;
226 ret = nfs4_state_start(); 227 ret = nfs4_state_start();
@@ -229,7 +230,7 @@ static int nfsd_startup(unsigned short port, int nrservs)
229 nfsd_up = true; 230 nfsd_up = true;
230 return 0; 231 return 0;
231out_lockd: 232out_lockd:
232 lockd_down(); 233 lockd_down(&init_net);
233out_racache: 234out_racache:
234 nfsd_racache_shutdown(); 235 nfsd_racache_shutdown();
235 return ret; 236 return ret;
@@ -246,7 +247,7 @@ static void nfsd_shutdown(void)
246 if (!nfsd_up) 247 if (!nfsd_up)
247 return; 248 return;
248 nfs4_state_shutdown(); 249 nfs4_state_shutdown();
249 lockd_down(); 250 lockd_down(&init_net);
250 nfsd_racache_shutdown(); 251 nfsd_racache_shutdown();
251 nfsd_up = false; 252 nfsd_up = false;
252} 253}
@@ -261,7 +262,7 @@ static void nfsd_last_thread(struct svc_serv *serv, struct net *net)
261 262
262 printk(KERN_WARNING "nfsd: last server has exited, flushing export " 263 printk(KERN_WARNING "nfsd: last server has exited, flushing export "
263 "cache\n"); 264 "cache\n");
264 nfsd_export_flush(); 265 nfsd_export_flush(net);
265} 266}
266 267
267void nfsd_reset_versions(void) 268void nfsd_reset_versions(void)
@@ -330,6 +331,8 @@ static int nfsd_get_default_max_blksize(void)
330 331
331int nfsd_create_serv(void) 332int nfsd_create_serv(void)
332{ 333{
334 int error;
335
333 WARN_ON(!mutex_is_locked(&nfsd_mutex)); 336 WARN_ON(!mutex_is_locked(&nfsd_mutex));
334 if (nfsd_serv) { 337 if (nfsd_serv) {
335 svc_get(nfsd_serv); 338 svc_get(nfsd_serv);
@@ -343,6 +346,12 @@ int nfsd_create_serv(void)
343 if (nfsd_serv == NULL) 346 if (nfsd_serv == NULL)
344 return -ENOMEM; 347 return -ENOMEM;
345 348
349 error = svc_bind(nfsd_serv, current->nsproxy->net_ns);
350 if (error < 0) {
351 svc_destroy(nfsd_serv);
352 return error;
353 }
354
346 set_max_drc(); 355 set_max_drc();
347 do_gettimeofday(&nfssvc_boot); /* record boot time */ 356 do_gettimeofday(&nfssvc_boot); /* record boot time */
348 return 0; 357 return 0;
@@ -373,6 +382,7 @@ int nfsd_set_nrthreads(int n, int *nthreads)
373 int i = 0; 382 int i = 0;
374 int tot = 0; 383 int tot = 0;
375 int err = 0; 384 int err = 0;
385 struct net *net = &init_net;
376 386
377 WARN_ON(!mutex_is_locked(&nfsd_mutex)); 387 WARN_ON(!mutex_is_locked(&nfsd_mutex));
378 388
@@ -417,6 +427,9 @@ int nfsd_set_nrthreads(int n, int *nthreads)
417 if (err) 427 if (err)
418 break; 428 break;
419 } 429 }
430
431 if (nfsd_serv->sv_nrthreads == 1)
432 svc_shutdown_net(nfsd_serv, net);
420 svc_destroy(nfsd_serv); 433 svc_destroy(nfsd_serv);
421 434
422 return err; 435 return err;
@@ -432,6 +445,7 @@ nfsd_svc(unsigned short port, int nrservs)
432{ 445{
433 int error; 446 int error;
434 bool nfsd_up_before; 447 bool nfsd_up_before;
448 struct net *net = &init_net;
435 449
436 mutex_lock(&nfsd_mutex); 450 mutex_lock(&nfsd_mutex);
437 dprintk("nfsd: creating service\n"); 451 dprintk("nfsd: creating service\n");
@@ -464,6 +478,8 @@ out_shutdown:
464 if (error < 0 && !nfsd_up_before) 478 if (error < 0 && !nfsd_up_before)
465 nfsd_shutdown(); 479 nfsd_shutdown();
466out_destroy: 480out_destroy:
481 if (nfsd_serv->sv_nrthreads == 1)
482 svc_shutdown_net(nfsd_serv, net);
467 svc_destroy(nfsd_serv); /* Release server */ 483 svc_destroy(nfsd_serv); /* Release server */
468out: 484out:
469 mutex_unlock(&nfsd_mutex); 485 mutex_unlock(&nfsd_mutex);
@@ -547,6 +563,9 @@ nfsd(void *vrqstp)
547 nfsdstats.th_cnt --; 563 nfsdstats.th_cnt --;
548 564
549out: 565out:
566 if (rqstp->rq_server->sv_nrthreads == 1)
567 svc_shutdown_net(rqstp->rq_server, &init_net);
568
550 /* Release the thread */ 569 /* Release the thread */
551 svc_exit_thread(rqstp); 570 svc_exit_thread(rqstp);
552 571
@@ -659,8 +678,12 @@ int nfsd_pool_stats_open(struct inode *inode, struct file *file)
659int nfsd_pool_stats_release(struct inode *inode, struct file *file) 678int nfsd_pool_stats_release(struct inode *inode, struct file *file)
660{ 679{
661 int ret = seq_release(inode, file); 680 int ret = seq_release(inode, file);
681 struct net *net = &init_net;
682
662 mutex_lock(&nfsd_mutex); 683 mutex_lock(&nfsd_mutex);
663 /* this function really, really should have been called svc_put() */ 684 /* this function really, really should have been called svc_put() */
685 if (nfsd_serv->sv_nrthreads == 1)
686 svc_shutdown_net(nfsd_serv, net);
664 svc_destroy(nfsd_serv); 687 svc_destroy(nfsd_serv);
665 mutex_unlock(&nfsd_mutex); 688 mutex_unlock(&nfsd_mutex);
666 return ret; 689 return ret;
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 89ab137d379a..849091e16ea6 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -232,7 +232,6 @@ struct nfs4_client {
232 time_t cl_time; /* time of last lease renewal */ 232 time_t cl_time; /* time of last lease renewal */
233 struct sockaddr_storage cl_addr; /* client ipaddress */ 233 struct sockaddr_storage cl_addr; /* client ipaddress */
234 u32 cl_flavor; /* setclientid pseudoflavor */ 234 u32 cl_flavor; /* setclientid pseudoflavor */
235 char *cl_principal; /* setclientid principal name */
236 struct svc_cred cl_cred; /* setclientid principal */ 235 struct svc_cred cl_cred; /* setclientid principal */
237 clientid_t cl_clientid; /* generated by server */ 236 clientid_t cl_clientid; /* generated by server */
238 nfs4_verifier cl_confirm; /* generated by server */ 237 nfs4_verifier cl_confirm; /* generated by server */
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 568666156ea4..c8bd9c3be7f7 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -2039,7 +2039,7 @@ nfsd_readdir(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t *offsetp,
2039 if (err) 2039 if (err)
2040 goto out; 2040 goto out;
2041 2041
2042 offset = vfs_llseek(file, offset, 0); 2042 offset = vfs_llseek(file, offset, SEEK_SET);
2043 if (offset < 0) { 2043 if (offset < 0) {
2044 err = nfserrno((int)offset); 2044 err = nfserrno((int)offset);
2045 goto out_close; 2045 goto out_close;
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index 1b3501598ab5..acd127d4ee82 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -60,7 +60,7 @@ struct nfsd4_compound_state {
60 __be32 *datap; 60 __be32 *datap;
61 size_t iovlen; 61 size_t iovlen;
62 u32 minorversion; 62 u32 minorversion;
63 u32 status; 63 __be32 status;
64 stateid_t current_stateid; 64 stateid_t current_stateid;
65 stateid_t save_stateid; 65 stateid_t save_stateid;
66 /* to indicate current and saved state id presents */ 66 /* to indicate current and saved state id presents */
@@ -364,7 +364,7 @@ struct nfsd4_test_stateid_id {
364}; 364};
365 365
366struct nfsd4_test_stateid { 366struct nfsd4_test_stateid {
367 __be32 ts_num_ids; 367 u32 ts_num_ids;
368 struct list_head ts_stateid_list; 368 struct list_head ts_stateid_list;
369}; 369};
370 370
@@ -549,7 +549,7 @@ int nfs4svc_decode_compoundargs(struct svc_rqst *, __be32 *,
549 struct nfsd4_compoundargs *); 549 struct nfsd4_compoundargs *);
550int nfs4svc_encode_compoundres(struct svc_rqst *, __be32 *, 550int nfs4svc_encode_compoundres(struct svc_rqst *, __be32 *,
551 struct nfsd4_compoundres *); 551 struct nfsd4_compoundres *);
552int nfsd4_check_resp_size(struct nfsd4_compoundres *, u32); 552__be32 nfsd4_check_resp_size(struct nfsd4_compoundres *, u32);
553void nfsd4_encode_operation(struct nfsd4_compoundres *, struct nfsd4_op *); 553void nfsd4_encode_operation(struct nfsd4_compoundres *, struct nfsd4_op *);
554void nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op); 554void nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op);
555__be32 nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, 555__be32 nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c
index 26601529dc17..62cebc8e1a1f 100644
--- a/fs/nilfs2/file.c
+++ b/fs/nilfs2/file.c
@@ -37,6 +37,7 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
37 * This function should be implemented when the writeback function 37 * This function should be implemented when the writeback function
38 * will be implemented. 38 * will be implemented.
39 */ 39 */
40 struct the_nilfs *nilfs;
40 struct inode *inode = file->f_mapping->host; 41 struct inode *inode = file->f_mapping->host;
41 int err; 42 int err;
42 43
@@ -45,18 +46,21 @@ int nilfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
45 return err; 46 return err;
46 mutex_lock(&inode->i_mutex); 47 mutex_lock(&inode->i_mutex);
47 48
48 if (!nilfs_inode_dirty(inode)) { 49 if (nilfs_inode_dirty(inode)) {
49 mutex_unlock(&inode->i_mutex); 50 if (datasync)
50 return 0; 51 err = nilfs_construct_dsync_segment(inode->i_sb, inode,
52 0, LLONG_MAX);
53 else
54 err = nilfs_construct_segment(inode->i_sb);
51 } 55 }
52
53 if (datasync)
54 err = nilfs_construct_dsync_segment(inode->i_sb, inode, 0,
55 LLONG_MAX);
56 else
57 err = nilfs_construct_segment(inode->i_sb);
58
59 mutex_unlock(&inode->i_mutex); 56 mutex_unlock(&inode->i_mutex);
57
58 nilfs = inode->i_sb->s_fs_info;
59 if (!err && nilfs_test_opt(nilfs, BARRIER)) {
60 err = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
61 if (err != -EIO)
62 err = 0;
63 }
60 return err; 64 return err;
61} 65}
62 66
diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index 2a70fce70c65..06658caa18bd 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -692,8 +692,14 @@ static int nilfs_ioctl_sync(struct inode *inode, struct file *filp,
692 if (ret < 0) 692 if (ret < 0)
693 return ret; 693 return ret;
694 694
695 nilfs = inode->i_sb->s_fs_info;
696 if (nilfs_test_opt(nilfs, BARRIER)) {
697 ret = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
698 if (ret == -EIO)
699 return ret;
700 }
701
695 if (argp != NULL) { 702 if (argp != NULL) {
696 nilfs = inode->i_sb->s_fs_info;
697 down_read(&nilfs->ns_segctor_sem); 703 down_read(&nilfs->ns_segctor_sem);
698 cno = nilfs->ns_cno - 1; 704 cno = nilfs->ns_cno - 1;
699 up_read(&nilfs->ns_segctor_sem); 705 up_read(&nilfs->ns_segctor_sem);
diff --git a/fs/nilfs2/namei.c b/fs/nilfs2/namei.c
index 0bb2c2010b95..b72847988b78 100644
--- a/fs/nilfs2/namei.c
+++ b/fs/nilfs2/namei.c
@@ -508,31 +508,29 @@ static struct dentry *nilfs_fh_to_parent(struct super_block *sb, struct fid *fh,
508 return nilfs_get_dentry(sb, fid->cno, fid->parent_ino, fid->parent_gen); 508 return nilfs_get_dentry(sb, fid->cno, fid->parent_ino, fid->parent_gen);
509} 509}
510 510
511static int nilfs_encode_fh(struct dentry *dentry, __u32 *fh, int *lenp, 511static int nilfs_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
512 int connectable) 512 struct inode *parent)
513{ 513{
514 struct nilfs_fid *fid = (struct nilfs_fid *)fh; 514 struct nilfs_fid *fid = (struct nilfs_fid *)fh;
515 struct inode *inode = dentry->d_inode;
516 struct nilfs_root *root = NILFS_I(inode)->i_root; 515 struct nilfs_root *root = NILFS_I(inode)->i_root;
517 int type; 516 int type;
518 517
519 if (*lenp < NILFS_FID_SIZE_NON_CONNECTABLE || 518 if (parent && *lenp < NILFS_FID_SIZE_CONNECTABLE) {
520 (connectable && *lenp < NILFS_FID_SIZE_CONNECTABLE)) 519 *lenp = NILFS_FID_SIZE_CONNECTABLE;
520 return 255;
521 }
522 if (*lenp < NILFS_FID_SIZE_NON_CONNECTABLE) {
523 *lenp = NILFS_FID_SIZE_NON_CONNECTABLE;
521 return 255; 524 return 255;
525 }
522 526
523 fid->cno = root->cno; 527 fid->cno = root->cno;
524 fid->ino = inode->i_ino; 528 fid->ino = inode->i_ino;
525 fid->gen = inode->i_generation; 529 fid->gen = inode->i_generation;
526 530
527 if (connectable && !S_ISDIR(inode->i_mode)) { 531 if (parent) {
528 struct inode *parent;
529
530 spin_lock(&dentry->d_lock);
531 parent = dentry->d_parent->d_inode;
532 fid->parent_ino = parent->i_ino; 532 fid->parent_ino = parent->i_ino;
533 fid->parent_gen = parent->i_generation; 533 fid->parent_gen = parent->i_generation;
534 spin_unlock(&dentry->d_lock);
535
536 type = FILEID_NILFS_WITH_PARENT; 534 type = FILEID_NILFS_WITH_PARENT;
537 *lenp = NILFS_FID_SIZE_CONNECTABLE; 535 *lenp = NILFS_FID_SIZE_CONNECTABLE;
538 } else { 536 } else {
diff --git a/fs/nls/Kconfig b/fs/nls/Kconfig
index a39edc41becc..e2ce79ef48c4 100644
--- a/fs/nls/Kconfig
+++ b/fs/nls/Kconfig
@@ -30,7 +30,7 @@ config NLS_DEFAULT
30 cp949, cp950, cp1251, cp1255, euc-jp, euc-kr, gb2312, iso8859-1, 30 cp949, cp950, cp1251, cp1255, euc-jp, euc-kr, gb2312, iso8859-1,
31 iso8859-2, iso8859-3, iso8859-4, iso8859-5, iso8859-6, iso8859-7, 31 iso8859-2, iso8859-3, iso8859-4, iso8859-5, iso8859-6, iso8859-7,
32 iso8859-8, iso8859-9, iso8859-13, iso8859-14, iso8859-15, 32 iso8859-8, iso8859-9, iso8859-13, iso8859-14, iso8859-15,
33 koi8-r, koi8-ru, koi8-u, sjis, tis-620, utf8. 33 koi8-r, koi8-ru, koi8-u, sjis, tis-620, macroman, utf8.
34 If you specify a wrong value, it will use the built-in NLS; 34 If you specify a wrong value, it will use the built-in NLS;
35 compatible with iso8859-1. 35 compatible with iso8859-1.
36 36
@@ -452,6 +452,161 @@ config NLS_KOI8_U
452 input/output character sets. Say Y here for the preferred Ukrainian 452 input/output character sets. Say Y here for the preferred Ukrainian
453 (koi8-u) and Belarusian (koi8-ru) character sets. 453 (koi8-u) and Belarusian (koi8-ru) character sets.
454 454
455config NLS_MAC_ROMAN
456 tristate "Codepage macroman"
457 ---help---
458 The Apple HFS file system family can deal with filenames in
459 native language character sets. These character sets are stored in
460 so-called MAC codepages. You need to include the appropriate
461 codepage if you want to be able to read/write these filenames on
462 Mac partitions correctly. This does apply to the filenames
463 only, not to the file contents. You can include several codepages;
464 say Y here if you want to include the Mac codepage that is used for
465 much of Europe -- United Kingdom, Germany, Spain, Italy, and [add
466 more countries here].
467
468 If unsure, say Y.
469
470config NLS_MAC_CELTIC
471 tristate "Codepage macceltic"
472 ---help---
473 The Apple HFS file system family can deal with filenames in
474 native language character sets. These character sets are stored in
475 so-called MAC codepages. You need to include the appropriate
476 codepage if you want to be able to read/write these filenames on
477 Mac partitions correctly. This does apply to the filenames
478 only, not to the file contents. You can include several codepages;
479 say Y here if you want to include the Mac codepage that is used for
480 Celtic.
481
482 If unsure, say Y.
483
484config NLS_MAC_CENTEURO
485 tristate "Codepage maccenteuro"
486 ---help---
487 The Apple HFS file system family can deal with filenames in
488 native language character sets. These character sets are stored in
489 so-called MAC codepages. You need to include the appropriate
490 codepage if you want to be able to read/write these filenames on
491 Mac partitions correctly. This does apply to the filenames
492 only, not to the file contents. You can include several codepages;
493 say Y here if you want to include the Mac codepage that is used for
494 Central Europe.
495
496 If unsure, say Y.
497
498config NLS_MAC_CROATIAN
499 tristate "Codepage maccroatian"
500 ---help---
501 The Apple HFS file system family can deal with filenames in
502 native language character sets. These character sets are stored in
503 so-called MAC codepages. You need to include the appropriate
504 codepage if you want to be able to read/write these filenames on
505 Mac partitions correctly. This does apply to the filenames
506 only, not to the file contents. You can include several codepages;
507 say Y here if you want to include the Mac codepage that is used for
508 Croatian.
509
510 If unsure, say Y.
511
512config NLS_MAC_CYRILLIC
513 tristate "Codepage maccyrillic"
514 ---help---
515 The Apple HFS file system family can deal with filenames in
516 native language character sets. These character sets are stored in
517 so-called MAC codepages. You need to include the appropriate
518 codepage if you want to be able to read/write these filenames on
519 Mac partitions correctly. This does apply to the filenames
520 only, not to the file contents. You can include several codepages;
521 say Y here if you want to include the Mac codepage that is used for
522 Cyrillic.
523
524 If unsure, say Y.
525
526config NLS_MAC_GAELIC
527 tristate "Codepage macgaelic"
528 ---help---
529 The Apple HFS file system family can deal with filenames in
530 native language character sets. These character sets are stored in
531 so-called MAC codepages. You need to include the appropriate
532 codepage if you want to be able to read/write these filenames on
533 Mac partitions correctly. This does apply to the filenames
534 only, not to the file contents. You can include several codepages;
535 say Y here if you want to include the Mac codepage that is used for
536 Gaelic.
537
538 If unsure, say Y.
539
540config NLS_MAC_GREEK
541 tristate "Codepage macgreek"
542 ---help---
543 The Apple HFS file system family can deal with filenames in
544 native language character sets. These character sets are stored in
545 so-called MAC codepages. You need to include the appropriate
546 codepage if you want to be able to read/write these filenames on
547 Mac partitions correctly. This does apply to the filenames
548 only, not to the file contents. You can include several codepages;
549 say Y here if you want to include the Mac codepage that is used for
550 Greek.
551
552 If unsure, say Y.
553
554config NLS_MAC_ICELAND
555 tristate "Codepage maciceland"
556 ---help---
557 The Apple HFS file system family can deal with filenames in
558 native language character sets. These character sets are stored in
559 so-called MAC codepages. You need to include the appropriate
560 codepage if you want to be able to read/write these filenames on
561 Mac partitions correctly. This does apply to the filenames
562 only, not to the file contents. You can include several codepages;
563 say Y here if you want to include the Mac codepage that is used for
564 Iceland.
565
566 If unsure, say Y.
567
568config NLS_MAC_INUIT
569 tristate "Codepage macinuit"
570 ---help---
571 The Apple HFS file system family can deal with filenames in
572 native language character sets. These character sets are stored in
573 so-called MAC codepages. You need to include the appropriate
574 codepage if you want to be able to read/write these filenames on
575 Mac partitions correctly. This does apply to the filenames
576 only, not to the file contents. You can include several codepages;
577 say Y here if you want to include the Mac codepage that is used for
578 Inuit.
579
580 If unsure, say Y.
581
582config NLS_MAC_ROMANIAN
583 tristate "Codepage macromanian"
584 ---help---
585 The Apple HFS file system family can deal with filenames in
586 native language character sets. These character sets are stored in
587 so-called MAC codepages. You need to include the appropriate
588 codepage if you want to be able to read/write these filenames on
589 Mac partitions correctly. This does apply to the filenames
590 only, not to the file contents. You can include several codepages;
591 say Y here if you want to include the Mac codepage that is used for
592 Romanian.
593
594 If unsure, say Y.
595
596config NLS_MAC_TURKISH
597 tristate "Codepage macturkish"
598 ---help---
599 The Apple HFS file system family can deal with filenames in
600 native language character sets. These character sets are stored in
601 so-called MAC codepages. You need to include the appropriate
602 codepage if you want to be able to read/write these filenames on
603 Mac partitions correctly. This does apply to the filenames
604 only, not to the file contents. You can include several codepages;
605 say Y here if you want to include the Mac codepage that is used for
606 Turkish.
607
608 If unsure, say Y.
609
455config NLS_UTF8 610config NLS_UTF8
456 tristate "NLS UTF-8" 611 tristate "NLS UTF-8"
457 help 612 help
diff --git a/fs/nls/Makefile b/fs/nls/Makefile
index f499dd7c3905..8ae37c1b5249 100644
--- a/fs/nls/Makefile
+++ b/fs/nls/Makefile
@@ -42,3 +42,14 @@ obj-$(CONFIG_NLS_ISO8859_15) += nls_iso8859-15.o
42obj-$(CONFIG_NLS_KOI8_R) += nls_koi8-r.o 42obj-$(CONFIG_NLS_KOI8_R) += nls_koi8-r.o
43obj-$(CONFIG_NLS_KOI8_U) += nls_koi8-u.o nls_koi8-ru.o 43obj-$(CONFIG_NLS_KOI8_U) += nls_koi8-u.o nls_koi8-ru.o
44obj-$(CONFIG_NLS_UTF8) += nls_utf8.o 44obj-$(CONFIG_NLS_UTF8) += nls_utf8.o
45obj-$(CONFIG_NLS_MAC_CELTIC) += mac-celtic.o
46obj-$(CONFIG_NLS_MAC_CENTEURO) += mac-centeuro.o
47obj-$(CONFIG_NLS_MAC_CROATIAN) += mac-croatian.o
48obj-$(CONFIG_NLS_MAC_CYRILLIC) += mac-cyrillic.o
49obj-$(CONFIG_NLS_MAC_GAELIC) += mac-gaelic.o
50obj-$(CONFIG_NLS_MAC_GREEK) += mac-greek.o
51obj-$(CONFIG_NLS_MAC_ICELAND) += mac-iceland.o
52obj-$(CONFIG_NLS_MAC_INUIT) += mac-inuit.o
53obj-$(CONFIG_NLS_MAC_ROMANIAN) += mac-romanian.o
54obj-$(CONFIG_NLS_MAC_ROMAN) += mac-roman.o
55obj-$(CONFIG_NLS_MAC_TURKISH) += mac-turkish.o
diff --git a/fs/nls/mac-celtic.c b/fs/nls/mac-celtic.c
new file mode 100644
index 000000000000..634a8b717b02
--- /dev/null
+++ b/fs/nls/mac-celtic.c
@@ -0,0 +1,602 @@
1/*
2 * linux/fs/nls/mac-celtic.c
3 *
4 * Charset macceltic translation tables.
5 * Generated automatically from the Unicode and charset
6 * tables from the Unicode Organization (www.unicode.org).
7 * The Unicode to charset table has only exact mappings.
8 */
9
10/*
11 * COPYRIGHT AND PERMISSION NOTICE
12 *
13 * Copyright 1991-2012 Unicode, Inc. All rights reserved. Distributed under
14 * the Terms of Use in http://www.unicode.org/copyright.html.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of the Unicode data files and any associated documentation (the "Data
18 * Files") or Unicode software and any associated documentation (the
19 * "Software") to deal in the Data Files or Software without restriction,
20 * including without limitation the rights to use, copy, modify, merge,
21 * publish, distribute, and/or sell copies of the Data Files or Software, and
22 * to permit persons to whom the Data Files or Software are furnished to do
23 * so, provided that (a) the above copyright notice(s) and this permission
24 * notice appear with all copies of the Data Files or Software, (b) both the
25 * above copyright notice(s) and this permission notice appear in associated
26 * documentation, and (c) there is clear notice in each modified Data File or
27 * in the Software as well as in the documentation associated with the Data
28 * File(s) or Software that the data or software has been modified.
29 *
30 * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
33 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
34 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
35 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
36 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38 * PERFORMANCE OF THE DATA FILES OR SOFTWARE.
39 *
40 * Except as contained in this notice, the name of a copyright holder shall
41 * not be used in advertising or otherwise to promote the sale, use or other
42 * dealings in these Data Files or Software without prior written
43 * authorization of the copyright holder.
44 */
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/nls.h>
50#include <linux/errno.h>
51
52static const wchar_t charset2uni[256] = {
53 /* 0x00 */
54 0x0000, 0x0001, 0x0002, 0x0003,
55 0x0004, 0x0005, 0x0006, 0x0007,
56 0x0008, 0x0009, 0x000a, 0x000b,
57 0x000c, 0x000d, 0x000e, 0x000f,
58 /* 0x10 */
59 0x0010, 0x0011, 0x0012, 0x0013,
60 0x0014, 0x0015, 0x0016, 0x0017,
61 0x0018, 0x0019, 0x001a, 0x001b,
62 0x001c, 0x001d, 0x001e, 0x001f,
63 /* 0x20 */
64 0x0020, 0x0021, 0x0022, 0x0023,
65 0x0024, 0x0025, 0x0026, 0x0027,
66 0x0028, 0x0029, 0x002a, 0x002b,
67 0x002c, 0x002d, 0x002e, 0x002f,
68 /* 0x30 */
69 0x0030, 0x0031, 0x0032, 0x0033,
70 0x0034, 0x0035, 0x0036, 0x0037,
71 0x0038, 0x0039, 0x003a, 0x003b,
72 0x003c, 0x003d, 0x003e, 0x003f,
73 /* 0x40 */
74 0x0040, 0x0041, 0x0042, 0x0043,
75 0x0044, 0x0045, 0x0046, 0x0047,
76 0x0048, 0x0049, 0x004a, 0x004b,
77 0x004c, 0x004d, 0x004e, 0x004f,
78 /* 0x50 */
79 0x0050, 0x0051, 0x0052, 0x0053,
80 0x0054, 0x0055, 0x0056, 0x0057,
81 0x0058, 0x0059, 0x005a, 0x005b,
82 0x005c, 0x005d, 0x005e, 0x005f,
83 /* 0x60 */
84 0x0060, 0x0061, 0x0062, 0x0063,
85 0x0064, 0x0065, 0x0066, 0x0067,
86 0x0068, 0x0069, 0x006a, 0x006b,
87 0x006c, 0x006d, 0x006e, 0x006f,
88 /* 0x70 */
89 0x0070, 0x0071, 0x0072, 0x0073,
90 0x0074, 0x0075, 0x0076, 0x0077,
91 0x0078, 0x0079, 0x007a, 0x007b,
92 0x007c, 0x007d, 0x007e, 0x007f,
93 /* 0x80 */
94 0x00c4, 0x00c5, 0x00c7, 0x00c9,
95 0x00d1, 0x00d6, 0x00dc, 0x00e1,
96 0x00e0, 0x00e2, 0x00e4, 0x00e3,
97 0x00e5, 0x00e7, 0x00e9, 0x00e8,
98 /* 0x90 */
99 0x00ea, 0x00eb, 0x00ed, 0x00ec,
100 0x00ee, 0x00ef, 0x00f1, 0x00f3,
101 0x00f2, 0x00f4, 0x00f6, 0x00f5,
102 0x00fa, 0x00f9, 0x00fb, 0x00fc,
103 /* 0xa0 */
104 0x2020, 0x00b0, 0x00a2, 0x00a3,
105 0x00a7, 0x2022, 0x00b6, 0x00df,
106 0x00ae, 0x00a9, 0x2122, 0x00b4,
107 0x00a8, 0x2260, 0x00c6, 0x00d8,
108 /* 0xb0 */
109 0x221e, 0x00b1, 0x2264, 0x2265,
110 0x00a5, 0x00b5, 0x2202, 0x2211,
111 0x220f, 0x03c0, 0x222b, 0x00aa,
112 0x00ba, 0x03a9, 0x00e6, 0x00f8,
113 /* 0xc0 */
114 0x00bf, 0x00a1, 0x00ac, 0x221a,
115 0x0192, 0x2248, 0x2206, 0x00ab,
116 0x00bb, 0x2026, 0x00a0, 0x00c0,
117 0x00c3, 0x00d5, 0x0152, 0x0153,
118 /* 0xd0 */
119 0x2013, 0x2014, 0x201c, 0x201d,
120 0x2018, 0x2019, 0x00f7, 0x25ca,
121 0x00ff, 0x0178, 0x2044, 0x20ac,
122 0x2039, 0x203a, 0x0176, 0x0177,
123 /* 0xe0 */
124 0x2021, 0x00b7, 0x1ef2, 0x1ef3,
125 0x2030, 0x00c2, 0x00ca, 0x00c1,
126 0x00cb, 0x00c8, 0x00cd, 0x00ce,
127 0x00cf, 0x00cc, 0x00d3, 0x00d4,
128 /* 0xf0 */
129 0x2663, 0x00d2, 0x00da, 0x00db,
130 0x00d9, 0x0131, 0x00dd, 0x00fd,
131 0x0174, 0x0175, 0x1e84, 0x1e85,
132 0x1e80, 0x1e81, 0x1e82, 0x1e83,
133};
134
135static const unsigned char page00[256] = {
136 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00-0x07 */
137 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08-0x0f */
138 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10-0x17 */
139 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18-0x1f */
140 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20-0x27 */
141 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28-0x2f */
142 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30-0x37 */
143 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38-0x3f */
144 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40-0x47 */
145 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* 0x48-0x4f */
146 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50-0x57 */
147 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, /* 0x58-0x5f */
148 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60-0x67 */
149 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, /* 0x68-0x6f */
150 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70-0x77 */
151 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, /* 0x78-0x7f */
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
156 0xca, 0xc1, 0xa2, 0xa3, 0x00, 0xb4, 0x00, 0xa4, /* 0xa0-0xa7 */
157 0xac, 0xa9, 0xbb, 0xc7, 0xc2, 0x00, 0xa8, 0x00, /* 0xa8-0xaf */
158 0xa1, 0xb1, 0x00, 0x00, 0xab, 0xb5, 0xa6, 0xe1, /* 0xb0-0xb7 */
159 0x00, 0x00, 0xbc, 0xc8, 0x00, 0x00, 0x00, 0xc0, /* 0xb8-0xbf */
160 0xcb, 0xe7, 0xe5, 0xcc, 0x80, 0x81, 0xae, 0x82, /* 0xc0-0xc7 */
161 0xe9, 0x83, 0xe6, 0xe8, 0xed, 0xea, 0xeb, 0xec, /* 0xc8-0xcf */
162 0x00, 0x84, 0xf1, 0xee, 0xef, 0xcd, 0x85, 0x00, /* 0xd0-0xd7 */
163 0xaf, 0xf4, 0xf2, 0xf3, 0x86, 0xf6, 0x00, 0xa7, /* 0xd8-0xdf */
164 0x88, 0x87, 0x89, 0x8b, 0x8a, 0x8c, 0xbe, 0x8d, /* 0xe0-0xe7 */
165 0x8f, 0x8e, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, /* 0xe8-0xef */
166 0x00, 0x96, 0x98, 0x97, 0x99, 0x9b, 0x9a, 0xd6, /* 0xf0-0xf7 */
167 0xbf, 0x9d, 0x9c, 0x9e, 0x9f, 0xf7, 0x00, 0xd8, /* 0xf8-0xff */
168};
169
170static const unsigned char page01[256] = {
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
177 0x00, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
181 0x00, 0x00, 0xce, 0xcf, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
185 0x00, 0x00, 0x00, 0x00, 0xf8, 0xf9, 0xde, 0xdf, /* 0x70-0x77 */
186 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
189 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
203};
204
205static const unsigned char page03[256] = {
206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
227 0x00, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
230 0xb9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
238};
239
240static const unsigned char page1e[256] = {
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
257 0xfc, 0xfd, 0xfe, 0xff, 0xfa, 0xfb, 0x00, 0x00, /* 0x80-0x87 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
271 0x00, 0x00, 0xe2, 0xe3, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
273};
274
275static const unsigned char page20[256] = {
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
278 0x00, 0x00, 0x00, 0xd0, 0xd1, 0x00, 0x00, 0x00, /* 0x10-0x17 */
279 0xd4, 0xd5, 0x00, 0x00, 0xd2, 0xd3, 0x00, 0x00, /* 0x18-0x1f */
280 0xa0, 0xe0, 0xa5, 0x00, 0x00, 0x00, 0xc9, 0x00, /* 0x20-0x27 */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
282 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
283 0x00, 0xdc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
284 0x00, 0x00, 0x00, 0x00, 0xda, 0x00, 0x00, 0x00, /* 0x40-0x47 */
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
297 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
308};
309
310static const unsigned char page21[256] = {
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
315 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
336 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
343};
344
345static const unsigned char page22[256] = {
346 0x00, 0x00, 0xb6, 0x00, 0x00, 0x00, 0xc6, 0x00, /* 0x00-0x07 */
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, /* 0x08-0x0f */
348 0x00, 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
349 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0xb0, 0x00, /* 0x18-0x1f */
350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
351 0x00, 0x00, 0x00, 0xba, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
355 0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
358 0xad, 0x00, 0x00, 0x00, 0xb2, 0xb3, 0x00, 0x00, /* 0x60-0x67 */
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
361 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
365 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
366 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
367 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
371 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
373 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
376 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
378};
379
380static const unsigned char page25[256] = {
381 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
382 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
385 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
386 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
387 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
388 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
390 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
391 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
392 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
393 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
394 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
399 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
401 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
405 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
406 0x00, 0x00, 0xd7, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
407 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
408 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
409 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
410 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
411 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
412 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
413};
414
415static const unsigned char page26[256] = {
416 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
417 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
418 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
422 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
424 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
425 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
426 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
427 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
428 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
429 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
430 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
433 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
434 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
435 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
436 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
437 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
439 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
440 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
441 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
442 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
443 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
444 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
445 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
446 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
447 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
448};
449
450static const unsigned char *const page_uni2charset[256] = {
451 page00, page01, NULL, page03, NULL, NULL, NULL, NULL,
452 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
453 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
454 NULL, NULL, NULL, NULL, NULL, NULL, page1e, NULL,
455 page20, page21, page22, NULL, NULL, page25, page26, NULL,
456 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
457 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
458 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
459 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
460 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
461 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
462 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
463 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
464 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
465 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
466 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
467 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
468 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
469 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
470 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
471 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
472 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
473 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
474 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
475 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
476 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
477 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
478 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
479 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
480 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
481 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
482 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
483};
484
485static const unsigned char charset2lower[256] = {
486 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
487 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
488 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
489 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
490 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
491 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
492 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
493 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
494 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
495 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
496 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
497 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
498 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
499 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
500 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
501 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
502 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
503 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
504 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
505 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
506 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
507 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
508 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
509 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
510 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
511 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
512 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
513 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
514 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
515 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
516 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
517 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
518};
519
520static const unsigned char charset2upper[256] = {
521 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x00-0x07 */
522 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x08-0x0f */
523 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x10-0x17 */
524 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x18-0x1f */
525 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x20-0x27 */
526 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x28-0x2f */
527 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x30-0x37 */
528 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x38-0x3f */
529 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x40-0x47 */
530 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x48-0x4f */
531 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x50-0x57 */
532 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x58-0x5f */
533 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x60-0x67 */
534 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x68-0x6f */
535 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x70-0x77 */
536 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x78-0x7f */
537 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x80-0x87 */
538 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x88-0x8f */
539 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x90-0x97 */
540 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x98-0x9f */
541 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xa0-0xa7 */
542 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xa8-0xaf */
543 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xb0-0xb7 */
544 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xb8-0xbf */
545 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xc0-0xc7 */
546 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xc8-0xcf */
547 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xd0-0xd7 */
548 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xd8-0xdf */
549 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xe0-0xe7 */
550 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xe8-0xef */
551 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xf0-0xf7 */
552 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xf8-0xff */
553};
554
555static int uni2char(wchar_t uni, unsigned char *out, int boundlen)
556{
557 const unsigned char *uni2charset;
558 unsigned char cl = uni & 0x00ff;
559 unsigned char ch = (uni & 0xff00) >> 8;
560
561 if (boundlen <= 0)
562 return -ENAMETOOLONG;
563
564 uni2charset = page_uni2charset[ch];
565 if (uni2charset && uni2charset[cl])
566 out[0] = uni2charset[cl];
567 else
568 return -EINVAL;
569 return 1;
570}
571
572static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
573{
574 *uni = charset2uni[*rawstring];
575 if (*uni == 0x0000)
576 return -EINVAL;
577 return 1;
578}
579
580static struct nls_table table = {
581 .charset = "macceltic",
582 .uni2char = uni2char,
583 .char2uni = char2uni,
584 .charset2lower = charset2lower,
585 .charset2upper = charset2upper,
586 .owner = THIS_MODULE,
587};
588
589static int __init init_nls_macceltic(void)
590{
591 return register_nls(&table);
592}
593
594static void __exit exit_nls_macceltic(void)
595{
596 unregister_nls(&table);
597}
598
599module_init(init_nls_macceltic)
600module_exit(exit_nls_macceltic)
601
602MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/nls/mac-centeuro.c b/fs/nls/mac-centeuro.c
new file mode 100644
index 000000000000..979e6265ac5e
--- /dev/null
+++ b/fs/nls/mac-centeuro.c
@@ -0,0 +1,532 @@
1/*
2 * linux/fs/nls/mac-centeuro.c
3 *
4 * Charset maccenteuro translation tables.
5 * Generated automatically from the Unicode and charset
6 * tables from the Unicode Organization (www.unicode.org).
7 * The Unicode to charset table has only exact mappings.
8 */
9
10/*
11 * COPYRIGHT AND PERMISSION NOTICE
12 *
13 * Copyright 1991-2012 Unicode, Inc. All rights reserved. Distributed under
14 * the Terms of Use in http://www.unicode.org/copyright.html.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of the Unicode data files and any associated documentation (the "Data
18 * Files") or Unicode software and any associated documentation (the
19 * "Software") to deal in the Data Files or Software without restriction,
20 * including without limitation the rights to use, copy, modify, merge,
21 * publish, distribute, and/or sell copies of the Data Files or Software, and
22 * to permit persons to whom the Data Files or Software are furnished to do
23 * so, provided that (a) the above copyright notice(s) and this permission
24 * notice appear with all copies of the Data Files or Software, (b) both the
25 * above copyright notice(s) and this permission notice appear in associated
26 * documentation, and (c) there is clear notice in each modified Data File or
27 * in the Software as well as in the documentation associated with the Data
28 * File(s) or Software that the data or software has been modified.
29 *
30 * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
33 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
34 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
35 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
36 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38 * PERFORMANCE OF THE DATA FILES OR SOFTWARE.
39 *
40 * Except as contained in this notice, the name of a copyright holder shall
41 * not be used in advertising or otherwise to promote the sale, use or other
42 * dealings in these Data Files or Software without prior written
43 * authorization of the copyright holder.
44 */
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/nls.h>
50#include <linux/errno.h>
51
52static const wchar_t charset2uni[256] = {
53 /* 0x00 */
54 0x0000, 0x0001, 0x0002, 0x0003,
55 0x0004, 0x0005, 0x0006, 0x0007,
56 0x0008, 0x0009, 0x000a, 0x000b,
57 0x000c, 0x000d, 0x000e, 0x000f,
58 /* 0x10 */
59 0x0010, 0x0011, 0x0012, 0x0013,
60 0x0014, 0x0015, 0x0016, 0x0017,
61 0x0018, 0x0019, 0x001a, 0x001b,
62 0x001c, 0x001d, 0x001e, 0x001f,
63 /* 0x20 */
64 0x0020, 0x0021, 0x0022, 0x0023,
65 0x0024, 0x0025, 0x0026, 0x0027,
66 0x0028, 0x0029, 0x002a, 0x002b,
67 0x002c, 0x002d, 0x002e, 0x002f,
68 /* 0x30 */
69 0x0030, 0x0031, 0x0032, 0x0033,
70 0x0034, 0x0035, 0x0036, 0x0037,
71 0x0038, 0x0039, 0x003a, 0x003b,
72 0x003c, 0x003d, 0x003e, 0x003f,
73 /* 0x40 */
74 0x0040, 0x0041, 0x0042, 0x0043,
75 0x0044, 0x0045, 0x0046, 0x0047,
76 0x0048, 0x0049, 0x004a, 0x004b,
77 0x004c, 0x004d, 0x004e, 0x004f,
78 /* 0x50 */
79 0x0050, 0x0051, 0x0052, 0x0053,
80 0x0054, 0x0055, 0x0056, 0x0057,
81 0x0058, 0x0059, 0x005a, 0x005b,
82 0x005c, 0x005d, 0x005e, 0x005f,
83 /* 0x60 */
84 0x0060, 0x0061, 0x0062, 0x0063,
85 0x0064, 0x0065, 0x0066, 0x0067,
86 0x0068, 0x0069, 0x006a, 0x006b,
87 0x006c, 0x006d, 0x006e, 0x006f,
88 /* 0x70 */
89 0x0070, 0x0071, 0x0072, 0x0073,
90 0x0074, 0x0075, 0x0076, 0x0077,
91 0x0078, 0x0079, 0x007a, 0x007b,
92 0x007c, 0x007d, 0x007e, 0x007f,
93 /* 0x80 */
94 0x00c4, 0x0100, 0x0101, 0x00c9,
95 0x0104, 0x00d6, 0x00dc, 0x00e1,
96 0x0105, 0x010c, 0x00e4, 0x010d,
97 0x0106, 0x0107, 0x00e9, 0x0179,
98 /* 0x90 */
99 0x017a, 0x010e, 0x00ed, 0x010f,
100 0x0112, 0x0113, 0x0116, 0x00f3,
101 0x0117, 0x00f4, 0x00f6, 0x00f5,
102 0x00fa, 0x011a, 0x011b, 0x00fc,
103 /* 0xa0 */
104 0x2020, 0x00b0, 0x0118, 0x00a3,
105 0x00a7, 0x2022, 0x00b6, 0x00df,
106 0x00ae, 0x00a9, 0x2122, 0x0119,
107 0x00a8, 0x2260, 0x0123, 0x012e,
108 /* 0xb0 */
109 0x012f, 0x012a, 0x2264, 0x2265,
110 0x012b, 0x0136, 0x2202, 0x2211,
111 0x0142, 0x013b, 0x013c, 0x013d,
112 0x013e, 0x0139, 0x013a, 0x0145,
113 /* 0xc0 */
114 0x0146, 0x0143, 0x00ac, 0x221a,
115 0x0144, 0x0147, 0x2206, 0x00ab,
116 0x00bb, 0x2026, 0x00a0, 0x0148,
117 0x0150, 0x00d5, 0x0151, 0x014c,
118 /* 0xd0 */
119 0x2013, 0x2014, 0x201c, 0x201d,
120 0x2018, 0x2019, 0x00f7, 0x25ca,
121 0x014d, 0x0154, 0x0155, 0x0158,
122 0x2039, 0x203a, 0x0159, 0x0156,
123 /* 0xe0 */
124 0x0157, 0x0160, 0x201a, 0x201e,
125 0x0161, 0x015a, 0x015b, 0x00c1,
126 0x0164, 0x0165, 0x00cd, 0x017d,
127 0x017e, 0x016a, 0x00d3, 0x00d4,
128 /* 0xf0 */
129 0x016b, 0x016e, 0x00da, 0x016f,
130 0x0170, 0x0171, 0x0172, 0x0173,
131 0x00dd, 0x00fd, 0x0137, 0x017b,
132 0x0141, 0x017c, 0x0122, 0x02c7,
133};
134
135static const unsigned char page00[256] = {
136 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00-0x07 */
137 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08-0x0f */
138 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10-0x17 */
139 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18-0x1f */
140 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20-0x27 */
141 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28-0x2f */
142 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30-0x37 */
143 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38-0x3f */
144 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40-0x47 */
145 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* 0x48-0x4f */
146 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50-0x57 */
147 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, /* 0x58-0x5f */
148 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60-0x67 */
149 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, /* 0x68-0x6f */
150 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70-0x77 */
151 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, /* 0x78-0x7f */
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
156 0xca, 0x00, 0x00, 0xa3, 0x00, 0x00, 0x00, 0xa4, /* 0xa0-0xa7 */
157 0xac, 0xa9, 0x00, 0xc7, 0xc2, 0x00, 0xa8, 0x00, /* 0xa8-0xaf */
158 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa6, 0x00, /* 0xb0-0xb7 */
159 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
160 0x00, 0xe7, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
161 0x00, 0x83, 0x00, 0x00, 0x00, 0xea, 0x00, 0x00, /* 0xc8-0xcf */
162 0x00, 0x00, 0x00, 0xee, 0xef, 0xcd, 0x85, 0x00, /* 0xd0-0xd7 */
163 0x00, 0x00, 0xf2, 0x00, 0x86, 0xf8, 0x00, 0xa7, /* 0xd8-0xdf */
164 0x00, 0x87, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
165 0x00, 0x8e, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, /* 0xe8-0xef */
166 0x00, 0x00, 0x00, 0x97, 0x99, 0x9b, 0x9a, 0xd6, /* 0xf0-0xf7 */
167 0x00, 0x00, 0x9c, 0x00, 0x9f, 0xf9, 0x00, 0x00, /* 0xf8-0xff */
168};
169
170static const unsigned char page01[256] = {
171 0x81, 0x82, 0x00, 0x00, 0x84, 0x88, 0x8c, 0x8d, /* 0x00-0x07 */
172 0x00, 0x00, 0x00, 0x00, 0x89, 0x8b, 0x91, 0x93, /* 0x08-0x0f */
173 0x00, 0x00, 0x94, 0x95, 0x00, 0x00, 0x96, 0x98, /* 0x10-0x17 */
174 0xa2, 0xab, 0x9d, 0x9e, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
175 0x00, 0x00, 0xfe, 0xae, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
176 0x00, 0x00, 0xb1, 0xb4, 0x00, 0x00, 0xaf, 0xb0, /* 0x28-0x2f */
177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb5, 0xfa, /* 0x30-0x37 */
178 0x00, 0xbd, 0xbe, 0xb9, 0xba, 0xbb, 0xbc, 0x00, /* 0x38-0x3f */
179 0x00, 0xfc, 0xb8, 0xc1, 0xc4, 0xbf, 0xc0, 0xc5, /* 0x40-0x47 */
180 0xcb, 0x00, 0x00, 0x00, 0xcf, 0xd8, 0x00, 0x00, /* 0x48-0x4f */
181 0xcc, 0xce, 0x00, 0x00, 0xd9, 0xda, 0xdf, 0xe0, /* 0x50-0x57 */
182 0xdb, 0xde, 0xe5, 0xe6, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
183 0xe1, 0xe4, 0x00, 0x00, 0xe8, 0xe9, 0x00, 0x00, /* 0x60-0x67 */
184 0x00, 0x00, 0xed, 0xf0, 0x00, 0x00, 0xf1, 0xf3, /* 0x68-0x6f */
185 0xf4, 0xf5, 0xf6, 0xf7, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
186 0x00, 0x8f, 0x90, 0xfb, 0xfd, 0xeb, 0xec, 0x00, /* 0x78-0x7f */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
189 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
203};
204
205static const unsigned char page02[256] = {
206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, /* 0xc0-0xc7 */
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
238};
239
240static const unsigned char page20[256] = {
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
243 0x00, 0x00, 0x00, 0xd0, 0xd1, 0x00, 0x00, 0x00, /* 0x10-0x17 */
244 0xd4, 0xd5, 0xe2, 0x00, 0xd2, 0xd3, 0xe3, 0x00, /* 0x18-0x1f */
245 0xa0, 0x00, 0xa5, 0x00, 0x00, 0x00, 0xc9, 0x00, /* 0x20-0x27 */
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
248 0x00, 0xdc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
273};
274
275static const unsigned char page21[256] = {
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
280 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
308};
309
310static const unsigned char page22[256] = {
311 0x00, 0x00, 0xb6, 0x00, 0x00, 0x00, 0xc6, 0x00, /* 0x00-0x07 */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
313 0x00, 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
314 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
315 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
323 0xad, 0x00, 0x00, 0x00, 0xb2, 0xb3, 0x00, 0x00, /* 0x60-0x67 */
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
336 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
343};
344
345static const unsigned char page25[256] = {
346 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
348 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
349 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
351 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
358 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
361 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
365 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
366 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
367 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
371 0x00, 0x00, 0xd7, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
373 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
376 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
378};
379
380static const unsigned char *const page_uni2charset[256] = {
381 page00, page01, page02, NULL, NULL, NULL, NULL, NULL,
382 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
383 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
384 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
385 page20, page21, page22, NULL, NULL, page25, NULL, NULL,
386 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
387 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
388 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
389 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
390 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
391 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
392 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
393 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
394 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
395 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
396 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
397 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
398 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
399 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
400 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
401 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
402 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
403 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
404 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
405 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
406 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
407 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
408 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
409 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
410 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
411 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
412 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
413};
414
415static const unsigned char charset2lower[256] = {
416 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
417 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
418 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
419 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
420 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
421 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
422 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
423 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
424 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
425 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
426 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
427 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
428 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
429 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
430 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
431 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
432 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
433 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
434 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
435 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
436 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
437 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
438 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
439 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
440 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
441 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
442 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
443 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
444 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
445 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
446 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
447 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
448};
449
450static const unsigned char charset2upper[256] = {
451 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
452 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
453 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
454 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
455 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
456 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
457 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
458 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
459 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
460 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
461 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
462 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
463 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
464 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
465 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
466 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
467 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
468 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
469 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
470 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
471 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
472 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
473 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
474 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
475 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
476 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
477 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
478 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
479 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
480 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
481 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
482 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
483};
484
485static int uni2char(wchar_t uni, unsigned char *out, int boundlen)
486{
487 const unsigned char *uni2charset;
488 unsigned char cl = uni & 0x00ff;
489 unsigned char ch = (uni & 0xff00) >> 8;
490
491 if (boundlen <= 0)
492 return -ENAMETOOLONG;
493
494 uni2charset = page_uni2charset[ch];
495 if (uni2charset && uni2charset[cl])
496 out[0] = uni2charset[cl];
497 else
498 return -EINVAL;
499 return 1;
500}
501
502static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
503{
504 *uni = charset2uni[*rawstring];
505 if (*uni == 0x0000)
506 return -EINVAL;
507 return 1;
508}
509
510static struct nls_table table = {
511 .charset = "maccenteuro",
512 .uni2char = uni2char,
513 .char2uni = char2uni,
514 .charset2lower = charset2lower,
515 .charset2upper = charset2upper,
516 .owner = THIS_MODULE,
517};
518
519static int __init init_nls_maccenteuro(void)
520{
521 return register_nls(&table);
522}
523
524static void __exit exit_nls_maccenteuro(void)
525{
526 unregister_nls(&table);
527}
528
529module_init(init_nls_maccenteuro)
530module_exit(exit_nls_maccenteuro)
531
532MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/nls/mac-croatian.c b/fs/nls/mac-croatian.c
new file mode 100644
index 000000000000..dd3f675911ee
--- /dev/null
+++ b/fs/nls/mac-croatian.c
@@ -0,0 +1,602 @@
1/*
2 * linux/fs/nls/mac-croatian.c
3 *
4 * Charset maccroatian translation tables.
5 * Generated automatically from the Unicode and charset
6 * tables from the Unicode Organization (www.unicode.org).
7 * The Unicode to charset table has only exact mappings.
8 */
9
10/*
11 * COPYRIGHT AND PERMISSION NOTICE
12 *
13 * Copyright 1991-2012 Unicode, Inc. All rights reserved. Distributed under
14 * the Terms of Use in http://www.unicode.org/copyright.html.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of the Unicode data files and any associated documentation (the "Data
18 * Files") or Unicode software and any associated documentation (the
19 * "Software") to deal in the Data Files or Software without restriction,
20 * including without limitation the rights to use, copy, modify, merge,
21 * publish, distribute, and/or sell copies of the Data Files or Software, and
22 * to permit persons to whom the Data Files or Software are furnished to do
23 * so, provided that (a) the above copyright notice(s) and this permission
24 * notice appear with all copies of the Data Files or Software, (b) both the
25 * above copyright notice(s) and this permission notice appear in associated
26 * documentation, and (c) there is clear notice in each modified Data File or
27 * in the Software as well as in the documentation associated with the Data
28 * File(s) or Software that the data or software has been modified.
29 *
30 * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
33 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
34 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
35 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
36 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38 * PERFORMANCE OF THE DATA FILES OR SOFTWARE.
39 *
40 * Except as contained in this notice, the name of a copyright holder shall
41 * not be used in advertising or otherwise to promote the sale, use or other
42 * dealings in these Data Files or Software without prior written
43 * authorization of the copyright holder.
44 */
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/nls.h>
50#include <linux/errno.h>
51
52static const wchar_t charset2uni[256] = {
53 /* 0x00 */
54 0x0000, 0x0001, 0x0002, 0x0003,
55 0x0004, 0x0005, 0x0006, 0x0007,
56 0x0008, 0x0009, 0x000a, 0x000b,
57 0x000c, 0x000d, 0x000e, 0x000f,
58 /* 0x10 */
59 0x0010, 0x0011, 0x0012, 0x0013,
60 0x0014, 0x0015, 0x0016, 0x0017,
61 0x0018, 0x0019, 0x001a, 0x001b,
62 0x001c, 0x001d, 0x001e, 0x001f,
63 /* 0x20 */
64 0x0020, 0x0021, 0x0022, 0x0023,
65 0x0024, 0x0025, 0x0026, 0x0027,
66 0x0028, 0x0029, 0x002a, 0x002b,
67 0x002c, 0x002d, 0x002e, 0x002f,
68 /* 0x30 */
69 0x0030, 0x0031, 0x0032, 0x0033,
70 0x0034, 0x0035, 0x0036, 0x0037,
71 0x0038, 0x0039, 0x003a, 0x003b,
72 0x003c, 0x003d, 0x003e, 0x003f,
73 /* 0x40 */
74 0x0040, 0x0041, 0x0042, 0x0043,
75 0x0044, 0x0045, 0x0046, 0x0047,
76 0x0048, 0x0049, 0x004a, 0x004b,
77 0x004c, 0x004d, 0x004e, 0x004f,
78 /* 0x50 */
79 0x0050, 0x0051, 0x0052, 0x0053,
80 0x0054, 0x0055, 0x0056, 0x0057,
81 0x0058, 0x0059, 0x005a, 0x005b,
82 0x005c, 0x005d, 0x005e, 0x005f,
83 /* 0x60 */
84 0x0060, 0x0061, 0x0062, 0x0063,
85 0x0064, 0x0065, 0x0066, 0x0067,
86 0x0068, 0x0069, 0x006a, 0x006b,
87 0x006c, 0x006d, 0x006e, 0x006f,
88 /* 0x70 */
89 0x0070, 0x0071, 0x0072, 0x0073,
90 0x0074, 0x0075, 0x0076, 0x0077,
91 0x0078, 0x0079, 0x007a, 0x007b,
92 0x007c, 0x007d, 0x007e, 0x007f,
93 /* 0x80 */
94 0x00c4, 0x00c5, 0x00c7, 0x00c9,
95 0x00d1, 0x00d6, 0x00dc, 0x00e1,
96 0x00e0, 0x00e2, 0x00e4, 0x00e3,
97 0x00e5, 0x00e7, 0x00e9, 0x00e8,
98 /* 0x90 */
99 0x00ea, 0x00eb, 0x00ed, 0x00ec,
100 0x00ee, 0x00ef, 0x00f1, 0x00f3,
101 0x00f2, 0x00f4, 0x00f6, 0x00f5,
102 0x00fa, 0x00f9, 0x00fb, 0x00fc,
103 /* 0xa0 */
104 0x2020, 0x00b0, 0x00a2, 0x00a3,
105 0x00a7, 0x2022, 0x00b6, 0x00df,
106 0x00ae, 0x0160, 0x2122, 0x00b4,
107 0x00a8, 0x2260, 0x017d, 0x00d8,
108 /* 0xb0 */
109 0x221e, 0x00b1, 0x2264, 0x2265,
110 0x2206, 0x00b5, 0x2202, 0x2211,
111 0x220f, 0x0161, 0x222b, 0x00aa,
112 0x00ba, 0x03a9, 0x017e, 0x00f8,
113 /* 0xc0 */
114 0x00bf, 0x00a1, 0x00ac, 0x221a,
115 0x0192, 0x2248, 0x0106, 0x00ab,
116 0x010c, 0x2026, 0x00a0, 0x00c0,
117 0x00c3, 0x00d5, 0x0152, 0x0153,
118 /* 0xd0 */
119 0x0110, 0x2014, 0x201c, 0x201d,
120 0x2018, 0x2019, 0x00f7, 0x25ca,
121 0xf8ff, 0x00a9, 0x2044, 0x20ac,
122 0x2039, 0x203a, 0x00c6, 0x00bb,
123 /* 0xe0 */
124 0x2013, 0x00b7, 0x201a, 0x201e,
125 0x2030, 0x00c2, 0x0107, 0x00c1,
126 0x010d, 0x00c8, 0x00cd, 0x00ce,
127 0x00cf, 0x00cc, 0x00d3, 0x00d4,
128 /* 0xf0 */
129 0x0111, 0x00d2, 0x00da, 0x00db,
130 0x00d9, 0x0131, 0x02c6, 0x02dc,
131 0x00af, 0x03c0, 0x00cb, 0x02da,
132 0x00b8, 0x00ca, 0x00e6, 0x02c7,
133};
134
135static const unsigned char page00[256] = {
136 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00-0x07 */
137 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08-0x0f */
138 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10-0x17 */
139 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18-0x1f */
140 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20-0x27 */
141 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28-0x2f */
142 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30-0x37 */
143 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38-0x3f */
144 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40-0x47 */
145 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* 0x48-0x4f */
146 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50-0x57 */
147 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, /* 0x58-0x5f */
148 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60-0x67 */
149 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, /* 0x68-0x6f */
150 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70-0x77 */
151 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, /* 0x78-0x7f */
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
156 0xca, 0xc1, 0xa2, 0xa3, 0x00, 0x00, 0x00, 0xa4, /* 0xa0-0xa7 */
157 0xac, 0xd9, 0xbb, 0xc7, 0xc2, 0x00, 0xa8, 0xf8, /* 0xa8-0xaf */
158 0xa1, 0xb1, 0x00, 0x00, 0xab, 0xb5, 0xa6, 0xe1, /* 0xb0-0xb7 */
159 0xfc, 0x00, 0xbc, 0xdf, 0x00, 0x00, 0x00, 0xc0, /* 0xb8-0xbf */
160 0xcb, 0xe7, 0xe5, 0xcc, 0x80, 0x81, 0xde, 0x82, /* 0xc0-0xc7 */
161 0xe9, 0x83, 0xfd, 0xfa, 0xed, 0xea, 0xeb, 0xec, /* 0xc8-0xcf */
162 0x00, 0x84, 0xf1, 0xee, 0xef, 0xcd, 0x85, 0x00, /* 0xd0-0xd7 */
163 0xaf, 0xf4, 0xf2, 0xf3, 0x86, 0x00, 0x00, 0xa7, /* 0xd8-0xdf */
164 0x88, 0x87, 0x89, 0x8b, 0x8a, 0x8c, 0xfe, 0x8d, /* 0xe0-0xe7 */
165 0x8f, 0x8e, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, /* 0xe8-0xef */
166 0x00, 0x96, 0x98, 0x97, 0x99, 0x9b, 0x9a, 0xd6, /* 0xf0-0xf7 */
167 0xbf, 0x9d, 0x9c, 0x9e, 0x9f, 0x00, 0x00, 0x00, /* 0xf8-0xff */
168};
169
170static const unsigned char page01[256] = {
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xe6, /* 0x00-0x07 */
172 0x00, 0x00, 0x00, 0x00, 0xc8, 0xe8, 0x00, 0x00, /* 0x08-0x0f */
173 0xd0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
177 0x00, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
181 0x00, 0x00, 0xce, 0xcf, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
183 0xa9, 0xb9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
186 0x00, 0x00, 0x00, 0x00, 0x00, 0xae, 0xbe, 0x00, /* 0x78-0x7f */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
189 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
203};
204
205static const unsigned char page02[256] = {
206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xff, /* 0xc0-0xc7 */
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
233 0x00, 0x00, 0xfb, 0x00, 0xf7, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
238};
239
240static const unsigned char page03[256] = {
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
262 0x00, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
265 0xf9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
273};
274
275static const unsigned char page20[256] = {
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
278 0x00, 0x00, 0x00, 0xe0, 0xd1, 0x00, 0x00, 0x00, /* 0x10-0x17 */
279 0xd4, 0xd5, 0xe2, 0x00, 0xd2, 0xd3, 0xe3, 0x00, /* 0x18-0x1f */
280 0xa0, 0x00, 0xa5, 0x00, 0x00, 0x00, 0xc9, 0x00, /* 0x20-0x27 */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
282 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
283 0x00, 0xdc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
284 0x00, 0x00, 0x00, 0x00, 0xda, 0x00, 0x00, 0x00, /* 0x40-0x47 */
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
297 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
308};
309
310static const unsigned char page21[256] = {
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
315 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
336 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
343};
344
345static const unsigned char page22[256] = {
346 0x00, 0x00, 0xb6, 0x00, 0x00, 0x00, 0xb4, 0x00, /* 0x00-0x07 */
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, /* 0x08-0x0f */
348 0x00, 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
349 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0xb0, 0x00, /* 0x18-0x1f */
350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
351 0x00, 0x00, 0x00, 0xba, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
355 0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
358 0xad, 0x00, 0x00, 0x00, 0xb2, 0xb3, 0x00, 0x00, /* 0x60-0x67 */
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
361 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
365 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
366 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
367 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
371 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
373 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
376 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
378};
379
380static const unsigned char page25[256] = {
381 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
382 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
385 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
386 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
387 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
388 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
390 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
391 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
392 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
393 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
394 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
399 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
401 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
405 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
406 0x00, 0x00, 0xd7, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
407 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
408 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
409 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
410 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
411 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
412 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
413};
414
415static const unsigned char pagef8[256] = {
416 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
417 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
418 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
422 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
424 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
425 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
426 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
427 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
428 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
429 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
430 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
433 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
434 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
435 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
436 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
437 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
439 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
440 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
441 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
442 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
443 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
444 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
445 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
446 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
447 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, /* 0xf8-0xff */
448};
449
450static const unsigned char *const page_uni2charset[256] = {
451 page00, page01, page02, page03, NULL, NULL, NULL, NULL,
452 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
453 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
454 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
455 page20, page21, page22, NULL, NULL, page25, NULL, NULL,
456 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
457 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
458 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
459 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
460 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
461 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
462 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
463 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
464 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
465 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
466 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
467 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
468 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
469 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
470 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
471 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
472 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
473 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
474 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
475 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
476 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
477 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
478 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
479 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
480 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
481 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
482 pagef8, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
483};
484
485static const unsigned char charset2lower[256] = {
486 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
487 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
488 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
489 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
490 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
491 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
492 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
493 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
494 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
495 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
496 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
497 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
498 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
499 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
500 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
501 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
502 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
503 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
504 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
505 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
506 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
507 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
508 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
509 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
510 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
511 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
512 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
513 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
514 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
515 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
516 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
517 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
518};
519
520static const unsigned char charset2upper[256] = {
521 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
522 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
523 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
524 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
525 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
526 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
527 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
528 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
529 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
530 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
531 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
532 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
533 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
534 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
535 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
536 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
537 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
538 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
539 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
540 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
541 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
542 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
543 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
544 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
545 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
546 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
547 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
548 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
549 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
550 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
551 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
552 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
553};
554
555static int uni2char(wchar_t uni, unsigned char *out, int boundlen)
556{
557 const unsigned char *uni2charset;
558 unsigned char cl = uni & 0x00ff;
559 unsigned char ch = (uni & 0xff00) >> 8;
560
561 if (boundlen <= 0)
562 return -ENAMETOOLONG;
563
564 uni2charset = page_uni2charset[ch];
565 if (uni2charset && uni2charset[cl])
566 out[0] = uni2charset[cl];
567 else
568 return -EINVAL;
569 return 1;
570}
571
572static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
573{
574 *uni = charset2uni[*rawstring];
575 if (*uni == 0x0000)
576 return -EINVAL;
577 return 1;
578}
579
580static struct nls_table table = {
581 .charset = "maccroatian",
582 .uni2char = uni2char,
583 .char2uni = char2uni,
584 .charset2lower = charset2lower,
585 .charset2upper = charset2upper,
586 .owner = THIS_MODULE,
587};
588
589static int __init init_nls_maccroatian(void)
590{
591 return register_nls(&table);
592}
593
594static void __exit exit_nls_maccroatian(void)
595{
596 unregister_nls(&table);
597}
598
599module_init(init_nls_maccroatian)
600module_exit(exit_nls_maccroatian)
601
602MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/nls/mac-cyrillic.c b/fs/nls/mac-cyrillic.c
new file mode 100644
index 000000000000..1112c84dd8bb
--- /dev/null
+++ b/fs/nls/mac-cyrillic.c
@@ -0,0 +1,497 @@
1/*
2 * linux/fs/nls/mac-cyrillic.c
3 *
4 * Charset maccyrillic translation tables.
5 * Generated automatically from the Unicode and charset
6 * tables from the Unicode Organization (www.unicode.org).
7 * The Unicode to charset table has only exact mappings.
8 */
9
10/*
11 * COPYRIGHT AND PERMISSION NOTICE
12 *
13 * Copyright 1991-2012 Unicode, Inc. All rights reserved. Distributed under
14 * the Terms of Use in http://www.unicode.org/copyright.html.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of the Unicode data files and any associated documentation (the "Data
18 * Files") or Unicode software and any associated documentation (the
19 * "Software") to deal in the Data Files or Software without restriction,
20 * including without limitation the rights to use, copy, modify, merge,
21 * publish, distribute, and/or sell copies of the Data Files or Software, and
22 * to permit persons to whom the Data Files or Software are furnished to do
23 * so, provided that (a) the above copyright notice(s) and this permission
24 * notice appear with all copies of the Data Files or Software, (b) both the
25 * above copyright notice(s) and this permission notice appear in associated
26 * documentation, and (c) there is clear notice in each modified Data File or
27 * in the Software as well as in the documentation associated with the Data
28 * File(s) or Software that the data or software has been modified.
29 *
30 * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
33 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
34 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
35 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
36 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38 * PERFORMANCE OF THE DATA FILES OR SOFTWARE.
39 *
40 * Except as contained in this notice, the name of a copyright holder shall
41 * not be used in advertising or otherwise to promote the sale, use or other
42 * dealings in these Data Files or Software without prior written
43 * authorization of the copyright holder.
44 */
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/nls.h>
50#include <linux/errno.h>
51
52static const wchar_t charset2uni[256] = {
53 /* 0x00 */
54 0x0000, 0x0001, 0x0002, 0x0003,
55 0x0004, 0x0005, 0x0006, 0x0007,
56 0x0008, 0x0009, 0x000a, 0x000b,
57 0x000c, 0x000d, 0x000e, 0x000f,
58 /* 0x10 */
59 0x0010, 0x0011, 0x0012, 0x0013,
60 0x0014, 0x0015, 0x0016, 0x0017,
61 0x0018, 0x0019, 0x001a, 0x001b,
62 0x001c, 0x001d, 0x001e, 0x001f,
63 /* 0x20 */
64 0x0020, 0x0021, 0x0022, 0x0023,
65 0x0024, 0x0025, 0x0026, 0x0027,
66 0x0028, 0x0029, 0x002a, 0x002b,
67 0x002c, 0x002d, 0x002e, 0x002f,
68 /* 0x30 */
69 0x0030, 0x0031, 0x0032, 0x0033,
70 0x0034, 0x0035, 0x0036, 0x0037,
71 0x0038, 0x0039, 0x003a, 0x003b,
72 0x003c, 0x003d, 0x003e, 0x003f,
73 /* 0x40 */
74 0x0040, 0x0041, 0x0042, 0x0043,
75 0x0044, 0x0045, 0x0046, 0x0047,
76 0x0048, 0x0049, 0x004a, 0x004b,
77 0x004c, 0x004d, 0x004e, 0x004f,
78 /* 0x50 */
79 0x0050, 0x0051, 0x0052, 0x0053,
80 0x0054, 0x0055, 0x0056, 0x0057,
81 0x0058, 0x0059, 0x005a, 0x005b,
82 0x005c, 0x005d, 0x005e, 0x005f,
83 /* 0x60 */
84 0x0060, 0x0061, 0x0062, 0x0063,
85 0x0064, 0x0065, 0x0066, 0x0067,
86 0x0068, 0x0069, 0x006a, 0x006b,
87 0x006c, 0x006d, 0x006e, 0x006f,
88 /* 0x70 */
89 0x0070, 0x0071, 0x0072, 0x0073,
90 0x0074, 0x0075, 0x0076, 0x0077,
91 0x0078, 0x0079, 0x007a, 0x007b,
92 0x007c, 0x007d, 0x007e, 0x007f,
93 /* 0x80 */
94 0x0410, 0x0411, 0x0412, 0x0413,
95 0x0414, 0x0415, 0x0416, 0x0417,
96 0x0418, 0x0419, 0x041a, 0x041b,
97 0x041c, 0x041d, 0x041e, 0x041f,
98 /* 0x90 */
99 0x0420, 0x0421, 0x0422, 0x0423,
100 0x0424, 0x0425, 0x0426, 0x0427,
101 0x0428, 0x0429, 0x042a, 0x042b,
102 0x042c, 0x042d, 0x042e, 0x042f,
103 /* 0xa0 */
104 0x2020, 0x00b0, 0x0490, 0x00a3,
105 0x00a7, 0x2022, 0x00b6, 0x0406,
106 0x00ae, 0x00a9, 0x2122, 0x0402,
107 0x0452, 0x2260, 0x0403, 0x0453,
108 /* 0xb0 */
109 0x221e, 0x00b1, 0x2264, 0x2265,
110 0x0456, 0x00b5, 0x0491, 0x0408,
111 0x0404, 0x0454, 0x0407, 0x0457,
112 0x0409, 0x0459, 0x040a, 0x045a,
113 /* 0xc0 */
114 0x0458, 0x0405, 0x00ac, 0x221a,
115 0x0192, 0x2248, 0x2206, 0x00ab,
116 0x00bb, 0x2026, 0x00a0, 0x040b,
117 0x045b, 0x040c, 0x045c, 0x0455,
118 /* 0xd0 */
119 0x2013, 0x2014, 0x201c, 0x201d,
120 0x2018, 0x2019, 0x00f7, 0x201e,
121 0x040e, 0x045e, 0x040f, 0x045f,
122 0x2116, 0x0401, 0x0451, 0x044f,
123 /* 0xe0 */
124 0x0430, 0x0431, 0x0432, 0x0433,
125 0x0434, 0x0435, 0x0436, 0x0437,
126 0x0438, 0x0439, 0x043a, 0x043b,
127 0x043c, 0x043d, 0x043e, 0x043f,
128 /* 0xf0 */
129 0x0440, 0x0441, 0x0442, 0x0443,
130 0x0444, 0x0445, 0x0446, 0x0447,
131 0x0448, 0x0449, 0x044a, 0x044b,
132 0x044c, 0x044d, 0x044e, 0x20ac,
133};
134
135static const unsigned char page00[256] = {
136 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00-0x07 */
137 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08-0x0f */
138 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10-0x17 */
139 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18-0x1f */
140 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20-0x27 */
141 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28-0x2f */
142 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30-0x37 */
143 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38-0x3f */
144 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40-0x47 */
145 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* 0x48-0x4f */
146 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50-0x57 */
147 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, /* 0x58-0x5f */
148 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60-0x67 */
149 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, /* 0x68-0x6f */
150 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70-0x77 */
151 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, /* 0x78-0x7f */
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
156 0xca, 0x00, 0x00, 0xa3, 0x00, 0x00, 0x00, 0xa4, /* 0xa0-0xa7 */
157 0x00, 0xa9, 0x00, 0xc7, 0xc2, 0x00, 0xa8, 0x00, /* 0xa8-0xaf */
158 0xa1, 0xb1, 0x00, 0x00, 0x00, 0xb5, 0xa6, 0x00, /* 0xb0-0xb7 */
159 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
164 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
166 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, /* 0xf0-0xf7 */
167 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
168};
169
170static const unsigned char page01[256] = {
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
181 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
186 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
189 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
203};
204
205static const unsigned char page04[256] = {
206 0x00, 0xdd, 0xab, 0xae, 0xb8, 0xc1, 0xa7, 0xba, /* 0x00-0x07 */
207 0xb7, 0xbc, 0xbe, 0xcb, 0xcd, 0x00, 0xd8, 0xda, /* 0x08-0x0f */
208 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, /* 0x10-0x17 */
209 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, /* 0x18-0x1f */
210 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, /* 0x20-0x27 */
211 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, /* 0x28-0x2f */
212 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, /* 0x30-0x37 */
213 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, /* 0x38-0x3f */
214 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, /* 0x40-0x47 */
215 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xdf, /* 0x48-0x4f */
216 0x00, 0xde, 0xac, 0xaf, 0xb9, 0xcf, 0xb4, 0xbb, /* 0x50-0x57 */
217 0xc0, 0xbd, 0xbf, 0xcc, 0xce, 0x00, 0xd9, 0xdb, /* 0x58-0x5f */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
224 0xa2, 0xb6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
238};
239
240static const unsigned char page20[256] = {
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
243 0x00, 0x00, 0x00, 0xd0, 0xd1, 0x00, 0x00, 0x00, /* 0x10-0x17 */
244 0xd4, 0xd5, 0x00, 0x00, 0xd2, 0xd3, 0xd7, 0x00, /* 0x18-0x1f */
245 0xa0, 0x00, 0xa5, 0x00, 0x00, 0x00, 0xc9, 0x00, /* 0x20-0x27 */
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
262 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
273};
274
275static const unsigned char page21[256] = {
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x00, /* 0x10-0x17 */
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
280 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
308};
309
310static const unsigned char page22[256] = {
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, /* 0x00-0x07 */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
314 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0xb0, 0x00, /* 0x18-0x1f */
315 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
320 0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
323 0xad, 0x00, 0x00, 0x00, 0xb2, 0xb3, 0x00, 0x00, /* 0x60-0x67 */
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
336 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
343};
344
345static const unsigned char *const page_uni2charset[256] = {
346 page00, page01, NULL, NULL, page04, NULL, NULL, NULL,
347 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
348 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
349 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
350 page20, page21, page22, NULL, NULL, NULL, NULL, NULL,
351 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
352 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
353 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
354 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
355 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
356 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
357 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
358 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
359 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
360 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
361 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
362 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
363 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
364 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
365 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
366 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
367 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
368 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
369 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
370 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
371 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
372 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
373 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
374 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
375 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
376 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
377 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
378};
379
380static const unsigned char charset2lower[256] = {
381 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
382 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
383 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
384 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
385 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
386 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
387 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
388 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
389 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
390 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
391 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
392 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
393 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
394 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
395 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
396 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
397 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
398 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
399 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
400 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
401 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
402 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
403 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
404 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
405 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
406 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
407 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
408 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
409 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
410 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
411 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
412 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
413};
414
415static const unsigned char charset2upper[256] = {
416 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
417 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
418 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
419 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
420 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
421 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
422 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
423 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
424 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
425 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
426 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
427 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
428 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
429 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
430 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
431 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
432 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
433 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
434 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
435 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
436 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
437 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
438 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
439 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
440 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
441 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
442 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
443 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
444 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
445 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
446 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
447 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
448};
449
450static int uni2char(wchar_t uni, unsigned char *out, int boundlen)
451{
452 const unsigned char *uni2charset;
453 unsigned char cl = uni & 0x00ff;
454 unsigned char ch = (uni & 0xff00) >> 8;
455
456 if (boundlen <= 0)
457 return -ENAMETOOLONG;
458
459 uni2charset = page_uni2charset[ch];
460 if (uni2charset && uni2charset[cl])
461 out[0] = uni2charset[cl];
462 else
463 return -EINVAL;
464 return 1;
465}
466
467static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
468{
469 *uni = charset2uni[*rawstring];
470 if (*uni == 0x0000)
471 return -EINVAL;
472 return 1;
473}
474
475static struct nls_table table = {
476 .charset = "maccyrillic",
477 .uni2char = uni2char,
478 .char2uni = char2uni,
479 .charset2lower = charset2lower,
480 .charset2upper = charset2upper,
481 .owner = THIS_MODULE,
482};
483
484static int __init init_nls_maccyrillic(void)
485{
486 return register_nls(&table);
487}
488
489static void __exit exit_nls_maccyrillic(void)
490{
491 unregister_nls(&table);
492}
493
494module_init(init_nls_maccyrillic)
495module_exit(exit_nls_maccyrillic)
496
497MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/nls/mac-gaelic.c b/fs/nls/mac-gaelic.c
new file mode 100644
index 000000000000..2de9158409c8
--- /dev/null
+++ b/fs/nls/mac-gaelic.c
@@ -0,0 +1,567 @@
1/*
2 * linux/fs/nls/mac-gaelic.c
3 *
4 * Charset macgaelic translation tables.
5 * Generated automatically from the Unicode and charset
6 * tables from the Unicode Organization (www.unicode.org).
7 * The Unicode to charset table has only exact mappings.
8 */
9
10/*
11 * COPYRIGHT AND PERMISSION NOTICE
12 *
13 * Copyright 1991-2012 Unicode, Inc. All rights reserved. Distributed under
14 * the Terms of Use in http://www.unicode.org/copyright.html.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of the Unicode data files and any associated documentation (the "Data
18 * Files") or Unicode software and any associated documentation (the
19 * "Software") to deal in the Data Files or Software without restriction,
20 * including without limitation the rights to use, copy, modify, merge,
21 * publish, distribute, and/or sell copies of the Data Files or Software, and
22 * to permit persons to whom the Data Files or Software are furnished to do
23 * so, provided that (a) the above copyright notice(s) and this permission
24 * notice appear with all copies of the Data Files or Software, (b) both the
25 * above copyright notice(s) and this permission notice appear in associated
26 * documentation, and (c) there is clear notice in each modified Data File or
27 * in the Software as well as in the documentation associated with the Data
28 * File(s) or Software that the data or software has been modified.
29 *
30 * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
33 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
34 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
35 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
36 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38 * PERFORMANCE OF THE DATA FILES OR SOFTWARE.
39 *
40 * Except as contained in this notice, the name of a copyright holder shall
41 * not be used in advertising or otherwise to promote the sale, use or other
42 * dealings in these Data Files or Software without prior written
43 * authorization of the copyright holder.
44 */
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/nls.h>
50#include <linux/errno.h>
51
52static const wchar_t charset2uni[256] = {
53 /* 0x00 */
54 0x0000, 0x0001, 0x0002, 0x0003,
55 0x0004, 0x0005, 0x0006, 0x0007,
56 0x0008, 0x0009, 0x000a, 0x000b,
57 0x000c, 0x000d, 0x000e, 0x000f,
58 /* 0x10 */
59 0x0010, 0x0011, 0x0012, 0x0013,
60 0x0014, 0x0015, 0x0016, 0x0017,
61 0x0018, 0x0019, 0x001a, 0x001b,
62 0x001c, 0x001d, 0x001e, 0x001f,
63 /* 0x20 */
64 0x0020, 0x0021, 0x0022, 0x0023,
65 0x0024, 0x0025, 0x0026, 0x0027,
66 0x0028, 0x0029, 0x002a, 0x002b,
67 0x002c, 0x002d, 0x002e, 0x002f,
68 /* 0x30 */
69 0x0030, 0x0031, 0x0032, 0x0033,
70 0x0034, 0x0035, 0x0036, 0x0037,
71 0x0038, 0x0039, 0x003a, 0x003b,
72 0x003c, 0x003d, 0x003e, 0x003f,
73 /* 0x40 */
74 0x0040, 0x0041, 0x0042, 0x0043,
75 0x0044, 0x0045, 0x0046, 0x0047,
76 0x0048, 0x0049, 0x004a, 0x004b,
77 0x004c, 0x004d, 0x004e, 0x004f,
78 /* 0x50 */
79 0x0050, 0x0051, 0x0052, 0x0053,
80 0x0054, 0x0055, 0x0056, 0x0057,
81 0x0058, 0x0059, 0x005a, 0x005b,
82 0x005c, 0x005d, 0x005e, 0x005f,
83 /* 0x60 */
84 0x0060, 0x0061, 0x0062, 0x0063,
85 0x0064, 0x0065, 0x0066, 0x0067,
86 0x0068, 0x0069, 0x006a, 0x006b,
87 0x006c, 0x006d, 0x006e, 0x006f,
88 /* 0x70 */
89 0x0070, 0x0071, 0x0072, 0x0073,
90 0x0074, 0x0075, 0x0076, 0x0077,
91 0x0078, 0x0079, 0x007a, 0x007b,
92 0x007c, 0x007d, 0x007e, 0x007f,
93 /* 0x80 */
94 0x00c4, 0x00c5, 0x00c7, 0x00c9,
95 0x00d1, 0x00d6, 0x00dc, 0x00e1,
96 0x00e0, 0x00e2, 0x00e4, 0x00e3,
97 0x00e5, 0x00e7, 0x00e9, 0x00e8,
98 /* 0x90 */
99 0x00ea, 0x00eb, 0x00ed, 0x00ec,
100 0x00ee, 0x00ef, 0x00f1, 0x00f3,
101 0x00f2, 0x00f4, 0x00f6, 0x00f5,
102 0x00fa, 0x00f9, 0x00fb, 0x00fc,
103 /* 0xa0 */
104 0x2020, 0x00b0, 0x00a2, 0x00a3,
105 0x00a7, 0x2022, 0x00b6, 0x00df,
106 0x00ae, 0x00a9, 0x2122, 0x00b4,
107 0x00a8, 0x2260, 0x00c6, 0x00d8,
108 /* 0xb0 */
109 0x1e02, 0x00b1, 0x2264, 0x2265,
110 0x1e03, 0x010a, 0x010b, 0x1e0a,
111 0x1e0b, 0x1e1e, 0x1e1f, 0x0120,
112 0x0121, 0x1e40, 0x00e6, 0x00f8,
113 /* 0xc0 */
114 0x1e41, 0x1e56, 0x1e57, 0x027c,
115 0x0192, 0x017f, 0x1e60, 0x00ab,
116 0x00bb, 0x2026, 0x00a0, 0x00c0,
117 0x00c3, 0x00d5, 0x0152, 0x0153,
118 /* 0xd0 */
119 0x2013, 0x2014, 0x201c, 0x201d,
120 0x2018, 0x2019, 0x1e61, 0x1e9b,
121 0x00ff, 0x0178, 0x1e6a, 0x20ac,
122 0x2039, 0x203a, 0x0176, 0x0177,
123 /* 0xe0 */
124 0x1e6b, 0x00b7, 0x1ef2, 0x1ef3,
125 0x204a, 0x00c2, 0x00ca, 0x00c1,
126 0x00cb, 0x00c8, 0x00cd, 0x00ce,
127 0x00cf, 0x00cc, 0x00d3, 0x00d4,
128 /* 0xf0 */
129 0x2663, 0x00d2, 0x00da, 0x00db,
130 0x00d9, 0x0131, 0x00dd, 0x00fd,
131 0x0174, 0x0175, 0x1e84, 0x1e85,
132 0x1e80, 0x1e81, 0x1e82, 0x1e83,
133};
134
135static const unsigned char page00[256] = {
136 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00-0x07 */
137 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08-0x0f */
138 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10-0x17 */
139 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18-0x1f */
140 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20-0x27 */
141 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28-0x2f */
142 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30-0x37 */
143 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38-0x3f */
144 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40-0x47 */
145 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* 0x48-0x4f */
146 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50-0x57 */
147 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, /* 0x58-0x5f */
148 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60-0x67 */
149 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, /* 0x68-0x6f */
150 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70-0x77 */
151 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, /* 0x78-0x7f */
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
156 0xca, 0x00, 0xa2, 0xa3, 0x00, 0x00, 0x00, 0xa4, /* 0xa0-0xa7 */
157 0xac, 0xa9, 0x00, 0xc7, 0x00, 0x00, 0xa8, 0x00, /* 0xa8-0xaf */
158 0xa1, 0xb1, 0x00, 0x00, 0xab, 0x00, 0xa6, 0xe1, /* 0xb0-0xb7 */
159 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
160 0xcb, 0xe7, 0xe5, 0xcc, 0x80, 0x81, 0xae, 0x82, /* 0xc0-0xc7 */
161 0xe9, 0x83, 0xe6, 0xe8, 0xed, 0xea, 0xeb, 0xec, /* 0xc8-0xcf */
162 0x00, 0x84, 0xf1, 0xee, 0xef, 0xcd, 0x85, 0x00, /* 0xd0-0xd7 */
163 0xaf, 0xf4, 0xf2, 0xf3, 0x86, 0xf6, 0x00, 0xa7, /* 0xd8-0xdf */
164 0x88, 0x87, 0x89, 0x8b, 0x8a, 0x8c, 0xbe, 0x8d, /* 0xe0-0xe7 */
165 0x8f, 0x8e, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, /* 0xe8-0xef */
166 0x00, 0x96, 0x98, 0x97, 0x99, 0x9b, 0x9a, 0x00, /* 0xf0-0xf7 */
167 0xbf, 0x9d, 0x9c, 0x9e, 0x9f, 0xf7, 0x00, 0xd8, /* 0xf8-0xff */
168};
169
170static const unsigned char page01[256] = {
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
172 0x00, 0x00, 0xb5, 0xb6, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
175 0xbb, 0xbc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
177 0x00, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
181 0x00, 0x00, 0xce, 0xcf, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
185 0x00, 0x00, 0x00, 0x00, 0xf8, 0xf9, 0xde, 0xdf, /* 0x70-0x77 */
186 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, /* 0x78-0x7f */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
189 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
203};
204
205static const unsigned char page02[256] = {
206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
221 0x00, 0x00, 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, /* 0x78-0x7f */
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
238};
239
240static const unsigned char page1e[256] = {
241 0x00, 0x00, 0xb0, 0xb4, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
242 0x00, 0x00, 0xb7, 0xb8, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb9, 0xba, /* 0x18-0x1f */
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
249 0xbd, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0xc2, /* 0x50-0x57 */
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
253 0xc6, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
254 0x00, 0x00, 0xda, 0xe0, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
257 0xfc, 0xfd, 0xfe, 0xff, 0xfa, 0xfb, 0x00, 0x00, /* 0x80-0x87 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
260 0x00, 0x00, 0x00, 0xd7, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
271 0x00, 0x00, 0xe2, 0xe3, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
273};
274
275static const unsigned char page20[256] = {
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
278 0x00, 0x00, 0x00, 0xd0, 0xd1, 0x00, 0x00, 0x00, /* 0x10-0x17 */
279 0xd4, 0xd5, 0x00, 0x00, 0xd2, 0xd3, 0x00, 0x00, /* 0x18-0x1f */
280 0xa0, 0x00, 0xa5, 0x00, 0x00, 0x00, 0xc9, 0x00, /* 0x20-0x27 */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
283 0x00, 0xdc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
285 0x00, 0x00, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
297 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
308};
309
310static const unsigned char page21[256] = {
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
315 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
336 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
343};
344
345static const unsigned char page22[256] = {
346 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
348 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
349 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
351 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
358 0xad, 0x00, 0x00, 0x00, 0xb2, 0xb3, 0x00, 0x00, /* 0x60-0x67 */
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
361 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
365 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
366 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
367 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
371 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
373 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
376 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
378};
379
380static const unsigned char page26[256] = {
381 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
382 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
385 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
386 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
387 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
388 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
390 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
391 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
392 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
393 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
394 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
399 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
401 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
405 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
406 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
407 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
408 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
409 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
410 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
411 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
412 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
413};
414
415static const unsigned char *const page_uni2charset[256] = {
416 page00, page01, page02, NULL, NULL, NULL, NULL, NULL,
417 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
418 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
419 NULL, NULL, NULL, NULL, NULL, NULL, page1e, NULL,
420 page20, page21, page22, NULL, NULL, NULL, page26, NULL,
421 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
422 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
423 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
424 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
425 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
426 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
427 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
428 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
429 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
430 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
431 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
432 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
433 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
434 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
435 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
436 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
437 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
438 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
439 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
440 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
441 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
442 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
443 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
444 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
445 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
446 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
447 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
448};
449
450static const unsigned char charset2lower[256] = {
451 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
452 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
453 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
454 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
455 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
456 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
457 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
458 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
459 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
460 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
461 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
462 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
463 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
464 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
465 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
466 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
467 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
468 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
469 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
470 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
471 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
472 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
473 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
474 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
475 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
476 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
477 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
478 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
479 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
480 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
481 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
482 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
483};
484
485static const unsigned char charset2upper[256] = {
486 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x00-0x07 */
487 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x08-0x0f */
488 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x10-0x17 */
489 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x18-0x1f */
490 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x20-0x27 */
491 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x28-0x2f */
492 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x30-0x37 */
493 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x38-0x3f */
494 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x40-0x47 */
495 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x48-0x4f */
496 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x50-0x57 */
497 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x58-0x5f */
498 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x60-0x67 */
499 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x68-0x6f */
500 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x70-0x77 */
501 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x78-0x7f */
502 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x80-0x87 */
503 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x88-0x8f */
504 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x90-0x97 */
505 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x98-0x9f */
506 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xa0-0xa7 */
507 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xa8-0xaf */
508 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xb0-0xb7 */
509 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xb8-0xbf */
510 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xc0-0xc7 */
511 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xc8-0xcf */
512 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xd0-0xd7 */
513 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xd8-0xdf */
514 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xe0-0xe7 */
515 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xe8-0xef */
516 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xf0-0xf7 */
517 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xf8-0xff */
518};
519
520static int uni2char(wchar_t uni, unsigned char *out, int boundlen)
521{
522 const unsigned char *uni2charset;
523 unsigned char cl = uni & 0x00ff;
524 unsigned char ch = (uni & 0xff00) >> 8;
525
526 if (boundlen <= 0)
527 return -ENAMETOOLONG;
528
529 uni2charset = page_uni2charset[ch];
530 if (uni2charset && uni2charset[cl])
531 out[0] = uni2charset[cl];
532 else
533 return -EINVAL;
534 return 1;
535}
536
537static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
538{
539 *uni = charset2uni[*rawstring];
540 if (*uni == 0x0000)
541 return -EINVAL;
542 return 1;
543}
544
545static struct nls_table table = {
546 .charset = "macgaelic",
547 .uni2char = uni2char,
548 .char2uni = char2uni,
549 .charset2lower = charset2lower,
550 .charset2upper = charset2upper,
551 .owner = THIS_MODULE,
552};
553
554static int __init init_nls_macgaelic(void)
555{
556 return register_nls(&table);
557}
558
559static void __exit exit_nls_macgaelic(void)
560{
561 unregister_nls(&table);
562}
563
564module_init(init_nls_macgaelic)
565module_exit(exit_nls_macgaelic)
566
567MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/nls/mac-greek.c b/fs/nls/mac-greek.c
new file mode 100644
index 000000000000..a86310082802
--- /dev/null
+++ b/fs/nls/mac-greek.c
@@ -0,0 +1,497 @@
1/*
2 * linux/fs/nls/mac-greek.c
3 *
4 * Charset macgreek translation tables.
5 * Generated automatically from the Unicode and charset
6 * tables from the Unicode Organization (www.unicode.org).
7 * The Unicode to charset table has only exact mappings.
8 */
9
10/*
11 * COPYRIGHT AND PERMISSION NOTICE
12 *
13 * Copyright 1991-2012 Unicode, Inc. All rights reserved. Distributed under
14 * the Terms of Use in http://www.unicode.org/copyright.html.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of the Unicode data files and any associated documentation (the "Data
18 * Files") or Unicode software and any associated documentation (the
19 * "Software") to deal in the Data Files or Software without restriction,
20 * including without limitation the rights to use, copy, modify, merge,
21 * publish, distribute, and/or sell copies of the Data Files or Software, and
22 * to permit persons to whom the Data Files or Software are furnished to do
23 * so, provided that (a) the above copyright notice(s) and this permission
24 * notice appear with all copies of the Data Files or Software, (b) both the
25 * above copyright notice(s) and this permission notice appear in associated
26 * documentation, and (c) there is clear notice in each modified Data File or
27 * in the Software as well as in the documentation associated with the Data
28 * File(s) or Software that the data or software has been modified.
29 *
30 * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
33 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
34 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
35 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
36 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38 * PERFORMANCE OF THE DATA FILES OR SOFTWARE.
39 *
40 * Except as contained in this notice, the name of a copyright holder shall
41 * not be used in advertising or otherwise to promote the sale, use or other
42 * dealings in these Data Files or Software without prior written
43 * authorization of the copyright holder.
44 */
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/nls.h>
50#include <linux/errno.h>
51
52static const wchar_t charset2uni[256] = {
53 /* 0x00 */
54 0x0000, 0x0001, 0x0002, 0x0003,
55 0x0004, 0x0005, 0x0006, 0x0007,
56 0x0008, 0x0009, 0x000a, 0x000b,
57 0x000c, 0x000d, 0x000e, 0x000f,
58 /* 0x10 */
59 0x0010, 0x0011, 0x0012, 0x0013,
60 0x0014, 0x0015, 0x0016, 0x0017,
61 0x0018, 0x0019, 0x001a, 0x001b,
62 0x001c, 0x001d, 0x001e, 0x001f,
63 /* 0x20 */
64 0x0020, 0x0021, 0x0022, 0x0023,
65 0x0024, 0x0025, 0x0026, 0x0027,
66 0x0028, 0x0029, 0x002a, 0x002b,
67 0x002c, 0x002d, 0x002e, 0x002f,
68 /* 0x30 */
69 0x0030, 0x0031, 0x0032, 0x0033,
70 0x0034, 0x0035, 0x0036, 0x0037,
71 0x0038, 0x0039, 0x003a, 0x003b,
72 0x003c, 0x003d, 0x003e, 0x003f,
73 /* 0x40 */
74 0x0040, 0x0041, 0x0042, 0x0043,
75 0x0044, 0x0045, 0x0046, 0x0047,
76 0x0048, 0x0049, 0x004a, 0x004b,
77 0x004c, 0x004d, 0x004e, 0x004f,
78 /* 0x50 */
79 0x0050, 0x0051, 0x0052, 0x0053,
80 0x0054, 0x0055, 0x0056, 0x0057,
81 0x0058, 0x0059, 0x005a, 0x005b,
82 0x005c, 0x005d, 0x005e, 0x005f,
83 /* 0x60 */
84 0x0060, 0x0061, 0x0062, 0x0063,
85 0x0064, 0x0065, 0x0066, 0x0067,
86 0x0068, 0x0069, 0x006a, 0x006b,
87 0x006c, 0x006d, 0x006e, 0x006f,
88 /* 0x70 */
89 0x0070, 0x0071, 0x0072, 0x0073,
90 0x0074, 0x0075, 0x0076, 0x0077,
91 0x0078, 0x0079, 0x007a, 0x007b,
92 0x007c, 0x007d, 0x007e, 0x007f,
93 /* 0x80 */
94 0x00c4, 0x00b9, 0x00b2, 0x00c9,
95 0x00b3, 0x00d6, 0x00dc, 0x0385,
96 0x00e0, 0x00e2, 0x00e4, 0x0384,
97 0x00a8, 0x00e7, 0x00e9, 0x00e8,
98 /* 0x90 */
99 0x00ea, 0x00eb, 0x00a3, 0x2122,
100 0x00ee, 0x00ef, 0x2022, 0x00bd,
101 0x2030, 0x00f4, 0x00f6, 0x00a6,
102 0x20ac, 0x00f9, 0x00fb, 0x00fc,
103 /* 0xa0 */
104 0x2020, 0x0393, 0x0394, 0x0398,
105 0x039b, 0x039e, 0x03a0, 0x00df,
106 0x00ae, 0x00a9, 0x03a3, 0x03aa,
107 0x00a7, 0x2260, 0x00b0, 0x00b7,
108 /* 0xb0 */
109 0x0391, 0x00b1, 0x2264, 0x2265,
110 0x00a5, 0x0392, 0x0395, 0x0396,
111 0x0397, 0x0399, 0x039a, 0x039c,
112 0x03a6, 0x03ab, 0x03a8, 0x03a9,
113 /* 0xc0 */
114 0x03ac, 0x039d, 0x00ac, 0x039f,
115 0x03a1, 0x2248, 0x03a4, 0x00ab,
116 0x00bb, 0x2026, 0x00a0, 0x03a5,
117 0x03a7, 0x0386, 0x0388, 0x0153,
118 /* 0xd0 */
119 0x2013, 0x2015, 0x201c, 0x201d,
120 0x2018, 0x2019, 0x00f7, 0x0389,
121 0x038a, 0x038c, 0x038e, 0x03ad,
122 0x03ae, 0x03af, 0x03cc, 0x038f,
123 /* 0xe0 */
124 0x03cd, 0x03b1, 0x03b2, 0x03c8,
125 0x03b4, 0x03b5, 0x03c6, 0x03b3,
126 0x03b7, 0x03b9, 0x03be, 0x03ba,
127 0x03bb, 0x03bc, 0x03bd, 0x03bf,
128 /* 0xf0 */
129 0x03c0, 0x03ce, 0x03c1, 0x03c3,
130 0x03c4, 0x03b8, 0x03c9, 0x03c2,
131 0x03c7, 0x03c5, 0x03b6, 0x03ca,
132 0x03cb, 0x0390, 0x03b0, 0x00ad,
133};
134
135static const unsigned char page00[256] = {
136 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00-0x07 */
137 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08-0x0f */
138 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10-0x17 */
139 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18-0x1f */
140 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20-0x27 */
141 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28-0x2f */
142 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30-0x37 */
143 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38-0x3f */
144 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40-0x47 */
145 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* 0x48-0x4f */
146 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50-0x57 */
147 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, /* 0x58-0x5f */
148 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60-0x67 */
149 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, /* 0x68-0x6f */
150 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70-0x77 */
151 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, /* 0x78-0x7f */
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
156 0xca, 0x00, 0x00, 0x92, 0x00, 0xb4, 0x9b, 0xac, /* 0xa0-0xa7 */
157 0x8c, 0xa9, 0x00, 0xc7, 0xc2, 0xff, 0xa8, 0x00, /* 0xa8-0xaf */
158 0xae, 0xb1, 0x82, 0x84, 0x00, 0x00, 0x00, 0xaf, /* 0xb0-0xb7 */
159 0x00, 0x81, 0x00, 0xc8, 0x00, 0x97, 0x00, 0x00, /* 0xb8-0xbf */
160 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
161 0x00, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x00, /* 0xd0-0xd7 */
163 0x00, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, 0xa7, /* 0xd8-0xdf */
164 0x88, 0x00, 0x89, 0x00, 0x8a, 0x00, 0x00, 0x8d, /* 0xe0-0xe7 */
165 0x8f, 0x8e, 0x90, 0x91, 0x00, 0x00, 0x94, 0x95, /* 0xe8-0xef */
166 0x00, 0x00, 0x00, 0x00, 0x99, 0x00, 0x9a, 0xd6, /* 0xf0-0xf7 */
167 0x00, 0x9d, 0x00, 0x9e, 0x9f, 0x00, 0x00, 0x00, /* 0xf8-0xff */
168};
169
170static const unsigned char page01[256] = {
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
181 0x00, 0x00, 0x00, 0xcf, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
186 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
189 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
203};
204
205static const unsigned char page03[256] = {
206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
222 0x00, 0x00, 0x00, 0x00, 0x8b, 0x87, 0xcd, 0x00, /* 0x80-0x87 */
223 0xce, 0xd7, 0xd8, 0x00, 0xd9, 0x00, 0xda, 0xdf, /* 0x88-0x8f */
224 0xfd, 0xb0, 0xb5, 0xa1, 0xa2, 0xb6, 0xb7, 0xb8, /* 0x90-0x97 */
225 0xa3, 0xb9, 0xba, 0xa4, 0xbb, 0xc1, 0xa5, 0xc3, /* 0x98-0x9f */
226 0xa6, 0xc4, 0x00, 0xaa, 0xc6, 0xcb, 0xbc, 0xcc, /* 0xa0-0xa7 */
227 0xbe, 0xbf, 0xab, 0xbd, 0xc0, 0xdb, 0xdc, 0xdd, /* 0xa8-0xaf */
228 0xfe, 0xe1, 0xe2, 0xe7, 0xe4, 0xe5, 0xfa, 0xe8, /* 0xb0-0xb7 */
229 0xf5, 0xe9, 0xeb, 0xec, 0xed, 0xee, 0xea, 0xef, /* 0xb8-0xbf */
230 0xf0, 0xf2, 0xf7, 0xf3, 0xf4, 0xf9, 0xe6, 0xf8, /* 0xc0-0xc7 */
231 0xe3, 0xf6, 0xfb, 0xfc, 0xde, 0xe0, 0xf1, 0x00, /* 0xc8-0xcf */
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
238};
239
240static const unsigned char page20[256] = {
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
243 0x00, 0x00, 0x00, 0xd0, 0x00, 0xd1, 0x00, 0x00, /* 0x10-0x17 */
244 0xd4, 0xd5, 0x00, 0x00, 0xd2, 0xd3, 0x00, 0x00, /* 0x18-0x1f */
245 0xa0, 0x00, 0x96, 0x00, 0x00, 0x00, 0xc9, 0x00, /* 0x20-0x27 */
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
247 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
262 0x00, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
273};
274
275static const unsigned char page21[256] = {
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
280 0x00, 0x00, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
308};
309
310static const unsigned char page22[256] = {
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
315 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
320 0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
323 0xad, 0x00, 0x00, 0x00, 0xb2, 0xb3, 0x00, 0x00, /* 0x60-0x67 */
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
336 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
343};
344
345static const unsigned char *const page_uni2charset[256] = {
346 page00, page01, NULL, page03, NULL, NULL, NULL, NULL,
347 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
348 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
349 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
350 page20, page21, page22, NULL, NULL, NULL, NULL, NULL,
351 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
352 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
353 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
354 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
355 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
356 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
357 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
358 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
359 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
360 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
361 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
362 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
363 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
364 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
365 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
366 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
367 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
368 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
369 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
370 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
371 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
372 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
373 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
374 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
375 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
376 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
377 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
378};
379
380static const unsigned char charset2lower[256] = {
381 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
382 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
383 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
384 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
385 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
386 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
387 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
388 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
389 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
390 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
391 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
392 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
393 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
394 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
395 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
396 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
397 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
398 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
399 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
400 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
401 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
402 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
403 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
404 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
405 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
406 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
407 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
408 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
409 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
410 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
411 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
412 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
413};
414
415static const unsigned char charset2upper[256] = {
416 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
417 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
418 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
419 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
420 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
421 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
422 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
423 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
424 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
425 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
426 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
427 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
428 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
429 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
430 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
431 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
432 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
433 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
434 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
435 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
436 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
437 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
438 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
439 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
440 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
441 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
442 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
443 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
444 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
445 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
446 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
447 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
448};
449
450static int uni2char(wchar_t uni, unsigned char *out, int boundlen)
451{
452 const unsigned char *uni2charset;
453 unsigned char cl = uni & 0x00ff;
454 unsigned char ch = (uni & 0xff00) >> 8;
455
456 if (boundlen <= 0)
457 return -ENAMETOOLONG;
458
459 uni2charset = page_uni2charset[ch];
460 if (uni2charset && uni2charset[cl])
461 out[0] = uni2charset[cl];
462 else
463 return -EINVAL;
464 return 1;
465}
466
467static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
468{
469 *uni = charset2uni[*rawstring];
470 if (*uni == 0x0000)
471 return -EINVAL;
472 return 1;
473}
474
475static struct nls_table table = {
476 .charset = "macgreek",
477 .uni2char = uni2char,
478 .char2uni = char2uni,
479 .charset2lower = charset2lower,
480 .charset2upper = charset2upper,
481 .owner = THIS_MODULE,
482};
483
484static int __init init_nls_macgreek(void)
485{
486 return register_nls(&table);
487}
488
489static void __exit exit_nls_macgreek(void)
490{
491 unregister_nls(&table);
492}
493
494module_init(init_nls_macgreek)
495module_exit(exit_nls_macgreek)
496
497MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/nls/mac-iceland.c b/fs/nls/mac-iceland.c
new file mode 100644
index 000000000000..babe2998d5ce
--- /dev/null
+++ b/fs/nls/mac-iceland.c
@@ -0,0 +1,602 @@
1/*
2 * linux/fs/nls/mac-iceland.c
3 *
4 * Charset maciceland translation tables.
5 * Generated automatically from the Unicode and charset
6 * tables from the Unicode Organization (www.unicode.org).
7 * The Unicode to charset table has only exact mappings.
8 */
9
10/*
11 * COPYRIGHT AND PERMISSION NOTICE
12 *
13 * Copyright 1991-2012 Unicode, Inc. All rights reserved. Distributed under
14 * the Terms of Use in http://www.unicode.org/copyright.html.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of the Unicode data files and any associated documentation (the "Data
18 * Files") or Unicode software and any associated documentation (the
19 * "Software") to deal in the Data Files or Software without restriction,
20 * including without limitation the rights to use, copy, modify, merge,
21 * publish, distribute, and/or sell copies of the Data Files or Software, and
22 * to permit persons to whom the Data Files or Software are furnished to do
23 * so, provided that (a) the above copyright notice(s) and this permission
24 * notice appear with all copies of the Data Files or Software, (b) both the
25 * above copyright notice(s) and this permission notice appear in associated
26 * documentation, and (c) there is clear notice in each modified Data File or
27 * in the Software as well as in the documentation associated with the Data
28 * File(s) or Software that the data or software has been modified.
29 *
30 * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
33 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
34 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
35 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
36 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38 * PERFORMANCE OF THE DATA FILES OR SOFTWARE.
39 *
40 * Except as contained in this notice, the name of a copyright holder shall
41 * not be used in advertising or otherwise to promote the sale, use or other
42 * dealings in these Data Files or Software without prior written
43 * authorization of the copyright holder.
44 */
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/nls.h>
50#include <linux/errno.h>
51
52static const wchar_t charset2uni[256] = {
53 /* 0x00 */
54 0x0000, 0x0001, 0x0002, 0x0003,
55 0x0004, 0x0005, 0x0006, 0x0007,
56 0x0008, 0x0009, 0x000a, 0x000b,
57 0x000c, 0x000d, 0x000e, 0x000f,
58 /* 0x10 */
59 0x0010, 0x0011, 0x0012, 0x0013,
60 0x0014, 0x0015, 0x0016, 0x0017,
61 0x0018, 0x0019, 0x001a, 0x001b,
62 0x001c, 0x001d, 0x001e, 0x001f,
63 /* 0x20 */
64 0x0020, 0x0021, 0x0022, 0x0023,
65 0x0024, 0x0025, 0x0026, 0x0027,
66 0x0028, 0x0029, 0x002a, 0x002b,
67 0x002c, 0x002d, 0x002e, 0x002f,
68 /* 0x30 */
69 0x0030, 0x0031, 0x0032, 0x0033,
70 0x0034, 0x0035, 0x0036, 0x0037,
71 0x0038, 0x0039, 0x003a, 0x003b,
72 0x003c, 0x003d, 0x003e, 0x003f,
73 /* 0x40 */
74 0x0040, 0x0041, 0x0042, 0x0043,
75 0x0044, 0x0045, 0x0046, 0x0047,
76 0x0048, 0x0049, 0x004a, 0x004b,
77 0x004c, 0x004d, 0x004e, 0x004f,
78 /* 0x50 */
79 0x0050, 0x0051, 0x0052, 0x0053,
80 0x0054, 0x0055, 0x0056, 0x0057,
81 0x0058, 0x0059, 0x005a, 0x005b,
82 0x005c, 0x005d, 0x005e, 0x005f,
83 /* 0x60 */
84 0x0060, 0x0061, 0x0062, 0x0063,
85 0x0064, 0x0065, 0x0066, 0x0067,
86 0x0068, 0x0069, 0x006a, 0x006b,
87 0x006c, 0x006d, 0x006e, 0x006f,
88 /* 0x70 */
89 0x0070, 0x0071, 0x0072, 0x0073,
90 0x0074, 0x0075, 0x0076, 0x0077,
91 0x0078, 0x0079, 0x007a, 0x007b,
92 0x007c, 0x007d, 0x007e, 0x007f,
93 /* 0x80 */
94 0x00c4, 0x00c5, 0x00c7, 0x00c9,
95 0x00d1, 0x00d6, 0x00dc, 0x00e1,
96 0x00e0, 0x00e2, 0x00e4, 0x00e3,
97 0x00e5, 0x00e7, 0x00e9, 0x00e8,
98 /* 0x90 */
99 0x00ea, 0x00eb, 0x00ed, 0x00ec,
100 0x00ee, 0x00ef, 0x00f1, 0x00f3,
101 0x00f2, 0x00f4, 0x00f6, 0x00f5,
102 0x00fa, 0x00f9, 0x00fb, 0x00fc,
103 /* 0xa0 */
104 0x00dd, 0x00b0, 0x00a2, 0x00a3,
105 0x00a7, 0x2022, 0x00b6, 0x00df,
106 0x00ae, 0x00a9, 0x2122, 0x00b4,
107 0x00a8, 0x2260, 0x00c6, 0x00d8,
108 /* 0xb0 */
109 0x221e, 0x00b1, 0x2264, 0x2265,
110 0x00a5, 0x00b5, 0x2202, 0x2211,
111 0x220f, 0x03c0, 0x222b, 0x00aa,
112 0x00ba, 0x03a9, 0x00e6, 0x00f8,
113 /* 0xc0 */
114 0x00bf, 0x00a1, 0x00ac, 0x221a,
115 0x0192, 0x2248, 0x2206, 0x00ab,
116 0x00bb, 0x2026, 0x00a0, 0x00c0,
117 0x00c3, 0x00d5, 0x0152, 0x0153,
118 /* 0xd0 */
119 0x2013, 0x2014, 0x201c, 0x201d,
120 0x2018, 0x2019, 0x00f7, 0x25ca,
121 0x00ff, 0x0178, 0x2044, 0x20ac,
122 0x00d0, 0x00f0, 0x00de, 0x00fe,
123 /* 0xe0 */
124 0x00fd, 0x00b7, 0x201a, 0x201e,
125 0x2030, 0x00c2, 0x00ca, 0x00c1,
126 0x00cb, 0x00c8, 0x00cd, 0x00ce,
127 0x00cf, 0x00cc, 0x00d3, 0x00d4,
128 /* 0xf0 */
129 0xf8ff, 0x00d2, 0x00da, 0x00db,
130 0x00d9, 0x0131, 0x02c6, 0x02dc,
131 0x00af, 0x02d8, 0x02d9, 0x02da,
132 0x00b8, 0x02dd, 0x02db, 0x02c7,
133};
134
135static const unsigned char page00[256] = {
136 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00-0x07 */
137 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08-0x0f */
138 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10-0x17 */
139 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18-0x1f */
140 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20-0x27 */
141 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28-0x2f */
142 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30-0x37 */
143 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38-0x3f */
144 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40-0x47 */
145 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* 0x48-0x4f */
146 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50-0x57 */
147 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, /* 0x58-0x5f */
148 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60-0x67 */
149 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, /* 0x68-0x6f */
150 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70-0x77 */
151 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, /* 0x78-0x7f */
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
156 0xca, 0xc1, 0xa2, 0xa3, 0x00, 0xb4, 0x00, 0xa4, /* 0xa0-0xa7 */
157 0xac, 0xa9, 0xbb, 0xc7, 0xc2, 0x00, 0xa8, 0xf8, /* 0xa8-0xaf */
158 0xa1, 0xb1, 0x00, 0x00, 0xab, 0xb5, 0xa6, 0xe1, /* 0xb0-0xb7 */
159 0xfc, 0x00, 0xbc, 0xc8, 0x00, 0x00, 0x00, 0xc0, /* 0xb8-0xbf */
160 0xcb, 0xe7, 0xe5, 0xcc, 0x80, 0x81, 0xae, 0x82, /* 0xc0-0xc7 */
161 0xe9, 0x83, 0xe6, 0xe8, 0xed, 0xea, 0xeb, 0xec, /* 0xc8-0xcf */
162 0xdc, 0x84, 0xf1, 0xee, 0xef, 0xcd, 0x85, 0x00, /* 0xd0-0xd7 */
163 0xaf, 0xf4, 0xf2, 0xf3, 0x86, 0xa0, 0xde, 0xa7, /* 0xd8-0xdf */
164 0x88, 0x87, 0x89, 0x8b, 0x8a, 0x8c, 0xbe, 0x8d, /* 0xe0-0xe7 */
165 0x8f, 0x8e, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, /* 0xe8-0xef */
166 0xdd, 0x96, 0x98, 0x97, 0x99, 0x9b, 0x9a, 0xd6, /* 0xf0-0xf7 */
167 0xbf, 0x9d, 0x9c, 0x9e, 0x9f, 0xe0, 0xdf, 0xd8, /* 0xf8-0xff */
168};
169
170static const unsigned char page01[256] = {
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
177 0x00, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
181 0x00, 0x00, 0xce, 0xcf, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
186 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
189 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
203};
204
205static const unsigned char page02[256] = {
206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xff, /* 0xc0-0xc7 */
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
233 0xf9, 0xfa, 0xfb, 0xfe, 0xf7, 0xfd, 0x00, 0x00, /* 0xd8-0xdf */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
238};
239
240static const unsigned char page03[256] = {
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
262 0x00, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
265 0xb9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
273};
274
275static const unsigned char page20[256] = {
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
278 0x00, 0x00, 0x00, 0xd0, 0xd1, 0x00, 0x00, 0x00, /* 0x10-0x17 */
279 0xd4, 0xd5, 0xe2, 0x00, 0xd2, 0xd3, 0xe3, 0x00, /* 0x18-0x1f */
280 0x00, 0x00, 0xa5, 0x00, 0x00, 0x00, 0xc9, 0x00, /* 0x20-0x27 */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
282 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
284 0x00, 0x00, 0x00, 0x00, 0xda, 0x00, 0x00, 0x00, /* 0x40-0x47 */
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
297 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
308};
309
310static const unsigned char page21[256] = {
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
315 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
336 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
343};
344
345static const unsigned char page22[256] = {
346 0x00, 0x00, 0xb6, 0x00, 0x00, 0x00, 0xc6, 0x00, /* 0x00-0x07 */
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, /* 0x08-0x0f */
348 0x00, 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
349 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0xb0, 0x00, /* 0x18-0x1f */
350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
351 0x00, 0x00, 0x00, 0xba, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
355 0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
358 0xad, 0x00, 0x00, 0x00, 0xb2, 0xb3, 0x00, 0x00, /* 0x60-0x67 */
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
361 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
365 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
366 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
367 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
371 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
373 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
376 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
378};
379
380static const unsigned char page25[256] = {
381 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
382 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
385 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
386 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
387 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
388 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
390 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
391 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
392 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
393 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
394 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
399 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
401 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
405 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
406 0x00, 0x00, 0xd7, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
407 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
408 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
409 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
410 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
411 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
412 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
413};
414
415static const unsigned char pagef8[256] = {
416 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
417 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
418 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
422 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
424 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
425 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
426 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
427 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
428 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
429 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
430 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
433 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
434 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
435 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
436 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
437 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
439 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
440 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
441 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
442 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
443 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
444 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
445 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
446 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
447 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, /* 0xf8-0xff */
448};
449
450static const unsigned char *const page_uni2charset[256] = {
451 page00, page01, page02, page03, NULL, NULL, NULL, NULL,
452 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
453 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
454 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
455 page20, page21, page22, NULL, NULL, page25, NULL, NULL,
456 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
457 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
458 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
459 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
460 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
461 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
462 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
463 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
464 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
465 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
466 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
467 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
468 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
469 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
470 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
471 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
472 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
473 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
474 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
475 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
476 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
477 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
478 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
479 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
480 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
481 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
482 pagef8, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
483};
484
485static const unsigned char charset2lower[256] = {
486 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
487 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
488 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
489 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
490 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
491 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
492 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
493 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
494 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
495 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
496 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
497 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
498 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
499 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
500 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
501 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
502 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
503 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
504 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
505 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
506 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
507 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
508 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
509 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
510 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
511 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
512 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
513 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
514 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
515 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
516 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
517 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
518};
519
520static const unsigned char charset2upper[256] = {
521 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
522 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
523 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
524 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
525 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
526 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
527 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
528 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
529 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
530 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
531 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
532 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
533 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
534 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
535 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
536 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
537 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
538 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
539 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
540 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
541 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
542 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
543 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
544 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
545 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
546 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
547 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
548 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
549 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
550 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
551 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
552 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
553};
554
555static int uni2char(wchar_t uni, unsigned char *out, int boundlen)
556{
557 const unsigned char *uni2charset;
558 unsigned char cl = uni & 0x00ff;
559 unsigned char ch = (uni & 0xff00) >> 8;
560
561 if (boundlen <= 0)
562 return -ENAMETOOLONG;
563
564 uni2charset = page_uni2charset[ch];
565 if (uni2charset && uni2charset[cl])
566 out[0] = uni2charset[cl];
567 else
568 return -EINVAL;
569 return 1;
570}
571
572static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
573{
574 *uni = charset2uni[*rawstring];
575 if (*uni == 0x0000)
576 return -EINVAL;
577 return 1;
578}
579
580static struct nls_table table = {
581 .charset = "maciceland",
582 .uni2char = uni2char,
583 .char2uni = char2uni,
584 .charset2lower = charset2lower,
585 .charset2upper = charset2upper,
586 .owner = THIS_MODULE,
587};
588
589static int __init init_nls_maciceland(void)
590{
591 return register_nls(&table);
592}
593
594static void __exit exit_nls_maciceland(void)
595{
596 unregister_nls(&table);
597}
598
599module_init(init_nls_maciceland)
600module_exit(exit_nls_maciceland)
601
602MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/nls/mac-inuit.c b/fs/nls/mac-inuit.c
new file mode 100644
index 000000000000..312364f010dc
--- /dev/null
+++ b/fs/nls/mac-inuit.c
@@ -0,0 +1,532 @@
1/*
2 * linux/fs/nls/mac-inuit.c
3 *
4 * Charset macinuit translation tables.
5 * Generated automatically from the Unicode and charset
6 * tables from the Unicode Organization (www.unicode.org).
7 * The Unicode to charset table has only exact mappings.
8 */
9
10/*
11 * COPYRIGHT AND PERMISSION NOTICE
12 *
13 * Copyright 1991-2012 Unicode, Inc. All rights reserved. Distributed under
14 * the Terms of Use in http://www.unicode.org/copyright.html.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of the Unicode data files and any associated documentation (the "Data
18 * Files") or Unicode software and any associated documentation (the
19 * "Software") to deal in the Data Files or Software without restriction,
20 * including without limitation the rights to use, copy, modify, merge,
21 * publish, distribute, and/or sell copies of the Data Files or Software, and
22 * to permit persons to whom the Data Files or Software are furnished to do
23 * so, provided that (a) the above copyright notice(s) and this permission
24 * notice appear with all copies of the Data Files or Software, (b) both the
25 * above copyright notice(s) and this permission notice appear in associated
26 * documentation, and (c) there is clear notice in each modified Data File or
27 * in the Software as well as in the documentation associated with the Data
28 * File(s) or Software that the data or software has been modified.
29 *
30 * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
33 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
34 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
35 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
36 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38 * PERFORMANCE OF THE DATA FILES OR SOFTWARE.
39 *
40 * Except as contained in this notice, the name of a copyright holder shall
41 * not be used in advertising or otherwise to promote the sale, use or other
42 * dealings in these Data Files or Software without prior written
43 * authorization of the copyright holder.
44 */
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/nls.h>
50#include <linux/errno.h>
51
52static const wchar_t charset2uni[256] = {
53 /* 0x00 */
54 0x0000, 0x0001, 0x0002, 0x0003,
55 0x0004, 0x0005, 0x0006, 0x0007,
56 0x0008, 0x0009, 0x000a, 0x000b,
57 0x000c, 0x000d, 0x000e, 0x000f,
58 /* 0x10 */
59 0x0010, 0x0011, 0x0012, 0x0013,
60 0x0014, 0x0015, 0x0016, 0x0017,
61 0x0018, 0x0019, 0x001a, 0x001b,
62 0x001c, 0x001d, 0x001e, 0x001f,
63 /* 0x20 */
64 0x0020, 0x0021, 0x0022, 0x0023,
65 0x0024, 0x0025, 0x0026, 0x0027,
66 0x0028, 0x0029, 0x002a, 0x002b,
67 0x002c, 0x002d, 0x002e, 0x002f,
68 /* 0x30 */
69 0x0030, 0x0031, 0x0032, 0x0033,
70 0x0034, 0x0035, 0x0036, 0x0037,
71 0x0038, 0x0039, 0x003a, 0x003b,
72 0x003c, 0x003d, 0x003e, 0x003f,
73 /* 0x40 */
74 0x0040, 0x0041, 0x0042, 0x0043,
75 0x0044, 0x0045, 0x0046, 0x0047,
76 0x0048, 0x0049, 0x004a, 0x004b,
77 0x004c, 0x004d, 0x004e, 0x004f,
78 /* 0x50 */
79 0x0050, 0x0051, 0x0052, 0x0053,
80 0x0054, 0x0055, 0x0056, 0x0057,
81 0x0058, 0x0059, 0x005a, 0x005b,
82 0x005c, 0x005d, 0x005e, 0x005f,
83 /* 0x60 */
84 0x0060, 0x0061, 0x0062, 0x0063,
85 0x0064, 0x0065, 0x0066, 0x0067,
86 0x0068, 0x0069, 0x006a, 0x006b,
87 0x006c, 0x006d, 0x006e, 0x006f,
88 /* 0x70 */
89 0x0070, 0x0071, 0x0072, 0x0073,
90 0x0074, 0x0075, 0x0076, 0x0077,
91 0x0078, 0x0079, 0x007a, 0x007b,
92 0x007c, 0x007d, 0x007e, 0x007f,
93 /* 0x80 */
94 0x1403, 0x1404, 0x1405, 0x1406,
95 0x140a, 0x140b, 0x1431, 0x1432,
96 0x1433, 0x1434, 0x1438, 0x1439,
97 0x1449, 0x144e, 0x144f, 0x1450,
98 /* 0x90 */
99 0x1451, 0x1455, 0x1456, 0x1466,
100 0x146d, 0x146e, 0x146f, 0x1470,
101 0x1472, 0x1473, 0x1483, 0x148b,
102 0x148c, 0x148d, 0x148e, 0x1490,
103 /* 0xa0 */
104 0x1491, 0x00b0, 0x14a1, 0x14a5,
105 0x14a6, 0x2022, 0x00b6, 0x14a7,
106 0x00ae, 0x00a9, 0x2122, 0x14a8,
107 0x14aa, 0x14ab, 0x14bb, 0x14c2,
108 /* 0xb0 */
109 0x14c3, 0x14c4, 0x14c5, 0x14c7,
110 0x14c8, 0x14d0, 0x14ef, 0x14f0,
111 0x14f1, 0x14f2, 0x14f4, 0x14f5,
112 0x1505, 0x14d5, 0x14d6, 0x14d7,
113 /* 0xc0 */
114 0x14d8, 0x14da, 0x14db, 0x14ea,
115 0x1528, 0x1529, 0x152a, 0x152b,
116 0x152d, 0x2026, 0x00a0, 0x152e,
117 0x153e, 0x1555, 0x1556, 0x1557,
118 /* 0xd0 */
119 0x2013, 0x2014, 0x201c, 0x201d,
120 0x2018, 0x2019, 0x1558, 0x1559,
121 0x155a, 0x155d, 0x1546, 0x1547,
122 0x1548, 0x1549, 0x154b, 0x154c,
123 /* 0xe0 */
124 0x1550, 0x157f, 0x1580, 0x1581,
125 0x1582, 0x1583, 0x1584, 0x1585,
126 0x158f, 0x1590, 0x1591, 0x1592,
127 0x1593, 0x1594, 0x1595, 0x1671,
128 /* 0xf0 */
129 0x1672, 0x1673, 0x1674, 0x1675,
130 0x1676, 0x1596, 0x15a0, 0x15a1,
131 0x15a2, 0x15a3, 0x15a4, 0x15a5,
132 0x15a6, 0x157c, 0x0141, 0x0142,
133};
134
135static const unsigned char page00[256] = {
136 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00-0x07 */
137 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08-0x0f */
138 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10-0x17 */
139 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18-0x1f */
140 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20-0x27 */
141 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28-0x2f */
142 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30-0x37 */
143 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38-0x3f */
144 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40-0x47 */
145 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* 0x48-0x4f */
146 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50-0x57 */
147 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, /* 0x58-0x5f */
148 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60-0x67 */
149 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, /* 0x68-0x6f */
150 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70-0x77 */
151 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, /* 0x78-0x7f */
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
156 0xca, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
157 0x00, 0xa9, 0x00, 0x00, 0x00, 0x00, 0xa8, 0x00, /* 0xa8-0xaf */
158 0xa1, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa6, 0x00, /* 0xb0-0xb7 */
159 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
164 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
166 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
167 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
168};
169
170static const unsigned char page01[256] = {
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
179 0x00, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
181 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
186 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
189 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
203};
204
205static const unsigned char page14[256] = {
206 0x00, 0x00, 0x00, 0x80, 0x81, 0x82, 0x83, 0x00, /* 0x00-0x07 */
207 0x00, 0x00, 0x84, 0x85, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
212 0x00, 0x86, 0x87, 0x88, 0x89, 0x00, 0x00, 0x00, /* 0x30-0x37 */
213 0x8a, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
215 0x00, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x8d, 0x8e, /* 0x48-0x4f */
216 0x8f, 0x90, 0x00, 0x00, 0x00, 0x91, 0x92, 0x00, /* 0x50-0x57 */
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x00, /* 0x60-0x67 */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x95, 0x96, /* 0x68-0x6f */
220 0x97, 0x00, 0x98, 0x99, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
222 0x00, 0x00, 0x00, 0x9a, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
223 0x00, 0x00, 0x00, 0x9b, 0x9c, 0x9d, 0x9e, 0x00, /* 0x88-0x8f */
224 0x9f, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
226 0x00, 0xa2, 0x00, 0x00, 0x00, 0xa3, 0xa4, 0xa7, /* 0xa0-0xa7 */
227 0xab, 0x00, 0xac, 0xad, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
229 0x00, 0x00, 0x00, 0xae, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
230 0x00, 0x00, 0xaf, 0xb0, 0xb1, 0xb2, 0x00, 0xb3, /* 0xc0-0xc7 */
231 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
232 0xb5, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xbe, 0xbf, /* 0xd0-0xd7 */
233 0xc0, 0x00, 0xc1, 0xc2, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
235 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0x00, 0xb6, /* 0xe8-0xef */
236 0xb7, 0xb8, 0xb9, 0x00, 0xba, 0xbb, 0x00, 0x00, /* 0xf0-0xf7 */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
238};
239
240static const unsigned char page15[256] = {
241 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x00, 0x00, /* 0x00-0x07 */
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
246 0xc4, 0xc5, 0xc6, 0xc7, 0x00, 0xc8, 0xcb, 0x00, /* 0x28-0x2f */
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x00, /* 0x38-0x3f */
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xda, 0xdb, /* 0x40-0x47 */
250 0xdc, 0xdd, 0x00, 0xde, 0xdf, 0x00, 0x00, 0x00, /* 0x48-0x4f */
251 0xe0, 0x00, 0x00, 0x00, 0x00, 0xcd, 0xce, 0xcf, /* 0x50-0x57 */
252 0xd6, 0xd7, 0xd8, 0x00, 0x00, 0xd9, 0x00, 0x00, /* 0x58-0x5f */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
256 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x00, 0xe1, /* 0x78-0x7f */
257 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0x00, 0x00, /* 0x80-0x87 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, /* 0x88-0x8f */
259 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xf5, 0x00, /* 0x90-0x97 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
261 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0x00, /* 0xa0-0xa7 */
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
273};
274
275static const unsigned char page16[256] = {
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
290 0x00, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0x00, /* 0x70-0x77 */
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
308};
309
310static const unsigned char page20[256] = {
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
313 0x00, 0x00, 0x00, 0xd0, 0xd1, 0x00, 0x00, 0x00, /* 0x10-0x17 */
314 0xd4, 0xd5, 0x00, 0x00, 0xd2, 0xd3, 0x00, 0x00, /* 0x18-0x1f */
315 0x00, 0x00, 0xa5, 0x00, 0x00, 0x00, 0xc9, 0x00, /* 0x20-0x27 */
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
336 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
343};
344
345static const unsigned char page21[256] = {
346 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
348 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
349 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
350 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
351 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
358 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
361 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
365 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
366 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
367 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
371 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
373 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
376 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
378};
379
380static const unsigned char *const page_uni2charset[256] = {
381 page00, page01, NULL, NULL, NULL, NULL, NULL, NULL,
382 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
383 NULL, NULL, NULL, NULL, page14, page15, page16, NULL,
384 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
385 page20, page21, NULL, NULL, NULL, NULL, NULL, NULL,
386 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
387 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
388 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
389 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
390 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
391 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
392 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
393 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
394 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
395 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
396 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
397 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
398 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
399 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
400 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
401 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
402 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
403 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
404 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
405 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
406 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
407 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
408 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
409 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
410 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
411 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
412 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
413};
414
415static const unsigned char charset2lower[256] = {
416 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
417 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
418 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
419 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
420 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
421 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
422 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
423 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
424 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
425 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
426 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
427 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
428 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
429 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
430 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
431 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
432 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
433 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
434 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
435 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
436 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
437 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
438 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
439 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
440 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
441 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
442 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
443 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
444 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
445 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
446 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
447 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
448};
449
450static const unsigned char charset2upper[256] = {
451 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x00-0x07 */
452 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x08-0x0f */
453 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x10-0x17 */
454 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x18-0x1f */
455 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x20-0x27 */
456 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x28-0x2f */
457 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x30-0x37 */
458 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x38-0x3f */
459 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x40-0x47 */
460 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x48-0x4f */
461 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x50-0x57 */
462 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x58-0x5f */
463 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x60-0x67 */
464 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x68-0x6f */
465 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x70-0x77 */
466 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x78-0x7f */
467 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x80-0x87 */
468 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x88-0x8f */
469 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x90-0x97 */
470 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0x98-0x9f */
471 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xa0-0xa7 */
472 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xa8-0xaf */
473 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xb0-0xb7 */
474 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xb8-0xbf */
475 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xc0-0xc7 */
476 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xc8-0xcf */
477 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xd0-0xd7 */
478 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xd8-0xdf */
479 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xe0-0xe7 */
480 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xe8-0xef */
481 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xf0-0xf7 */
482 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, /* 0xf8-0xff */
483};
484
485static int uni2char(wchar_t uni, unsigned char *out, int boundlen)
486{
487 const unsigned char *uni2charset;
488 unsigned char cl = uni & 0x00ff;
489 unsigned char ch = (uni & 0xff00) >> 8;
490
491 if (boundlen <= 0)
492 return -ENAMETOOLONG;
493
494 uni2charset = page_uni2charset[ch];
495 if (uni2charset && uni2charset[cl])
496 out[0] = uni2charset[cl];
497 else
498 return -EINVAL;
499 return 1;
500}
501
502static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
503{
504 *uni = charset2uni[*rawstring];
505 if (*uni == 0x0000)
506 return -EINVAL;
507 return 1;
508}
509
510static struct nls_table table = {
511 .charset = "macinuit",
512 .uni2char = uni2char,
513 .char2uni = char2uni,
514 .charset2lower = charset2lower,
515 .charset2upper = charset2upper,
516 .owner = THIS_MODULE,
517};
518
519static int __init init_nls_macinuit(void)
520{
521 return register_nls(&table);
522}
523
524static void __exit exit_nls_macinuit(void)
525{
526 unregister_nls(&table);
527}
528
529module_init(init_nls_macinuit)
530module_exit(exit_nls_macinuit)
531
532MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/nls/mac-roman.c b/fs/nls/mac-roman.c
new file mode 100644
index 000000000000..53ce0809cbd2
--- /dev/null
+++ b/fs/nls/mac-roman.c
@@ -0,0 +1,637 @@
1/*
2 * linux/fs/nls/mac-roman.c
3 *
4 * Charset macroman translation tables.
5 * Generated automatically from the Unicode and charset
6 * tables from the Unicode Organization (www.unicode.org).
7 * The Unicode to charset table has only exact mappings.
8 */
9
10/*
11 * COPYRIGHT AND PERMISSION NOTICE
12 *
13 * Copyright 1991-2012 Unicode, Inc. All rights reserved. Distributed under
14 * the Terms of Use in http://www.unicode.org/copyright.html.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of the Unicode data files and any associated documentation (the "Data
18 * Files") or Unicode software and any associated documentation (the
19 * "Software") to deal in the Data Files or Software without restriction,
20 * including without limitation the rights to use, copy, modify, merge,
21 * publish, distribute, and/or sell copies of the Data Files or Software, and
22 * to permit persons to whom the Data Files or Software are furnished to do
23 * so, provided that (a) the above copyright notice(s) and this permission
24 * notice appear with all copies of the Data Files or Software, (b) both the
25 * above copyright notice(s) and this permission notice appear in associated
26 * documentation, and (c) there is clear notice in each modified Data File or
27 * in the Software as well as in the documentation associated with the Data
28 * File(s) or Software that the data or software has been modified.
29 *
30 * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
33 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
34 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
35 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
36 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38 * PERFORMANCE OF THE DATA FILES OR SOFTWARE.
39 *
40 * Except as contained in this notice, the name of a copyright holder shall
41 * not be used in advertising or otherwise to promote the sale, use or other
42 * dealings in these Data Files or Software without prior written
43 * authorization of the copyright holder.
44 */
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/nls.h>
50#include <linux/errno.h>
51
52static const wchar_t charset2uni[256] = {
53 /* 0x00 */
54 0x0000, 0x0001, 0x0002, 0x0003,
55 0x0004, 0x0005, 0x0006, 0x0007,
56 0x0008, 0x0009, 0x000a, 0x000b,
57 0x000c, 0x000d, 0x000e, 0x000f,
58 /* 0x10 */
59 0x0010, 0x0011, 0x0012, 0x0013,
60 0x0014, 0x0015, 0x0016, 0x0017,
61 0x0018, 0x0019, 0x001a, 0x001b,
62 0x001c, 0x001d, 0x001e, 0x001f,
63 /* 0x20 */
64 0x0020, 0x0021, 0x0022, 0x0023,
65 0x0024, 0x0025, 0x0026, 0x0027,
66 0x0028, 0x0029, 0x002a, 0x002b,
67 0x002c, 0x002d, 0x002e, 0x002f,
68 /* 0x30 */
69 0x0030, 0x0031, 0x0032, 0x0033,
70 0x0034, 0x0035, 0x0036, 0x0037,
71 0x0038, 0x0039, 0x003a, 0x003b,
72 0x003c, 0x003d, 0x003e, 0x003f,
73 /* 0x40 */
74 0x0040, 0x0041, 0x0042, 0x0043,
75 0x0044, 0x0045, 0x0046, 0x0047,
76 0x0048, 0x0049, 0x004a, 0x004b,
77 0x004c, 0x004d, 0x004e, 0x004f,
78 /* 0x50 */
79 0x0050, 0x0051, 0x0052, 0x0053,
80 0x0054, 0x0055, 0x0056, 0x0057,
81 0x0058, 0x0059, 0x005a, 0x005b,
82 0x005c, 0x005d, 0x005e, 0x005f,
83 /* 0x60 */
84 0x0060, 0x0061, 0x0062, 0x0063,
85 0x0064, 0x0065, 0x0066, 0x0067,
86 0x0068, 0x0069, 0x006a, 0x006b,
87 0x006c, 0x006d, 0x006e, 0x006f,
88 /* 0x70 */
89 0x0070, 0x0071, 0x0072, 0x0073,
90 0x0074, 0x0075, 0x0076, 0x0077,
91 0x0078, 0x0079, 0x007a, 0x007b,
92 0x007c, 0x007d, 0x007e, 0x007f,
93 /* 0x80 */
94 0x00c4, 0x00c5, 0x00c7, 0x00c9,
95 0x00d1, 0x00d6, 0x00dc, 0x00e1,
96 0x00e0, 0x00e2, 0x00e4, 0x00e3,
97 0x00e5, 0x00e7, 0x00e9, 0x00e8,
98 /* 0x90 */
99 0x00ea, 0x00eb, 0x00ed, 0x00ec,
100 0x00ee, 0x00ef, 0x00f1, 0x00f3,
101 0x00f2, 0x00f4, 0x00f6, 0x00f5,
102 0x00fa, 0x00f9, 0x00fb, 0x00fc,
103 /* 0xa0 */
104 0x2020, 0x00b0, 0x00a2, 0x00a3,
105 0x00a7, 0x2022, 0x00b6, 0x00df,
106 0x00ae, 0x00a9, 0x2122, 0x00b4,
107 0x00a8, 0x2260, 0x00c6, 0x00d8,
108 /* 0xb0 */
109 0x221e, 0x00b1, 0x2264, 0x2265,
110 0x00a5, 0x00b5, 0x2202, 0x2211,
111 0x220f, 0x03c0, 0x222b, 0x00aa,
112 0x00ba, 0x03a9, 0x00e6, 0x00f8,
113 /* 0xc0 */
114 0x00bf, 0x00a1, 0x00ac, 0x221a,
115 0x0192, 0x2248, 0x2206, 0x00ab,
116 0x00bb, 0x2026, 0x00a0, 0x00c0,
117 0x00c3, 0x00d5, 0x0152, 0x0153,
118 /* 0xd0 */
119 0x2013, 0x2014, 0x201c, 0x201d,
120 0x2018, 0x2019, 0x00f7, 0x25ca,
121 0x00ff, 0x0178, 0x2044, 0x20ac,
122 0x2039, 0x203a, 0xfb01, 0xfb02,
123 /* 0xe0 */
124 0x2021, 0x00b7, 0x201a, 0x201e,
125 0x2030, 0x00c2, 0x00ca, 0x00c1,
126 0x00cb, 0x00c8, 0x00cd, 0x00ce,
127 0x00cf, 0x00cc, 0x00d3, 0x00d4,
128 /* 0xf0 */
129 0xf8ff, 0x00d2, 0x00da, 0x00db,
130 0x00d9, 0x0131, 0x02c6, 0x02dc,
131 0x00af, 0x02d8, 0x02d9, 0x02da,
132 0x00b8, 0x02dd, 0x02db, 0x02c7,
133};
134
135static const unsigned char page00[256] = {
136 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00-0x07 */
137 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08-0x0f */
138 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10-0x17 */
139 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18-0x1f */
140 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20-0x27 */
141 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28-0x2f */
142 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30-0x37 */
143 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38-0x3f */
144 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40-0x47 */
145 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* 0x48-0x4f */
146 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50-0x57 */
147 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, /* 0x58-0x5f */
148 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60-0x67 */
149 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, /* 0x68-0x6f */
150 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70-0x77 */
151 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, /* 0x78-0x7f */
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
156 0xca, 0xc1, 0xa2, 0xa3, 0x00, 0xb4, 0x00, 0xa4, /* 0xa0-0xa7 */
157 0xac, 0xa9, 0xbb, 0xc7, 0xc2, 0x00, 0xa8, 0xf8, /* 0xa8-0xaf */
158 0xa1, 0xb1, 0x00, 0x00, 0xab, 0xb5, 0xa6, 0xe1, /* 0xb0-0xb7 */
159 0xfc, 0x00, 0xbc, 0xc8, 0x00, 0x00, 0x00, 0xc0, /* 0xb8-0xbf */
160 0xcb, 0xe7, 0xe5, 0xcc, 0x80, 0x81, 0xae, 0x82, /* 0xc0-0xc7 */
161 0xe9, 0x83, 0xe6, 0xe8, 0xed, 0xea, 0xeb, 0xec, /* 0xc8-0xcf */
162 0x00, 0x84, 0xf1, 0xee, 0xef, 0xcd, 0x85, 0x00, /* 0xd0-0xd7 */
163 0xaf, 0xf4, 0xf2, 0xf3, 0x86, 0x00, 0x00, 0xa7, /* 0xd8-0xdf */
164 0x88, 0x87, 0x89, 0x8b, 0x8a, 0x8c, 0xbe, 0x8d, /* 0xe0-0xe7 */
165 0x8f, 0x8e, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, /* 0xe8-0xef */
166 0x00, 0x96, 0x98, 0x97, 0x99, 0x9b, 0x9a, 0xd6, /* 0xf0-0xf7 */
167 0xbf, 0x9d, 0x9c, 0x9e, 0x9f, 0x00, 0x00, 0xd8, /* 0xf8-0xff */
168};
169
170static const unsigned char page01[256] = {
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
177 0x00, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
181 0x00, 0x00, 0xce, 0xcf, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
186 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
189 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
203};
204
205static const unsigned char page02[256] = {
206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xff, /* 0xc0-0xc7 */
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
233 0xf9, 0xfa, 0xfb, 0xfe, 0xf7, 0xfd, 0x00, 0x00, /* 0xd8-0xdf */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
238};
239
240static const unsigned char page03[256] = {
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
262 0x00, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
265 0xb9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
273};
274
275static const unsigned char page20[256] = {
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
278 0x00, 0x00, 0x00, 0xd0, 0xd1, 0x00, 0x00, 0x00, /* 0x10-0x17 */
279 0xd4, 0xd5, 0xe2, 0x00, 0xd2, 0xd3, 0xe3, 0x00, /* 0x18-0x1f */
280 0xa0, 0xe0, 0xa5, 0x00, 0x00, 0x00, 0xc9, 0x00, /* 0x20-0x27 */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
282 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
283 0x00, 0xdc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
284 0x00, 0x00, 0x00, 0x00, 0xda, 0x00, 0x00, 0x00, /* 0x40-0x47 */
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
297 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
308};
309
310static const unsigned char page21[256] = {
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
315 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
336 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
343};
344
345static const unsigned char page22[256] = {
346 0x00, 0x00, 0xb6, 0x00, 0x00, 0x00, 0xc6, 0x00, /* 0x00-0x07 */
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, /* 0x08-0x0f */
348 0x00, 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
349 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0xb0, 0x00, /* 0x18-0x1f */
350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
351 0x00, 0x00, 0x00, 0xba, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
355 0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
358 0xad, 0x00, 0x00, 0x00, 0xb2, 0xb3, 0x00, 0x00, /* 0x60-0x67 */
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
361 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
365 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
366 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
367 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
371 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
373 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
376 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
378};
379
380static const unsigned char page25[256] = {
381 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
382 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
385 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
386 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
387 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
388 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
390 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
391 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
392 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
393 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
394 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
399 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
401 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
405 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
406 0x00, 0x00, 0xd7, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
407 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
408 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
409 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
410 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
411 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
412 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
413};
414
415static const unsigned char pagef8[256] = {
416 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
417 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
418 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
422 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
424 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
425 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
426 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
427 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
428 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
429 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
430 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
433 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
434 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
435 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
436 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
437 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
439 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
440 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
441 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
442 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
443 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
444 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
445 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
446 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
447 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, /* 0xf8-0xff */
448};
449
450static const unsigned char pagefb[256] = {
451 0x00, 0xde, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
452 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
453 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
454 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
455 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
456 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
457 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
458 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
459 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
460 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
461 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
462 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
463 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
464 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
465 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
466 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
467 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
468 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
469 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
470 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
471 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
472 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
473 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
474 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
475 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
476 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
477 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
478 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
479 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
480 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
481 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
482 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
483};
484
485static const unsigned char *const page_uni2charset[256] = {
486 page00, page01, page02, page03, NULL, NULL, NULL, NULL,
487 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
488 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
489 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
490 page20, page21, page22, NULL, NULL, page25, NULL, NULL,
491 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
492 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
493 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
494 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
495 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
496 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
497 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
498 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
499 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
500 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
501 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
502 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
503 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
504 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
505 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
506 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
507 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
508 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
509 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
510 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
511 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
512 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
513 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
514 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
515 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
516 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
517 pagef8, NULL, NULL, pagefb, NULL, NULL, NULL, NULL,
518};
519
520static const unsigned char charset2lower[256] = {
521 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
522 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
523 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
524 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
525 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
526 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
527 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
528 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
529 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
530 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
531 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
532 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
533 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
534 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
535 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
536 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
537 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
538 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
539 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
540 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
541 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
542 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
543 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
544 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
545 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
546 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
547 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
548 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
549 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
550 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
551 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
552 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
553};
554
555static const unsigned char charset2upper[256] = {
556 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
557 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
558 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
559 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
560 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
561 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
562 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
563 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
564 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
565 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
566 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
567 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
568 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
569 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
570 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
571 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
572 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
573 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
574 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
575 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
576 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
577 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
578 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
579 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
580 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
581 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
582 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
583 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
584 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
585 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
586 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
587 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
588};
589
590static int uni2char(wchar_t uni, unsigned char *out, int boundlen)
591{
592 const unsigned char *uni2charset;
593 unsigned char cl = uni & 0x00ff;
594 unsigned char ch = (uni & 0xff00) >> 8;
595
596 if (boundlen <= 0)
597 return -ENAMETOOLONG;
598
599 uni2charset = page_uni2charset[ch];
600 if (uni2charset && uni2charset[cl])
601 out[0] = uni2charset[cl];
602 else
603 return -EINVAL;
604 return 1;
605}
606
607static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
608{
609 *uni = charset2uni[*rawstring];
610 if (*uni == 0x0000)
611 return -EINVAL;
612 return 1;
613}
614
615static struct nls_table table = {
616 .charset = "macroman",
617 .uni2char = uni2char,
618 .char2uni = char2uni,
619 .charset2lower = charset2lower,
620 .charset2upper = charset2upper,
621 .owner = THIS_MODULE,
622};
623
624static int __init init_nls_macroman(void)
625{
626 return register_nls(&table);
627}
628
629static void __exit exit_nls_macroman(void)
630{
631 unregister_nls(&table);
632}
633
634module_init(init_nls_macroman)
635module_exit(exit_nls_macroman)
636
637MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/nls/mac-romanian.c b/fs/nls/mac-romanian.c
new file mode 100644
index 000000000000..add6f7a0c666
--- /dev/null
+++ b/fs/nls/mac-romanian.c
@@ -0,0 +1,602 @@
1/*
2 * linux/fs/nls/mac-romanian.c
3 *
4 * Charset macromanian translation tables.
5 * Generated automatically from the Unicode and charset
6 * tables from the Unicode Organization (www.unicode.org).
7 * The Unicode to charset table has only exact mappings.
8 */
9
10/*
11 * COPYRIGHT AND PERMISSION NOTICE
12 *
13 * Copyright 1991-2012 Unicode, Inc. All rights reserved. Distributed under
14 * the Terms of Use in http://www.unicode.org/copyright.html.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of the Unicode data files and any associated documentation (the "Data
18 * Files") or Unicode software and any associated documentation (the
19 * "Software") to deal in the Data Files or Software without restriction,
20 * including without limitation the rights to use, copy, modify, merge,
21 * publish, distribute, and/or sell copies of the Data Files or Software, and
22 * to permit persons to whom the Data Files or Software are furnished to do
23 * so, provided that (a) the above copyright notice(s) and this permission
24 * notice appear with all copies of the Data Files or Software, (b) both the
25 * above copyright notice(s) and this permission notice appear in associated
26 * documentation, and (c) there is clear notice in each modified Data File or
27 * in the Software as well as in the documentation associated with the Data
28 * File(s) or Software that the data or software has been modified.
29 *
30 * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
33 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
34 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
35 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
36 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38 * PERFORMANCE OF THE DATA FILES OR SOFTWARE.
39 *
40 * Except as contained in this notice, the name of a copyright holder shall
41 * not be used in advertising or otherwise to promote the sale, use or other
42 * dealings in these Data Files or Software without prior written
43 * authorization of the copyright holder.
44 */
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/nls.h>
50#include <linux/errno.h>
51
52static const wchar_t charset2uni[256] = {
53 /* 0x00 */
54 0x0000, 0x0001, 0x0002, 0x0003,
55 0x0004, 0x0005, 0x0006, 0x0007,
56 0x0008, 0x0009, 0x000a, 0x000b,
57 0x000c, 0x000d, 0x000e, 0x000f,
58 /* 0x10 */
59 0x0010, 0x0011, 0x0012, 0x0013,
60 0x0014, 0x0015, 0x0016, 0x0017,
61 0x0018, 0x0019, 0x001a, 0x001b,
62 0x001c, 0x001d, 0x001e, 0x001f,
63 /* 0x20 */
64 0x0020, 0x0021, 0x0022, 0x0023,
65 0x0024, 0x0025, 0x0026, 0x0027,
66 0x0028, 0x0029, 0x002a, 0x002b,
67 0x002c, 0x002d, 0x002e, 0x002f,
68 /* 0x30 */
69 0x0030, 0x0031, 0x0032, 0x0033,
70 0x0034, 0x0035, 0x0036, 0x0037,
71 0x0038, 0x0039, 0x003a, 0x003b,
72 0x003c, 0x003d, 0x003e, 0x003f,
73 /* 0x40 */
74 0x0040, 0x0041, 0x0042, 0x0043,
75 0x0044, 0x0045, 0x0046, 0x0047,
76 0x0048, 0x0049, 0x004a, 0x004b,
77 0x004c, 0x004d, 0x004e, 0x004f,
78 /* 0x50 */
79 0x0050, 0x0051, 0x0052, 0x0053,
80 0x0054, 0x0055, 0x0056, 0x0057,
81 0x0058, 0x0059, 0x005a, 0x005b,
82 0x005c, 0x005d, 0x005e, 0x005f,
83 /* 0x60 */
84 0x0060, 0x0061, 0x0062, 0x0063,
85 0x0064, 0x0065, 0x0066, 0x0067,
86 0x0068, 0x0069, 0x006a, 0x006b,
87 0x006c, 0x006d, 0x006e, 0x006f,
88 /* 0x70 */
89 0x0070, 0x0071, 0x0072, 0x0073,
90 0x0074, 0x0075, 0x0076, 0x0077,
91 0x0078, 0x0079, 0x007a, 0x007b,
92 0x007c, 0x007d, 0x007e, 0x007f,
93 /* 0x80 */
94 0x00c4, 0x00c5, 0x00c7, 0x00c9,
95 0x00d1, 0x00d6, 0x00dc, 0x00e1,
96 0x00e0, 0x00e2, 0x00e4, 0x00e3,
97 0x00e5, 0x00e7, 0x00e9, 0x00e8,
98 /* 0x90 */
99 0x00ea, 0x00eb, 0x00ed, 0x00ec,
100 0x00ee, 0x00ef, 0x00f1, 0x00f3,
101 0x00f2, 0x00f4, 0x00f6, 0x00f5,
102 0x00fa, 0x00f9, 0x00fb, 0x00fc,
103 /* 0xa0 */
104 0x2020, 0x00b0, 0x00a2, 0x00a3,
105 0x00a7, 0x2022, 0x00b6, 0x00df,
106 0x00ae, 0x00a9, 0x2122, 0x00b4,
107 0x00a8, 0x2260, 0x0102, 0x0218,
108 /* 0xb0 */
109 0x221e, 0x00b1, 0x2264, 0x2265,
110 0x00a5, 0x00b5, 0x2202, 0x2211,
111 0x220f, 0x03c0, 0x222b, 0x00aa,
112 0x00ba, 0x03a9, 0x0103, 0x0219,
113 /* 0xc0 */
114 0x00bf, 0x00a1, 0x00ac, 0x221a,
115 0x0192, 0x2248, 0x2206, 0x00ab,
116 0x00bb, 0x2026, 0x00a0, 0x00c0,
117 0x00c3, 0x00d5, 0x0152, 0x0153,
118 /* 0xd0 */
119 0x2013, 0x2014, 0x201c, 0x201d,
120 0x2018, 0x2019, 0x00f7, 0x25ca,
121 0x00ff, 0x0178, 0x2044, 0x20ac,
122 0x2039, 0x203a, 0x021a, 0x021b,
123 /* 0xe0 */
124 0x2021, 0x00b7, 0x201a, 0x201e,
125 0x2030, 0x00c2, 0x00ca, 0x00c1,
126 0x00cb, 0x00c8, 0x00cd, 0x00ce,
127 0x00cf, 0x00cc, 0x00d3, 0x00d4,
128 /* 0xf0 */
129 0xf8ff, 0x00d2, 0x00da, 0x00db,
130 0x00d9, 0x0131, 0x02c6, 0x02dc,
131 0x00af, 0x02d8, 0x02d9, 0x02da,
132 0x00b8, 0x02dd, 0x02db, 0x02c7,
133};
134
135static const unsigned char page00[256] = {
136 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00-0x07 */
137 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08-0x0f */
138 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10-0x17 */
139 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18-0x1f */
140 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20-0x27 */
141 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28-0x2f */
142 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30-0x37 */
143 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38-0x3f */
144 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40-0x47 */
145 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* 0x48-0x4f */
146 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50-0x57 */
147 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, /* 0x58-0x5f */
148 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60-0x67 */
149 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, /* 0x68-0x6f */
150 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70-0x77 */
151 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, /* 0x78-0x7f */
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
156 0xca, 0xc1, 0xa2, 0xa3, 0x00, 0xb4, 0x00, 0xa4, /* 0xa0-0xa7 */
157 0xac, 0xa9, 0xbb, 0xc7, 0xc2, 0x00, 0xa8, 0xf8, /* 0xa8-0xaf */
158 0xa1, 0xb1, 0x00, 0x00, 0xab, 0xb5, 0xa6, 0xe1, /* 0xb0-0xb7 */
159 0xfc, 0x00, 0xbc, 0xc8, 0x00, 0x00, 0x00, 0xc0, /* 0xb8-0xbf */
160 0xcb, 0xe7, 0xe5, 0xcc, 0x80, 0x81, 0x00, 0x82, /* 0xc0-0xc7 */
161 0xe9, 0x83, 0xe6, 0xe8, 0xed, 0xea, 0xeb, 0xec, /* 0xc8-0xcf */
162 0x00, 0x84, 0xf1, 0xee, 0xef, 0xcd, 0x85, 0x00, /* 0xd0-0xd7 */
163 0x00, 0xf4, 0xf2, 0xf3, 0x86, 0x00, 0x00, 0xa7, /* 0xd8-0xdf */
164 0x88, 0x87, 0x89, 0x8b, 0x8a, 0x8c, 0x00, 0x8d, /* 0xe0-0xe7 */
165 0x8f, 0x8e, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, /* 0xe8-0xef */
166 0x00, 0x96, 0x98, 0x97, 0x99, 0x9b, 0x9a, 0xd6, /* 0xf0-0xf7 */
167 0x00, 0x9d, 0x9c, 0x9e, 0x9f, 0x00, 0x00, 0xd8, /* 0xf8-0xff */
168};
169
170static const unsigned char page01[256] = {
171 0x00, 0x00, 0xae, 0xbe, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
177 0x00, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
181 0x00, 0x00, 0xce, 0xcf, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
186 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
189 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
203};
204
205static const unsigned char page02[256] = {
206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
209 0xaf, 0xbf, 0xde, 0xdf, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xff, /* 0xc0-0xc7 */
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
233 0xf9, 0xfa, 0xfb, 0xfe, 0xf7, 0xfd, 0x00, 0x00, /* 0xd8-0xdf */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
238};
239
240static const unsigned char page03[256] = {
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
262 0x00, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
265 0xb9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
273};
274
275static const unsigned char page20[256] = {
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
278 0x00, 0x00, 0x00, 0xd0, 0xd1, 0x00, 0x00, 0x00, /* 0x10-0x17 */
279 0xd4, 0xd5, 0xe2, 0x00, 0xd2, 0xd3, 0xe3, 0x00, /* 0x18-0x1f */
280 0xa0, 0xe0, 0xa5, 0x00, 0x00, 0x00, 0xc9, 0x00, /* 0x20-0x27 */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
282 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
283 0x00, 0xdc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
284 0x00, 0x00, 0x00, 0x00, 0xda, 0x00, 0x00, 0x00, /* 0x40-0x47 */
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
297 0x00, 0x00, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
308};
309
310static const unsigned char page21[256] = {
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
315 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
336 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
343};
344
345static const unsigned char page22[256] = {
346 0x00, 0x00, 0xb6, 0x00, 0x00, 0x00, 0xc6, 0x00, /* 0x00-0x07 */
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, /* 0x08-0x0f */
348 0x00, 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
349 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0xb0, 0x00, /* 0x18-0x1f */
350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
351 0x00, 0x00, 0x00, 0xba, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
355 0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
358 0xad, 0x00, 0x00, 0x00, 0xb2, 0xb3, 0x00, 0x00, /* 0x60-0x67 */
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
361 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
365 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
366 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
367 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
371 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
373 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
376 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
378};
379
380static const unsigned char page25[256] = {
381 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
382 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
385 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
386 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
387 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
388 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
390 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
391 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
392 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
393 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
394 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
399 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
401 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
405 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
406 0x00, 0x00, 0xd7, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
407 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
408 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
409 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
410 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
411 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
412 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
413};
414
415static const unsigned char pagef8[256] = {
416 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
417 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
418 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
422 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
424 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
425 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
426 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
427 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
428 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
429 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
430 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
433 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
434 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
435 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
436 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
437 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
439 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
440 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
441 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
442 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
443 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
444 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
445 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
446 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
447 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, /* 0xf8-0xff */
448};
449
450static const unsigned char *const page_uni2charset[256] = {
451 page00, page01, page02, page03, NULL, NULL, NULL, NULL,
452 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
453 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
454 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
455 page20, page21, page22, NULL, NULL, page25, NULL, NULL,
456 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
457 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
458 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
459 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
460 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
461 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
462 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
463 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
464 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
465 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
466 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
467 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
468 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
469 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
470 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
471 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
472 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
473 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
474 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
475 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
476 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
477 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
478 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
479 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
480 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
481 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
482 pagef8, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
483};
484
485static const unsigned char charset2lower[256] = {
486 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
487 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
488 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
489 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
490 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
491 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
492 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
493 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
494 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
495 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
496 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
497 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
498 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
499 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
500 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
501 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
502 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
503 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
504 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
505 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
506 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
507 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
508 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
509 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
510 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
511 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
512 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
513 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
514 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
515 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
516 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
517 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
518};
519
520static const unsigned char charset2upper[256] = {
521 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
522 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
523 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
524 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
525 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
526 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
527 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
528 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
529 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
530 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
531 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
532 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
533 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
534 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
535 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
536 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
537 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
538 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
539 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
540 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
541 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
542 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
543 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
544 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
545 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
546 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
547 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
548 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
549 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
550 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
551 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
552 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
553};
554
555static int uni2char(wchar_t uni, unsigned char *out, int boundlen)
556{
557 const unsigned char *uni2charset;
558 unsigned char cl = uni & 0x00ff;
559 unsigned char ch = (uni & 0xff00) >> 8;
560
561 if (boundlen <= 0)
562 return -ENAMETOOLONG;
563
564 uni2charset = page_uni2charset[ch];
565 if (uni2charset && uni2charset[cl])
566 out[0] = uni2charset[cl];
567 else
568 return -EINVAL;
569 return 1;
570}
571
572static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
573{
574 *uni = charset2uni[*rawstring];
575 if (*uni == 0x0000)
576 return -EINVAL;
577 return 1;
578}
579
580static struct nls_table table = {
581 .charset = "macromanian",
582 .uni2char = uni2char,
583 .char2uni = char2uni,
584 .charset2lower = charset2lower,
585 .charset2upper = charset2upper,
586 .owner = THIS_MODULE,
587};
588
589static int __init init_nls_macromanian(void)
590{
591 return register_nls(&table);
592}
593
594static void __exit exit_nls_macromanian(void)
595{
596 unregister_nls(&table);
597}
598
599module_init(init_nls_macromanian)
600module_exit(exit_nls_macromanian)
601
602MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/nls/mac-turkish.c b/fs/nls/mac-turkish.c
new file mode 100644
index 000000000000..dffa96d5de00
--- /dev/null
+++ b/fs/nls/mac-turkish.c
@@ -0,0 +1,602 @@
1/*
2 * linux/fs/nls/mac-turkish.c
3 *
4 * Charset macturkish translation tables.
5 * Generated automatically from the Unicode and charset
6 * tables from the Unicode Organization (www.unicode.org).
7 * The Unicode to charset table has only exact mappings.
8 */
9
10/*
11 * COPYRIGHT AND PERMISSION NOTICE
12 *
13 * Copyright 1991-2012 Unicode, Inc. All rights reserved. Distributed under
14 * the Terms of Use in http://www.unicode.org/copyright.html.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of the Unicode data files and any associated documentation (the "Data
18 * Files") or Unicode software and any associated documentation (the
19 * "Software") to deal in the Data Files or Software without restriction,
20 * including without limitation the rights to use, copy, modify, merge,
21 * publish, distribute, and/or sell copies of the Data Files or Software, and
22 * to permit persons to whom the Data Files or Software are furnished to do
23 * so, provided that (a) the above copyright notice(s) and this permission
24 * notice appear with all copies of the Data Files or Software, (b) both the
25 * above copyright notice(s) and this permission notice appear in associated
26 * documentation, and (c) there is clear notice in each modified Data File or
27 * in the Software as well as in the documentation associated with the Data
28 * File(s) or Software that the data or software has been modified.
29 *
30 * THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
33 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
34 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
35 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
36 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38 * PERFORMANCE OF THE DATA FILES OR SOFTWARE.
39 *
40 * Except as contained in this notice, the name of a copyright holder shall
41 * not be used in advertising or otherwise to promote the sale, use or other
42 * dealings in these Data Files or Software without prior written
43 * authorization of the copyright holder.
44 */
45
46#include <linux/module.h>
47#include <linux/kernel.h>
48#include <linux/string.h>
49#include <linux/nls.h>
50#include <linux/errno.h>
51
52static const wchar_t charset2uni[256] = {
53 /* 0x00 */
54 0x0000, 0x0001, 0x0002, 0x0003,
55 0x0004, 0x0005, 0x0006, 0x0007,
56 0x0008, 0x0009, 0x000a, 0x000b,
57 0x000c, 0x000d, 0x000e, 0x000f,
58 /* 0x10 */
59 0x0010, 0x0011, 0x0012, 0x0013,
60 0x0014, 0x0015, 0x0016, 0x0017,
61 0x0018, 0x0019, 0x001a, 0x001b,
62 0x001c, 0x001d, 0x001e, 0x001f,
63 /* 0x20 */
64 0x0020, 0x0021, 0x0022, 0x0023,
65 0x0024, 0x0025, 0x0026, 0x0027,
66 0x0028, 0x0029, 0x002a, 0x002b,
67 0x002c, 0x002d, 0x002e, 0x002f,
68 /* 0x30 */
69 0x0030, 0x0031, 0x0032, 0x0033,
70 0x0034, 0x0035, 0x0036, 0x0037,
71 0x0038, 0x0039, 0x003a, 0x003b,
72 0x003c, 0x003d, 0x003e, 0x003f,
73 /* 0x40 */
74 0x0040, 0x0041, 0x0042, 0x0043,
75 0x0044, 0x0045, 0x0046, 0x0047,
76 0x0048, 0x0049, 0x004a, 0x004b,
77 0x004c, 0x004d, 0x004e, 0x004f,
78 /* 0x50 */
79 0x0050, 0x0051, 0x0052, 0x0053,
80 0x0054, 0x0055, 0x0056, 0x0057,
81 0x0058, 0x0059, 0x005a, 0x005b,
82 0x005c, 0x005d, 0x005e, 0x005f,
83 /* 0x60 */
84 0x0060, 0x0061, 0x0062, 0x0063,
85 0x0064, 0x0065, 0x0066, 0x0067,
86 0x0068, 0x0069, 0x006a, 0x006b,
87 0x006c, 0x006d, 0x006e, 0x006f,
88 /* 0x70 */
89 0x0070, 0x0071, 0x0072, 0x0073,
90 0x0074, 0x0075, 0x0076, 0x0077,
91 0x0078, 0x0079, 0x007a, 0x007b,
92 0x007c, 0x007d, 0x007e, 0x007f,
93 /* 0x80 */
94 0x00c4, 0x00c5, 0x00c7, 0x00c9,
95 0x00d1, 0x00d6, 0x00dc, 0x00e1,
96 0x00e0, 0x00e2, 0x00e4, 0x00e3,
97 0x00e5, 0x00e7, 0x00e9, 0x00e8,
98 /* 0x90 */
99 0x00ea, 0x00eb, 0x00ed, 0x00ec,
100 0x00ee, 0x00ef, 0x00f1, 0x00f3,
101 0x00f2, 0x00f4, 0x00f6, 0x00f5,
102 0x00fa, 0x00f9, 0x00fb, 0x00fc,
103 /* 0xa0 */
104 0x2020, 0x00b0, 0x00a2, 0x00a3,
105 0x00a7, 0x2022, 0x00b6, 0x00df,
106 0x00ae, 0x00a9, 0x2122, 0x00b4,
107 0x00a8, 0x2260, 0x00c6, 0x00d8,
108 /* 0xb0 */
109 0x221e, 0x00b1, 0x2264, 0x2265,
110 0x00a5, 0x00b5, 0x2202, 0x2211,
111 0x220f, 0x03c0, 0x222b, 0x00aa,
112 0x00ba, 0x03a9, 0x00e6, 0x00f8,
113 /* 0xc0 */
114 0x00bf, 0x00a1, 0x00ac, 0x221a,
115 0x0192, 0x2248, 0x2206, 0x00ab,
116 0x00bb, 0x2026, 0x00a0, 0x00c0,
117 0x00c3, 0x00d5, 0x0152, 0x0153,
118 /* 0xd0 */
119 0x2013, 0x2014, 0x201c, 0x201d,
120 0x2018, 0x2019, 0x00f7, 0x25ca,
121 0x00ff, 0x0178, 0x011e, 0x011f,
122 0x0130, 0x0131, 0x015e, 0x015f,
123 /* 0xe0 */
124 0x2021, 0x00b7, 0x201a, 0x201e,
125 0x2030, 0x00c2, 0x00ca, 0x00c1,
126 0x00cb, 0x00c8, 0x00cd, 0x00ce,
127 0x00cf, 0x00cc, 0x00d3, 0x00d4,
128 /* 0xf0 */
129 0xf8ff, 0x00d2, 0x00da, 0x00db,
130 0x00d9, 0xf8a0, 0x02c6, 0x02dc,
131 0x00af, 0x02d8, 0x02d9, 0x02da,
132 0x00b8, 0x02dd, 0x02db, 0x02c7,
133};
134
135static const unsigned char page00[256] = {
136 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 0x00-0x07 */
137 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 0x08-0x0f */
138 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* 0x10-0x17 */
139 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* 0x18-0x1f */
140 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20-0x27 */
141 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, /* 0x28-0x2f */
142 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30-0x37 */
143 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, /* 0x38-0x3f */
144 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40-0x47 */
145 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* 0x48-0x4f */
146 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50-0x57 */
147 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, /* 0x58-0x5f */
148 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60-0x67 */
149 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, /* 0x68-0x6f */
150 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70-0x77 */
151 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, /* 0x78-0x7f */
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
156 0xca, 0xc1, 0xa2, 0xa3, 0x00, 0xb4, 0x00, 0xa4, /* 0xa0-0xa7 */
157 0xac, 0xa9, 0xbb, 0xc7, 0xc2, 0x00, 0xa8, 0xf8, /* 0xa8-0xaf */
158 0xa1, 0xb1, 0x00, 0x00, 0xab, 0xb5, 0xa6, 0xe1, /* 0xb0-0xb7 */
159 0xfc, 0x00, 0xbc, 0xc8, 0x00, 0x00, 0x00, 0xc0, /* 0xb8-0xbf */
160 0xcb, 0xe7, 0xe5, 0xcc, 0x80, 0x81, 0xae, 0x82, /* 0xc0-0xc7 */
161 0xe9, 0x83, 0xe6, 0xe8, 0xed, 0xea, 0xeb, 0xec, /* 0xc8-0xcf */
162 0x00, 0x84, 0xf1, 0xee, 0xef, 0xcd, 0x85, 0x00, /* 0xd0-0xd7 */
163 0xaf, 0xf4, 0xf2, 0xf3, 0x86, 0x00, 0x00, 0xa7, /* 0xd8-0xdf */
164 0x88, 0x87, 0x89, 0x8b, 0x8a, 0x8c, 0xbe, 0x8d, /* 0xe0-0xe7 */
165 0x8f, 0x8e, 0x90, 0x91, 0x93, 0x92, 0x94, 0x95, /* 0xe8-0xef */
166 0x00, 0x96, 0x98, 0x97, 0x99, 0x9b, 0x9a, 0xd6, /* 0xf0-0xf7 */
167 0xbf, 0x9d, 0x9c, 0x9e, 0x9f, 0x00, 0x00, 0xd8, /* 0xf8-0xff */
168};
169
170static const unsigned char page01[256] = {
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xda, 0xdb, /* 0x18-0x1f */
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
177 0xdc, 0xdd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
181 0x00, 0x00, 0xce, 0xcf, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0xdf, /* 0x58-0x5f */
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
186 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
189 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
199 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
200 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
203};
204
205static const unsigned char page02[256] = {
206 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
208 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
212 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
215 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xff, /* 0xc0-0xc7 */
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
233 0xf9, 0xfa, 0xfb, 0xfe, 0xf7, 0xfd, 0x00, 0x00, /* 0xd8-0xdf */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
238};
239
240static const unsigned char page03[256] = {
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
262 0x00, 0xbd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
265 0xb9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
273};
274
275static const unsigned char page20[256] = {
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
278 0x00, 0x00, 0x00, 0xd0, 0xd1, 0x00, 0x00, 0x00, /* 0x10-0x17 */
279 0xd4, 0xd5, 0xe2, 0x00, 0xd2, 0xd3, 0xe3, 0x00, /* 0x18-0x1f */
280 0xa0, 0xe0, 0xa5, 0x00, 0x00, 0x00, 0xc9, 0x00, /* 0x20-0x27 */
281 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
282 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
283 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
288 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
289 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
290 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
291 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
295 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
298 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
306 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
308};
309
310static const unsigned char page21[256] = {
311 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
312 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
313 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
315 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
317 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
318 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
320 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
321 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
328 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
329 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
330 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
331 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
332 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
333 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
334 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
335 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
336 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
337 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
338 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
339 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
343};
344
345static const unsigned char page22[256] = {
346 0x00, 0x00, 0xb6, 0x00, 0x00, 0x00, 0xc6, 0x00, /* 0x00-0x07 */
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, /* 0x08-0x0f */
348 0x00, 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
349 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0xb0, 0x00, /* 0x18-0x1f */
350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
351 0x00, 0x00, 0x00, 0xba, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
355 0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
358 0xad, 0x00, 0x00, 0x00, 0xb2, 0xb3, 0x00, 0x00, /* 0x60-0x67 */
359 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
361 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
362 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
365 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
366 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
367 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
370 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
371 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
373 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
375 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
376 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
377 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
378};
379
380static const unsigned char page25[256] = {
381 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
382 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
383 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
385 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
386 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
387 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
388 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
389 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
390 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
391 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
392 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
393 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
394 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
396 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
397 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
398 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
399 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
401 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
403 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
404 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
405 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
406 0x00, 0x00, 0xd7, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
407 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
408 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
409 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
410 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
411 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
412 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf8-0xff */
413};
414
415static const unsigned char pagef8[256] = {
416 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00-0x07 */
417 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x08-0x0f */
418 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x10-0x17 */
419 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x18-0x1f */
420 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x27 */
421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x28-0x2f */
422 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x30-0x37 */
423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x38-0x3f */
424 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40-0x47 */
425 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x48-0x4f */
426 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50-0x57 */
427 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x58-0x5f */
428 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60-0x67 */
429 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x68-0x6f */
430 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70-0x77 */
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x78-0x7f */
432 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80-0x87 */
433 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
434 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
435 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
436 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
437 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
439 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
440 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0-0xc7 */
441 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
442 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
443 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
444 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe0-0xe7 */
445 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
446 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xf0-0xf7 */
447 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, /* 0xf8-0xff */
448};
449
450static const unsigned char *const page_uni2charset[256] = {
451 page00, page01, page02, page03, NULL, NULL, NULL, NULL,
452 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
453 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
454 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
455 page20, page21, page22, NULL, NULL, page25, NULL, NULL,
456 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
457 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
458 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
459 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
460 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
461 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
462 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
463 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
464 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
465 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
466 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
467 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
468 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
469 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
470 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
471 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
472 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
473 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
474 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
475 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
476 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
477 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
478 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
479 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
480 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
481 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
482 pagef8, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
483};
484
485static const unsigned char charset2lower[256] = {
486 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
487 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
488 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
489 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
490 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
491 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
492 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
493 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
494 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
495 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
496 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
497 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
498 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
499 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
500 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
501 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
502 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
503 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
504 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
505 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
506 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
507 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
508 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
509 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
510 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
511 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
512 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
513 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
514 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
515 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
516 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
517 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
518};
519
520static const unsigned char charset2upper[256] = {
521 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x00-0x07 */
522 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x08-0x0f */
523 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x10-0x17 */
524 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x18-0x1f */
525 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x20-0x27 */
526 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x28-0x2f */
527 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30-0x37 */
528 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x38-0x3f */
529 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x40-0x47 */
530 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x48-0x4f */
531 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50-0x57 */
532 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x58-0x5f */
533 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x60-0x67 */
534 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x68-0x6f */
535 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x70-0x77 */
536 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x78-0x7f */
537 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x80-0x87 */
538 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x88-0x8f */
539 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x90-0x97 */
540 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x98-0x9f */
541 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa0-0xa7 */
542 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xa8-0xaf */
543 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb0-0xb7 */
544 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xb8-0xbf */
545 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc0-0xc7 */
546 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xc8-0xcf */
547 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd0-0xd7 */
548 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xd8-0xdf */
549 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe0-0xe7 */
550 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xe8-0xef */
551 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf0-0xf7 */
552 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0xf8-0xff */
553};
554
555static int uni2char(wchar_t uni, unsigned char *out, int boundlen)
556{
557 const unsigned char *uni2charset;
558 unsigned char cl = uni & 0x00ff;
559 unsigned char ch = (uni & 0xff00) >> 8;
560
561 if (boundlen <= 0)
562 return -ENAMETOOLONG;
563
564 uni2charset = page_uni2charset[ch];
565 if (uni2charset && uni2charset[cl])
566 out[0] = uni2charset[cl];
567 else
568 return -EINVAL;
569 return 1;
570}
571
572static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni)
573{
574 *uni = charset2uni[*rawstring];
575 if (*uni == 0x0000)
576 return -EINVAL;
577 return 1;
578}
579
580static struct nls_table table = {
581 .charset = "macturkish",
582 .uni2char = uni2char,
583 .char2uni = char2uni,
584 .charset2lower = charset2lower,
585 .charset2upper = charset2upper,
586 .owner = THIS_MODULE,
587};
588
589static int __init init_nls_macturkish(void)
590{
591 return register_nls(&table);
592}
593
594static void __exit exit_nls_macturkish(void)
595{
596 unregister_nls(&table);
597}
598
599module_init(init_nls_macturkish)
600module_exit(exit_nls_macturkish)
601
602MODULE_LICENSE("Dual BSD/GPL");
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index ccb14d3fc0de..b39c5c161adb 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -123,7 +123,7 @@ int __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
123} 123}
124EXPORT_SYMBOL_GPL(__fsnotify_parent); 124EXPORT_SYMBOL_GPL(__fsnotify_parent);
125 125
126static int send_to_group(struct inode *to_tell, struct vfsmount *mnt, 126static int send_to_group(struct inode *to_tell,
127 struct fsnotify_mark *inode_mark, 127 struct fsnotify_mark *inode_mark,
128 struct fsnotify_mark *vfsmount_mark, 128 struct fsnotify_mark *vfsmount_mark,
129 __u32 mask, void *data, 129 __u32 mask, void *data,
@@ -168,10 +168,10 @@ static int send_to_group(struct inode *to_tell, struct vfsmount *mnt,
168 vfsmount_test_mask &= ~inode_mark->ignored_mask; 168 vfsmount_test_mask &= ~inode_mark->ignored_mask;
169 } 169 }
170 170
171 pr_debug("%s: group=%p to_tell=%p mnt=%p mask=%x inode_mark=%p" 171 pr_debug("%s: group=%p to_tell=%p mask=%x inode_mark=%p"
172 " inode_test_mask=%x vfsmount_mark=%p vfsmount_test_mask=%x" 172 " inode_test_mask=%x vfsmount_mark=%p vfsmount_test_mask=%x"
173 " data=%p data_is=%d cookie=%d event=%p\n", 173 " data=%p data_is=%d cookie=%d event=%p\n",
174 __func__, group, to_tell, mnt, mask, inode_mark, 174 __func__, group, to_tell, mask, inode_mark,
175 inode_test_mask, vfsmount_mark, vfsmount_test_mask, data, 175 inode_test_mask, vfsmount_mark, vfsmount_test_mask, data,
176 data_is, cookie, *event); 176 data_is, cookie, *event);
177 177
@@ -258,16 +258,16 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
258 258
259 if (inode_group > vfsmount_group) { 259 if (inode_group > vfsmount_group) {
260 /* handle inode */ 260 /* handle inode */
261 ret = send_to_group(to_tell, NULL, inode_mark, NULL, mask, data, 261 ret = send_to_group(to_tell, inode_mark, NULL, mask, data,
262 data_is, cookie, file_name, &event); 262 data_is, cookie, file_name, &event);
263 /* we didn't use the vfsmount_mark */ 263 /* we didn't use the vfsmount_mark */
264 vfsmount_group = NULL; 264 vfsmount_group = NULL;
265 } else if (vfsmount_group > inode_group) { 265 } else if (vfsmount_group > inode_group) {
266 ret = send_to_group(to_tell, &mnt->mnt, NULL, vfsmount_mark, mask, data, 266 ret = send_to_group(to_tell, NULL, vfsmount_mark, mask, data,
267 data_is, cookie, file_name, &event); 267 data_is, cookie, file_name, &event);
268 inode_group = NULL; 268 inode_group = NULL;
269 } else { 269 } else {
270 ret = send_to_group(to_tell, &mnt->mnt, inode_mark, vfsmount_mark, 270 ret = send_to_group(to_tell, inode_mark, vfsmount_mark,
271 mask, data, data_is, cookie, file_name, 271 mask, data, data_is, cookie, file_name,
272 &event); 272 &event);
273 } 273 }
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 8639169221c7..7389d2d5e51d 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -2096,7 +2096,9 @@ static ssize_t ntfs_file_aio_write_nolock(struct kiocb *iocb,
2096 err = file_remove_suid(file); 2096 err = file_remove_suid(file);
2097 if (err) 2097 if (err)
2098 goto out; 2098 goto out;
2099 file_update_time(file); 2099 err = file_update_time(file);
2100 if (err)
2101 goto out;
2100 written = ntfs_file_buffered_write(iocb, iov, nr_segs, pos, ppos, 2102 written = ntfs_file_buffered_write(iocb, iov, nr_segs, pos, ppos,
2101 count); 2103 count);
2102out: 2104out:
diff --git a/fs/ocfs2/blockcheck.c b/fs/ocfs2/blockcheck.c
index c7ee03c22226..0725e6054650 100644
--- a/fs/ocfs2/blockcheck.c
+++ b/fs/ocfs2/blockcheck.c
@@ -422,45 +422,46 @@ int ocfs2_block_check_validate(void *data, size_t blocksize,
422 struct ocfs2_blockcheck_stats *stats) 422 struct ocfs2_blockcheck_stats *stats)
423{ 423{
424 int rc = 0; 424 int rc = 0;
425 struct ocfs2_block_check check; 425 u32 bc_crc32e;
426 u16 bc_ecc;
426 u32 crc, ecc; 427 u32 crc, ecc;
427 428
428 ocfs2_blockcheck_inc_check(stats); 429 ocfs2_blockcheck_inc_check(stats);
429 430
430 check.bc_crc32e = le32_to_cpu(bc->bc_crc32e); 431 bc_crc32e = le32_to_cpu(bc->bc_crc32e);
431 check.bc_ecc = le16_to_cpu(bc->bc_ecc); 432 bc_ecc = le16_to_cpu(bc->bc_ecc);
432 433
433 memset(bc, 0, sizeof(struct ocfs2_block_check)); 434 memset(bc, 0, sizeof(struct ocfs2_block_check));
434 435
435 /* Fast path - if the crc32 validates, we're good to go */ 436 /* Fast path - if the crc32 validates, we're good to go */
436 crc = crc32_le(~0, data, blocksize); 437 crc = crc32_le(~0, data, blocksize);
437 if (crc == check.bc_crc32e) 438 if (crc == bc_crc32e)
438 goto out; 439 goto out;
439 440
440 ocfs2_blockcheck_inc_failure(stats); 441 ocfs2_blockcheck_inc_failure(stats);
441 mlog(ML_ERROR, 442 mlog(ML_ERROR,
442 "CRC32 failed: stored: 0x%x, computed 0x%x. Applying ECC.\n", 443 "CRC32 failed: stored: 0x%x, computed 0x%x. Applying ECC.\n",
443 (unsigned int)check.bc_crc32e, (unsigned int)crc); 444 (unsigned int)bc_crc32e, (unsigned int)crc);
444 445
445 /* Ok, try ECC fixups */ 446 /* Ok, try ECC fixups */
446 ecc = ocfs2_hamming_encode_block(data, blocksize); 447 ecc = ocfs2_hamming_encode_block(data, blocksize);
447 ocfs2_hamming_fix_block(data, blocksize, ecc ^ check.bc_ecc); 448 ocfs2_hamming_fix_block(data, blocksize, ecc ^ bc_ecc);
448 449
449 /* And check the crc32 again */ 450 /* And check the crc32 again */
450 crc = crc32_le(~0, data, blocksize); 451 crc = crc32_le(~0, data, blocksize);
451 if (crc == check.bc_crc32e) { 452 if (crc == bc_crc32e) {
452 ocfs2_blockcheck_inc_recover(stats); 453 ocfs2_blockcheck_inc_recover(stats);
453 goto out; 454 goto out;
454 } 455 }
455 456
456 mlog(ML_ERROR, "Fixed CRC32 failed: stored: 0x%x, computed 0x%x\n", 457 mlog(ML_ERROR, "Fixed CRC32 failed: stored: 0x%x, computed 0x%x\n",
457 (unsigned int)check.bc_crc32e, (unsigned int)crc); 458 (unsigned int)bc_crc32e, (unsigned int)crc);
458 459
459 rc = -EIO; 460 rc = -EIO;
460 461
461out: 462out:
462 bc->bc_crc32e = cpu_to_le32(check.bc_crc32e); 463 bc->bc_crc32e = cpu_to_le32(bc_crc32e);
463 bc->bc_ecc = cpu_to_le16(check.bc_ecc); 464 bc->bc_ecc = cpu_to_le16(bc_ecc);
464 465
465 return rc; 466 return rc;
466} 467}
@@ -528,7 +529,8 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
528 struct ocfs2_blockcheck_stats *stats) 529 struct ocfs2_blockcheck_stats *stats)
529{ 530{
530 int i, rc = 0; 531 int i, rc = 0;
531 struct ocfs2_block_check check; 532 u32 bc_crc32e;
533 u16 bc_ecc;
532 u32 crc, ecc, fix; 534 u32 crc, ecc, fix;
533 535
534 BUG_ON(nr < 0); 536 BUG_ON(nr < 0);
@@ -538,21 +540,21 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
538 540
539 ocfs2_blockcheck_inc_check(stats); 541 ocfs2_blockcheck_inc_check(stats);
540 542
541 check.bc_crc32e = le32_to_cpu(bc->bc_crc32e); 543 bc_crc32e = le32_to_cpu(bc->bc_crc32e);
542 check.bc_ecc = le16_to_cpu(bc->bc_ecc); 544 bc_ecc = le16_to_cpu(bc->bc_ecc);
543 545
544 memset(bc, 0, sizeof(struct ocfs2_block_check)); 546 memset(bc, 0, sizeof(struct ocfs2_block_check));
545 547
546 /* Fast path - if the crc32 validates, we're good to go */ 548 /* Fast path - if the crc32 validates, we're good to go */
547 for (i = 0, crc = ~0; i < nr; i++) 549 for (i = 0, crc = ~0; i < nr; i++)
548 crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); 550 crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size);
549 if (crc == check.bc_crc32e) 551 if (crc == bc_crc32e)
550 goto out; 552 goto out;
551 553
552 ocfs2_blockcheck_inc_failure(stats); 554 ocfs2_blockcheck_inc_failure(stats);
553 mlog(ML_ERROR, 555 mlog(ML_ERROR,
554 "CRC32 failed: stored: %u, computed %u. Applying ECC.\n", 556 "CRC32 failed: stored: %u, computed %u. Applying ECC.\n",
555 (unsigned int)check.bc_crc32e, (unsigned int)crc); 557 (unsigned int)bc_crc32e, (unsigned int)crc);
556 558
557 /* Ok, try ECC fixups */ 559 /* Ok, try ECC fixups */
558 for (i = 0, ecc = 0; i < nr; i++) { 560 for (i = 0, ecc = 0; i < nr; i++) {
@@ -565,7 +567,7 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
565 bhs[i]->b_size * 8, 567 bhs[i]->b_size * 8,
566 bhs[i]->b_size * 8 * i); 568 bhs[i]->b_size * 8 * i);
567 } 569 }
568 fix = ecc ^ check.bc_ecc; 570 fix = ecc ^ bc_ecc;
569 for (i = 0; i < nr; i++) { 571 for (i = 0; i < nr; i++) {
570 /* 572 /*
571 * Try the fix against each buffer. It will only affect 573 * Try the fix against each buffer. It will only affect
@@ -578,19 +580,19 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
578 /* And check the crc32 again */ 580 /* And check the crc32 again */
579 for (i = 0, crc = ~0; i < nr; i++) 581 for (i = 0, crc = ~0; i < nr; i++)
580 crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); 582 crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size);
581 if (crc == check.bc_crc32e) { 583 if (crc == bc_crc32e) {
582 ocfs2_blockcheck_inc_recover(stats); 584 ocfs2_blockcheck_inc_recover(stats);
583 goto out; 585 goto out;
584 } 586 }
585 587
586 mlog(ML_ERROR, "Fixed CRC32 failed: stored: %u, computed %u\n", 588 mlog(ML_ERROR, "Fixed CRC32 failed: stored: %u, computed %u\n",
587 (unsigned int)check.bc_crc32e, (unsigned int)crc); 589 (unsigned int)bc_crc32e, (unsigned int)crc);
588 590
589 rc = -EIO; 591 rc = -EIO;
590 592
591out: 593out:
592 bc->bc_crc32e = cpu_to_le32(check.bc_crc32e); 594 bc->bc_crc32e = cpu_to_le32(bc_crc32e);
593 bc->bc_ecc = cpu_to_le16(check.bc_ecc); 595 bc->bc_ecc = cpu_to_le16(bc_ecc);
594 596
595 return rc; 597 return rc;
596} 598}
diff --git a/fs/ocfs2/dlm/dlmast.c b/fs/ocfs2/dlm/dlmast.c
index 3a3ed4bb794b..fbec0be62326 100644
--- a/fs/ocfs2/dlm/dlmast.c
+++ b/fs/ocfs2/dlm/dlmast.c
@@ -293,7 +293,7 @@ int dlm_proxy_ast_handler(struct o2net_msg *msg, u32 len, void *data,
293 struct dlm_proxy_ast *past = (struct dlm_proxy_ast *) msg->buf; 293 struct dlm_proxy_ast *past = (struct dlm_proxy_ast *) msg->buf;
294 char *name; 294 char *name;
295 struct list_head *iter, *head=NULL; 295 struct list_head *iter, *head=NULL;
296 u64 cookie; 296 __be64 cookie;
297 u32 flags; 297 u32 flags;
298 u8 node; 298 u8 node;
299 299
diff --git a/fs/ocfs2/dlm/dlmcommon.h b/fs/ocfs2/dlm/dlmcommon.h
index a5952ceecba5..de854cca12a2 100644
--- a/fs/ocfs2/dlm/dlmcommon.h
+++ b/fs/ocfs2/dlm/dlmcommon.h
@@ -679,7 +679,7 @@ struct dlm_query_join_packet {
679}; 679};
680 680
681union dlm_query_join_response { 681union dlm_query_join_response {
682 u32 intval; 682 __be32 intval;
683 struct dlm_query_join_packet packet; 683 struct dlm_query_join_packet packet;
684}; 684};
685 685
@@ -755,8 +755,8 @@ struct dlm_query_region {
755struct dlm_node_info { 755struct dlm_node_info {
756 u8 ni_nodenum; 756 u8 ni_nodenum;
757 u8 pad1; 757 u8 pad1;
758 u16 ni_ipv4_port; 758 __be16 ni_ipv4_port;
759 u32 ni_ipv4_address; 759 __be32 ni_ipv4_address;
760}; 760};
761 761
762struct dlm_query_nodeinfo { 762struct dlm_query_nodeinfo {
diff --git a/fs/ocfs2/dlm/dlmdomain.c b/fs/ocfs2/dlm/dlmdomain.c
index 92f2ead0fab6..9e89d70df337 100644
--- a/fs/ocfs2/dlm/dlmdomain.c
+++ b/fs/ocfs2/dlm/dlmdomain.c
@@ -818,7 +818,7 @@ static void dlm_query_join_packet_to_wire(struct dlm_query_join_packet *packet,
818 union dlm_query_join_response response; 818 union dlm_query_join_response response;
819 819
820 response.packet = *packet; 820 response.packet = *packet;
821 *wire = cpu_to_be32(response.intval); 821 *wire = be32_to_cpu(response.intval);
822} 822}
823 823
824static void dlm_query_join_wire_to_packet(u32 wire, 824static void dlm_query_join_wire_to_packet(u32 wire,
diff --git a/fs/ocfs2/export.c b/fs/ocfs2/export.c
index 745db42528d5..322216a5f0dd 100644
--- a/fs/ocfs2/export.c
+++ b/fs/ocfs2/export.c
@@ -177,21 +177,23 @@ bail:
177 return parent; 177 return parent;
178} 178}
179 179
180static int ocfs2_encode_fh(struct dentry *dentry, u32 *fh_in, int *max_len, 180static int ocfs2_encode_fh(struct inode *inode, u32 *fh_in, int *max_len,
181 int connectable) 181 struct inode *parent)
182{ 182{
183 struct inode *inode = dentry->d_inode;
184 int len = *max_len; 183 int len = *max_len;
185 int type = 1; 184 int type = 1;
186 u64 blkno; 185 u64 blkno;
187 u32 generation; 186 u32 generation;
188 __le32 *fh = (__force __le32 *) fh_in; 187 __le32 *fh = (__force __le32 *) fh_in;
189 188
189#ifdef TRACE_HOOKS_ARE_NOT_BRAINDEAD_IN_YOUR_OPINION
190#error "You go ahead and fix that mess, then. Somehow"
190 trace_ocfs2_encode_fh_begin(dentry, dentry->d_name.len, 191 trace_ocfs2_encode_fh_begin(dentry, dentry->d_name.len,
191 dentry->d_name.name, 192 dentry->d_name.name,
192 fh, len, connectable); 193 fh, len, connectable);
194#endif
193 195
194 if (connectable && (len < 6)) { 196 if (parent && (len < 6)) {
195 *max_len = 6; 197 *max_len = 6;
196 type = 255; 198 type = 255;
197 goto bail; 199 goto bail;
@@ -211,12 +213,7 @@ static int ocfs2_encode_fh(struct dentry *dentry, u32 *fh_in, int *max_len,
211 fh[1] = cpu_to_le32((u32)(blkno & 0xffffffff)); 213 fh[1] = cpu_to_le32((u32)(blkno & 0xffffffff));
212 fh[2] = cpu_to_le32(generation); 214 fh[2] = cpu_to_le32(generation);
213 215
214 if (connectable && !S_ISDIR(inode->i_mode)) { 216 if (parent) {
215 struct inode *parent;
216
217 spin_lock(&dentry->d_lock);
218
219 parent = dentry->d_parent->d_inode;
220 blkno = OCFS2_I(parent)->ip_blkno; 217 blkno = OCFS2_I(parent)->ip_blkno;
221 generation = parent->i_generation; 218 generation = parent->i_generation;
222 219
@@ -224,8 +221,6 @@ static int ocfs2_encode_fh(struct dentry *dentry, u32 *fh_in, int *max_len,
224 fh[4] = cpu_to_le32((u32)(blkno & 0xffffffff)); 221 fh[4] = cpu_to_le32((u32)(blkno & 0xffffffff));
225 fh[5] = cpu_to_le32(generation); 222 fh[5] = cpu_to_le32(generation);
226 223
227 spin_unlock(&dentry->d_lock);
228
229 len = 6; 224 len = 6;
230 type = 2; 225 type = 2;
231 226
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index 735514ca400f..d89e08a81eda 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -273,11 +273,13 @@ void ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
273 inode->i_gid = le32_to_cpu(fe->i_gid); 273 inode->i_gid = le32_to_cpu(fe->i_gid);
274 274
275 /* Fast symlinks will have i_size but no allocated clusters. */ 275 /* Fast symlinks will have i_size but no allocated clusters. */
276 if (S_ISLNK(inode->i_mode) && !fe->i_clusters) 276 if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
277 inode->i_blocks = 0; 277 inode->i_blocks = 0;
278 else 278 inode->i_mapping->a_ops = &ocfs2_fast_symlink_aops;
279 } else {
279 inode->i_blocks = ocfs2_inode_sector_count(inode); 280 inode->i_blocks = ocfs2_inode_sector_count(inode);
280 inode->i_mapping->a_ops = &ocfs2_aops; 281 inode->i_mapping->a_ops = &ocfs2_aops;
282 }
281 inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime); 283 inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime);
282 inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec); 284 inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec);
283 inode->i_mtime.tv_sec = le64_to_cpu(fe->i_mtime); 285 inode->i_mtime.tv_sec = le64_to_cpu(fe->i_mtime);
@@ -331,10 +333,7 @@ void ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
331 OCFS2_I(inode)->ip_dir_lock_gen = 1; 333 OCFS2_I(inode)->ip_dir_lock_gen = 1;
332 break; 334 break;
333 case S_IFLNK: 335 case S_IFLNK:
334 if (ocfs2_inode_is_fast_symlink(inode)) 336 inode->i_op = &ocfs2_symlink_inode_operations;
335 inode->i_op = &ocfs2_fast_symlink_inode_operations;
336 else
337 inode->i_op = &ocfs2_symlink_inode_operations;
338 i_size_write(inode, le64_to_cpu(fe->i_size)); 337 i_size_write(inode, le64_to_cpu(fe->i_size));
339 break; 338 break;
340 default: 339 default:
diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
index a1a1bfd652c9..d96f7f81d8dd 100644
--- a/fs/ocfs2/ioctl.c
+++ b/fs/ocfs2/ioctl.c
@@ -864,7 +864,7 @@ int ocfs2_info_handle(struct inode *inode, struct ocfs2_info *info,
864 if (status) 864 if (status)
865 break; 865 break;
866 866
867 reqp = (struct ocfs2_info_request *)(unsigned long)req_addr; 867 reqp = (struct ocfs2_info_request __user *)(unsigned long)req_addr;
868 if (!reqp) { 868 if (!reqp) {
869 status = -EINVAL; 869 status = -EINVAL;
870 goto bail; 870 goto bail;
@@ -888,9 +888,11 @@ long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
888 struct ocfs2_space_resv sr; 888 struct ocfs2_space_resv sr;
889 struct ocfs2_new_group_input input; 889 struct ocfs2_new_group_input input;
890 struct reflink_arguments args; 890 struct reflink_arguments args;
891 const char *old_path, *new_path; 891 const char __user *old_path;
892 const char __user *new_path;
892 bool preserve; 893 bool preserve;
893 struct ocfs2_info info; 894 struct ocfs2_info info;
895 void __user *argp = (void __user *)arg;
894 896
895 switch (cmd) { 897 switch (cmd) {
896 case OCFS2_IOC_GETFLAGS: 898 case OCFS2_IOC_GETFLAGS:
@@ -937,17 +939,15 @@ long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
937 939
938 return ocfs2_group_add(inode, &input); 940 return ocfs2_group_add(inode, &input);
939 case OCFS2_IOC_REFLINK: 941 case OCFS2_IOC_REFLINK:
940 if (copy_from_user(&args, (struct reflink_arguments *)arg, 942 if (copy_from_user(&args, argp, sizeof(args)))
941 sizeof(args)))
942 return -EFAULT; 943 return -EFAULT;
943 old_path = (const char *)(unsigned long)args.old_path; 944 old_path = (const char __user *)(unsigned long)args.old_path;
944 new_path = (const char *)(unsigned long)args.new_path; 945 new_path = (const char __user *)(unsigned long)args.new_path;
945 preserve = (args.preserve != 0); 946 preserve = (args.preserve != 0);
946 947
947 return ocfs2_reflink_ioctl(inode, old_path, new_path, preserve); 948 return ocfs2_reflink_ioctl(inode, old_path, new_path, preserve);
948 case OCFS2_IOC_INFO: 949 case OCFS2_IOC_INFO:
949 if (copy_from_user(&info, (struct ocfs2_info __user *)arg, 950 if (copy_from_user(&info, argp, sizeof(struct ocfs2_info)))
950 sizeof(struct ocfs2_info)))
951 return -EFAULT; 951 return -EFAULT;
952 952
953 return ocfs2_info_handle(inode, &info, 0); 953 return ocfs2_info_handle(inode, &info, 0);
@@ -960,22 +960,20 @@ long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
960 if (!capable(CAP_SYS_ADMIN)) 960 if (!capable(CAP_SYS_ADMIN))
961 return -EPERM; 961 return -EPERM;
962 962
963 if (copy_from_user(&range, (struct fstrim_range *)arg, 963 if (copy_from_user(&range, argp, sizeof(range)))
964 sizeof(range)))
965 return -EFAULT; 964 return -EFAULT;
966 965
967 ret = ocfs2_trim_fs(sb, &range); 966 ret = ocfs2_trim_fs(sb, &range);
968 if (ret < 0) 967 if (ret < 0)
969 return ret; 968 return ret;
970 969
971 if (copy_to_user((struct fstrim_range *)arg, &range, 970 if (copy_to_user(argp, &range, sizeof(range)))
972 sizeof(range)))
973 return -EFAULT; 971 return -EFAULT;
974 972
975 return 0; 973 return 0;
976 } 974 }
977 case OCFS2_IOC_MOVE_EXT: 975 case OCFS2_IOC_MOVE_EXT:
978 return ocfs2_ioctl_move_extents(filp, (void __user *)arg); 976 return ocfs2_ioctl_move_extents(filp, argp);
979 default: 977 default:
980 return -ENOTTY; 978 return -ENOTTY;
981 } 979 }
@@ -988,6 +986,7 @@ long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg)
988 struct reflink_arguments args; 986 struct reflink_arguments args;
989 struct inode *inode = file->f_path.dentry->d_inode; 987 struct inode *inode = file->f_path.dentry->d_inode;
990 struct ocfs2_info info; 988 struct ocfs2_info info;
989 void __user *argp = (void __user *)arg;
991 990
992 switch (cmd) { 991 switch (cmd) {
993 case OCFS2_IOC32_GETFLAGS: 992 case OCFS2_IOC32_GETFLAGS:
@@ -1006,16 +1005,14 @@ long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg)
1006 case FITRIM: 1005 case FITRIM:
1007 break; 1006 break;
1008 case OCFS2_IOC_REFLINK: 1007 case OCFS2_IOC_REFLINK:
1009 if (copy_from_user(&args, (struct reflink_arguments *)arg, 1008 if (copy_from_user(&args, argp, sizeof(args)))
1010 sizeof(args)))
1011 return -EFAULT; 1009 return -EFAULT;
1012 preserve = (args.preserve != 0); 1010 preserve = (args.preserve != 0);
1013 1011
1014 return ocfs2_reflink_ioctl(inode, compat_ptr(args.old_path), 1012 return ocfs2_reflink_ioctl(inode, compat_ptr(args.old_path),
1015 compat_ptr(args.new_path), preserve); 1013 compat_ptr(args.new_path), preserve);
1016 case OCFS2_IOC_INFO: 1014 case OCFS2_IOC_INFO:
1017 if (copy_from_user(&info, (struct ocfs2_info __user *)arg, 1015 if (copy_from_user(&info, argp, sizeof(struct ocfs2_info)))
1018 sizeof(struct ocfs2_info)))
1019 return -EFAULT; 1016 return -EFAULT;
1020 1017
1021 return ocfs2_info_handle(inode, &info, 1); 1018 return ocfs2_info_handle(inode, &info, 1);
diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
index b1e3fce72ea4..6083432f667e 100644
--- a/fs/ocfs2/move_extents.c
+++ b/fs/ocfs2/move_extents.c
@@ -1082,8 +1082,7 @@ int ocfs2_ioctl_move_extents(struct file *filp, void __user *argp)
1082 context->file = filp; 1082 context->file = filp;
1083 1083
1084 if (argp) { 1084 if (argp) {
1085 if (copy_from_user(&range, (struct ocfs2_move_extents *)argp, 1085 if (copy_from_user(&range, argp, sizeof(range))) {
1086 sizeof(range))) {
1087 status = -EFAULT; 1086 status = -EFAULT;
1088 goto out; 1087 goto out;
1089 } 1088 }
@@ -1138,8 +1137,7 @@ out:
1138 * length and new_offset even if failure happens somewhere. 1137 * length and new_offset even if failure happens somewhere.
1139 */ 1138 */
1140 if (argp) { 1139 if (argp) {
1141 if (copy_to_user((struct ocfs2_move_extents *)argp, &range, 1140 if (copy_to_user(argp, &range, sizeof(range)))
1142 sizeof(range)))
1143 status = -EFAULT; 1141 status = -EFAULT;
1144 } 1142 }
1145 1143
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index a9856e3eaaf0..9f39c640cddf 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -1724,15 +1724,16 @@ static int ocfs2_symlink(struct inode *dir,
1724 fe = (struct ocfs2_dinode *) new_fe_bh->b_data; 1724 fe = (struct ocfs2_dinode *) new_fe_bh->b_data;
1725 inode->i_rdev = 0; 1725 inode->i_rdev = 0;
1726 newsize = l - 1; 1726 newsize = l - 1;
1727 inode->i_op = &ocfs2_symlink_inode_operations;
1727 if (l > ocfs2_fast_symlink_chars(sb)) { 1728 if (l > ocfs2_fast_symlink_chars(sb)) {
1728 u32 offset = 0; 1729 u32 offset = 0;
1729 1730
1730 inode->i_op = &ocfs2_symlink_inode_operations;
1731 status = dquot_alloc_space_nodirty(inode, 1731 status = dquot_alloc_space_nodirty(inode,
1732 ocfs2_clusters_to_bytes(osb->sb, 1)); 1732 ocfs2_clusters_to_bytes(osb->sb, 1));
1733 if (status) 1733 if (status)
1734 goto bail; 1734 goto bail;
1735 did_quota = 1; 1735 did_quota = 1;
1736 inode->i_mapping->a_ops = &ocfs2_aops;
1736 status = ocfs2_add_inode_data(osb, inode, &offset, 1, 0, 1737 status = ocfs2_add_inode_data(osb, inode, &offset, 1, 0,
1737 new_fe_bh, 1738 new_fe_bh,
1738 handle, data_ac, NULL, 1739 handle, data_ac, NULL,
@@ -1750,7 +1751,7 @@ static int ocfs2_symlink(struct inode *dir,
1750 i_size_write(inode, newsize); 1751 i_size_write(inode, newsize);
1751 inode->i_blocks = ocfs2_inode_sector_count(inode); 1752 inode->i_blocks = ocfs2_inode_sector_count(inode);
1752 } else { 1753 } else {
1753 inode->i_op = &ocfs2_fast_symlink_inode_operations; 1754 inode->i_mapping->a_ops = &ocfs2_fast_symlink_aops;
1754 memcpy((char *) fe->id2.i_symlink, symname, l); 1755 memcpy((char *) fe->id2.i_symlink, symname, l);
1755 i_size_write(inode, newsize); 1756 i_size_write(inode, newsize);
1756 inode->i_blocks = 0; 1757 inode->i_blocks = 0;
diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
index 5d22872e2bb3..f1fbb4b552ad 100644
--- a/fs/ocfs2/symlink.c
+++ b/fs/ocfs2/symlink.c
@@ -54,101 +54,40 @@
54#include "buffer_head_io.h" 54#include "buffer_head_io.h"
55 55
56 56
57static char *ocfs2_fast_symlink_getlink(struct inode *inode, 57static int ocfs2_fast_symlink_readpage(struct file *unused, struct page *page)
58 struct buffer_head **bh)
59{ 58{
60 int status; 59 struct inode *inode = page->mapping->host;
61 char *link = NULL; 60 struct buffer_head *bh;
61 int status = ocfs2_read_inode_block(inode, &bh);
62 struct ocfs2_dinode *fe; 62 struct ocfs2_dinode *fe;
63 const char *link;
64 void *kaddr;
65 size_t len;
63 66
64 status = ocfs2_read_inode_block(inode, bh);
65 if (status < 0) { 67 if (status < 0) {
66 mlog_errno(status); 68 mlog_errno(status);
67 link = ERR_PTR(status); 69 return status;
68 goto bail;
69 } 70 }
70 71
71 fe = (struct ocfs2_dinode *) (*bh)->b_data; 72 fe = (struct ocfs2_dinode *) bh->b_data;
72 link = (char *) fe->id2.i_symlink; 73 link = (char *) fe->id2.i_symlink;
73bail: 74 /* will be less than a page size */
74 75 len = strnlen(link, ocfs2_fast_symlink_chars(inode->i_sb));
75 return link; 76 kaddr = kmap_atomic(page);
76} 77 memcpy(kaddr, link, len + 1);
77 78 kunmap_atomic(kaddr);
78static int ocfs2_readlink(struct dentry *dentry, 79 SetPageUptodate(page);
79 char __user *buffer, 80 unlock_page(page);
80 int buflen)
81{
82 int ret;
83 char *link;
84 struct buffer_head *bh = NULL;
85 struct inode *inode = dentry->d_inode;
86
87 link = ocfs2_fast_symlink_getlink(inode, &bh);
88 if (IS_ERR(link)) {
89 ret = PTR_ERR(link);
90 goto out;
91 }
92
93 /*
94 * Without vfsmount we can't update atime now,
95 * but we will update atime here ultimately.
96 */
97 ret = vfs_readlink(dentry, buffer, buflen, link);
98
99 brelse(bh); 81 brelse(bh);
100out: 82 return 0;
101 if (ret < 0)
102 mlog_errno(ret);
103 return ret;
104} 83}
105 84
106static void *ocfs2_fast_follow_link(struct dentry *dentry, 85const struct address_space_operations ocfs2_fast_symlink_aops = {
107 struct nameidata *nd) 86 .readpage = ocfs2_fast_symlink_readpage,
108{ 87};
109 int status = 0;
110 int len;
111 char *target, *link = ERR_PTR(-ENOMEM);
112 struct inode *inode = dentry->d_inode;
113 struct buffer_head *bh = NULL;
114
115 BUG_ON(!ocfs2_inode_is_fast_symlink(inode));
116 target = ocfs2_fast_symlink_getlink(inode, &bh);
117 if (IS_ERR(target)) {
118 status = PTR_ERR(target);
119 mlog_errno(status);
120 goto bail;
121 }
122
123 /* Fast symlinks can't be large */
124 len = strnlen(target, ocfs2_fast_symlink_chars(inode->i_sb));
125 link = kzalloc(len + 1, GFP_NOFS);
126 if (!link) {
127 status = -ENOMEM;
128 mlog_errno(status);
129 goto bail;
130 }
131
132 memcpy(link, target, len);
133
134bail:
135 nd_set_link(nd, status ? ERR_PTR(status) : link);
136 brelse(bh);
137
138 if (status)
139 mlog_errno(status);
140 return NULL;
141}
142
143static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
144{
145 char *link = nd_get_link(nd);
146 if (!IS_ERR(link))
147 kfree(link);
148}
149 88
150const struct inode_operations ocfs2_symlink_inode_operations = { 89const struct inode_operations ocfs2_symlink_inode_operations = {
151 .readlink = page_readlink, 90 .readlink = generic_readlink,
152 .follow_link = page_follow_link_light, 91 .follow_link = page_follow_link_light,
153 .put_link = page_put_link, 92 .put_link = page_put_link,
154 .getattr = ocfs2_getattr, 93 .getattr = ocfs2_getattr,
@@ -159,15 +98,3 @@ const struct inode_operations ocfs2_symlink_inode_operations = {
159 .removexattr = generic_removexattr, 98 .removexattr = generic_removexattr,
160 .fiemap = ocfs2_fiemap, 99 .fiemap = ocfs2_fiemap,
161}; 100};
162const struct inode_operations ocfs2_fast_symlink_inode_operations = {
163 .readlink = ocfs2_readlink,
164 .follow_link = ocfs2_fast_follow_link,
165 .put_link = ocfs2_fast_put_link,
166 .getattr = ocfs2_getattr,
167 .setattr = ocfs2_setattr,
168 .setxattr = generic_setxattr,
169 .getxattr = generic_getxattr,
170 .listxattr = ocfs2_listxattr,
171 .removexattr = generic_removexattr,
172 .fiemap = ocfs2_fiemap,
173};
diff --git a/fs/ocfs2/symlink.h b/fs/ocfs2/symlink.h
index 65a6c9c6ad51..71ee4245e919 100644
--- a/fs/ocfs2/symlink.h
+++ b/fs/ocfs2/symlink.h
@@ -27,7 +27,7 @@
27#define OCFS2_SYMLINK_H 27#define OCFS2_SYMLINK_H
28 28
29extern const struct inode_operations ocfs2_symlink_inode_operations; 29extern const struct inode_operations ocfs2_symlink_inode_operations;
30extern const struct inode_operations ocfs2_fast_symlink_inode_operations; 30extern const struct address_space_operations ocfs2_fast_symlink_aops;
31 31
32/* 32/*
33 * Test whether an inode is a fast symlink. 33 * Test whether an inode is a fast symlink.
diff --git a/fs/open.c b/fs/open.c
index d54301219d04..d6c79a0dffc7 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -654,10 +654,23 @@ static inline int __get_file_write_access(struct inode *inode,
654 return error; 654 return error;
655} 655}
656 656
657static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, 657int open_check_o_direct(struct file *f)
658 struct file *f, 658{
659 int (*open)(struct inode *, struct file *), 659 /* NB: we're sure to have correct a_ops only after f_op->open */
660 const struct cred *cred) 660 if (f->f_flags & O_DIRECT) {
661 if (!f->f_mapping->a_ops ||
662 ((!f->f_mapping->a_ops->direct_IO) &&
663 (!f->f_mapping->a_ops->get_xip_mem))) {
664 return -EINVAL;
665 }
666 }
667 return 0;
668}
669
670static struct file *do_dentry_open(struct dentry *dentry, struct vfsmount *mnt,
671 struct file *f,
672 int (*open)(struct inode *, struct file *),
673 const struct cred *cred)
661{ 674{
662 static const struct file_operations empty_fops = {}; 675 static const struct file_operations empty_fops = {};
663 struct inode *inode; 676 struct inode *inode;
@@ -713,16 +726,6 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
713 726
714 file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping); 727 file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping);
715 728
716 /* NB: we're sure to have correct a_ops only after f_op->open */
717 if (f->f_flags & O_DIRECT) {
718 if (!f->f_mapping->a_ops ||
719 ((!f->f_mapping->a_ops->direct_IO) &&
720 (!f->f_mapping->a_ops->get_xip_mem))) {
721 fput(f);
722 f = ERR_PTR(-EINVAL);
723 }
724 }
725
726 return f; 729 return f;
727 730
728cleanup_all: 731cleanup_all:
@@ -744,12 +747,29 @@ cleanup_all:
744 f->f_path.dentry = NULL; 747 f->f_path.dentry = NULL;
745 f->f_path.mnt = NULL; 748 f->f_path.mnt = NULL;
746cleanup_file: 749cleanup_file:
747 put_filp(f);
748 dput(dentry); 750 dput(dentry);
749 mntput(mnt); 751 mntput(mnt);
750 return ERR_PTR(error); 752 return ERR_PTR(error);
751} 753}
752 754
755static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
756 struct file *f,
757 int (*open)(struct inode *, struct file *),
758 const struct cred *cred)
759{
760 struct file *res = do_dentry_open(dentry, mnt, f, open, cred);
761 if (!IS_ERR(res)) {
762 int error = open_check_o_direct(f);
763 if (error) {
764 fput(res);
765 res = ERR_PTR(error);
766 }
767 } else {
768 put_filp(f);
769 }
770 return res;
771}
772
753/** 773/**
754 * lookup_instantiate_filp - instantiates the open intent filp 774 * lookup_instantiate_filp - instantiates the open intent filp
755 * @nd: pointer to nameidata 775 * @nd: pointer to nameidata
@@ -804,13 +824,31 @@ struct file *nameidata_to_filp(struct nameidata *nd)
804 824
805 /* Pick up the filp from the open intent */ 825 /* Pick up the filp from the open intent */
806 filp = nd->intent.open.file; 826 filp = nd->intent.open.file;
807 nd->intent.open.file = NULL;
808 827
809 /* Has the filesystem initialised the file for us? */ 828 /* Has the filesystem initialised the file for us? */
810 if (filp->f_path.dentry == NULL) { 829 if (filp->f_path.dentry != NULL) {
830 nd->intent.open.file = NULL;
831 } else {
832 struct file *res;
833
811 path_get(&nd->path); 834 path_get(&nd->path);
812 filp = __dentry_open(nd->path.dentry, nd->path.mnt, filp, 835 res = do_dentry_open(nd->path.dentry, nd->path.mnt,
813 NULL, cred); 836 filp, NULL, cred);
837 if (!IS_ERR(res)) {
838 int error;
839
840 nd->intent.open.file = NULL;
841 BUG_ON(res != filp);
842
843 error = open_check_o_direct(filp);
844 if (error) {
845 fput(filp);
846 filp = ERR_PTR(error);
847 }
848 } else {
849 /* Allow nd->intent.open.file to be recycled */
850 filp = res;
851 }
814 } 852 }
815 return filp; 853 return filp;
816} 854}
diff --git a/fs/pipe.c b/fs/pipe.c
index fec5e4ad071a..49c1065256fd 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -654,8 +654,11 @@ out:
654 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM); 654 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLRDNORM);
655 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN); 655 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
656 } 656 }
657 if (ret > 0) 657 if (ret > 0) {
658 file_update_time(filp); 658 int err = file_update_time(filp);
659 if (err)
660 ret = err;
661 }
659 return ret; 662 return ret;
660} 663}
661 664
@@ -693,7 +696,7 @@ static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
693 696
694 return put_user(count, (int __user *)arg); 697 return put_user(count, (int __user *)arg);
695 default: 698 default:
696 return -EINVAL; 699 return -ENOIOCTLCMD;
697 } 700 }
698} 701}
699 702
diff --git a/fs/pnode.c b/fs/pnode.c
index ab5fa9e1a79a..bed378db0758 100644
--- a/fs/pnode.c
+++ b/fs/pnode.c
@@ -257,12 +257,12 @@ int propagate_mnt(struct mount *dest_mnt, struct dentry *dest_dentry,
257 prev_src_mnt = child; 257 prev_src_mnt = child;
258 } 258 }
259out: 259out:
260 br_write_lock(vfsmount_lock); 260 br_write_lock(&vfsmount_lock);
261 while (!list_empty(&tmp_list)) { 261 while (!list_empty(&tmp_list)) {
262 child = list_first_entry(&tmp_list, struct mount, mnt_hash); 262 child = list_first_entry(&tmp_list, struct mount, mnt_hash);
263 umount_tree(child, 0, &umount_list); 263 umount_tree(child, 0, &umount_list);
264 } 264 }
265 br_write_unlock(vfsmount_lock); 265 br_write_unlock(&vfsmount_lock);
266 release_mounts(&umount_list); 266 release_mounts(&umount_list);
267 return ret; 267 return ret;
268} 268}
diff --git a/fs/proc/array.c b/fs/proc/array.c
index dc4c5a7b9ece..c1c207c36cae 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -370,7 +370,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
370 struct pid *pid, struct task_struct *task, int whole) 370 struct pid *pid, struct task_struct *task, int whole)
371{ 371{
372 unsigned long vsize, eip, esp, wchan = ~0UL; 372 unsigned long vsize, eip, esp, wchan = ~0UL;
373 long priority, nice; 373 int priority, nice;
374 int tty_pgrp = -1, tty_nr = 0; 374 int tty_pgrp = -1, tty_nr = 0;
375 sigset_t sigign, sigcatch; 375 sigset_t sigign, sigcatch;
376 char state; 376 char state;
@@ -492,7 +492,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
492 seq_put_decimal_ull(m, ' ', 0); 492 seq_put_decimal_ull(m, ' ', 0);
493 seq_put_decimal_ull(m, ' ', start_time); 493 seq_put_decimal_ull(m, ' ', start_time);
494 seq_put_decimal_ull(m, ' ', vsize); 494 seq_put_decimal_ull(m, ' ', vsize);
495 seq_put_decimal_ll(m, ' ', mm ? get_mm_rss(mm) : 0); 495 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
496 seq_put_decimal_ull(m, ' ', rsslim); 496 seq_put_decimal_ull(m, ' ', rsslim);
497 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0); 497 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
498 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0); 498 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
@@ -517,9 +517,23 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
517 seq_put_decimal_ull(m, ' ', delayacct_blkio_ticks(task)); 517 seq_put_decimal_ull(m, ' ', delayacct_blkio_ticks(task));
518 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime)); 518 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
519 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime)); 519 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
520 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_data : 0); 520
521 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->end_data : 0); 521 if (mm && permitted) {
522 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_brk : 0); 522 seq_put_decimal_ull(m, ' ', mm->start_data);
523 seq_put_decimal_ull(m, ' ', mm->end_data);
524 seq_put_decimal_ull(m, ' ', mm->start_brk);
525 seq_put_decimal_ull(m, ' ', mm->arg_start);
526 seq_put_decimal_ull(m, ' ', mm->arg_end);
527 seq_put_decimal_ull(m, ' ', mm->env_start);
528 seq_put_decimal_ull(m, ' ', mm->env_end);
529 } else
530 seq_printf(m, " 0 0 0 0 0 0 0");
531
532 if (permitted)
533 seq_put_decimal_ll(m, ' ', task->exit_code);
534 else
535 seq_put_decimal_ll(m, ' ', 0);
536
523 seq_putc(m, '\n'); 537 seq_putc(m, '\n');
524 if (mm) 538 if (mm)
525 mmput(mm); 539 mmput(mm);
@@ -565,3 +579,126 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
565 579
566 return 0; 580 return 0;
567} 581}
582
583#ifdef CONFIG_CHECKPOINT_RESTORE
584static struct pid *
585get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
586{
587 struct task_struct *start, *task;
588 struct pid *pid = NULL;
589
590 read_lock(&tasklist_lock);
591
592 start = pid_task(proc_pid(inode), PIDTYPE_PID);
593 if (!start)
594 goto out;
595
596 /*
597 * Lets try to continue searching first, this gives
598 * us significant speedup on children-rich processes.
599 */
600 if (pid_prev) {
601 task = pid_task(pid_prev, PIDTYPE_PID);
602 if (task && task->real_parent == start &&
603 !(list_empty(&task->sibling))) {
604 if (list_is_last(&task->sibling, &start->children))
605 goto out;
606 task = list_first_entry(&task->sibling,
607 struct task_struct, sibling);
608 pid = get_pid(task_pid(task));
609 goto out;
610 }
611 }
612
613 /*
614 * Slow search case.
615 *
616 * We might miss some children here if children
617 * are exited while we were not holding the lock,
618 * but it was never promised to be accurate that
619 * much.
620 *
621 * "Just suppose that the parent sleeps, but N children
622 * exit after we printed their tids. Now the slow paths
623 * skips N extra children, we miss N tasks." (c)
624 *
625 * So one need to stop or freeze the leader and all
626 * its children to get a precise result.
627 */
628 list_for_each_entry(task, &start->children, sibling) {
629 if (pos-- == 0) {
630 pid = get_pid(task_pid(task));
631 break;
632 }
633 }
634
635out:
636 read_unlock(&tasklist_lock);
637 return pid;
638}
639
640static int children_seq_show(struct seq_file *seq, void *v)
641{
642 struct inode *inode = seq->private;
643 pid_t pid;
644
645 pid = pid_nr_ns(v, inode->i_sb->s_fs_info);
646 return seq_printf(seq, "%d ", pid);
647}
648
649static void *children_seq_start(struct seq_file *seq, loff_t *pos)
650{
651 return get_children_pid(seq->private, NULL, *pos);
652}
653
654static void *children_seq_next(struct seq_file *seq, void *v, loff_t *pos)
655{
656 struct pid *pid;
657
658 pid = get_children_pid(seq->private, v, *pos + 1);
659 put_pid(v);
660
661 ++*pos;
662 return pid;
663}
664
665static void children_seq_stop(struct seq_file *seq, void *v)
666{
667 put_pid(v);
668}
669
670static const struct seq_operations children_seq_ops = {
671 .start = children_seq_start,
672 .next = children_seq_next,
673 .stop = children_seq_stop,
674 .show = children_seq_show,
675};
676
677static int children_seq_open(struct inode *inode, struct file *file)
678{
679 struct seq_file *m;
680 int ret;
681
682 ret = seq_open(file, &children_seq_ops);
683 if (ret)
684 return ret;
685
686 m = file->private_data;
687 m->private = inode;
688
689 return ret;
690}
691
692int children_seq_release(struct inode *inode, struct file *file)
693{
694 seq_release(inode, file);
695 return 0;
696}
697
698const struct file_operations proc_tid_children_operations = {
699 .open = children_seq_open,
700 .read = seq_read,
701 .llseek = seq_lseek,
702 .release = children_seq_release,
703};
704#endif /* CONFIG_CHECKPOINT_RESTORE */
diff --git a/fs/proc/base.c b/fs/proc/base.c
index d7d711876b6a..616f41a7cde6 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -199,11 +199,6 @@ static int proc_root_link(struct dentry *dentry, struct path *path)
199 return result; 199 return result;
200} 200}
201 201
202struct mm_struct *mm_for_maps(struct task_struct *task)
203{
204 return mm_access(task, PTRACE_MODE_READ);
205}
206
207static int proc_pid_cmdline(struct task_struct *task, char * buffer) 202static int proc_pid_cmdline(struct task_struct *task, char * buffer)
208{ 203{
209 int res = 0; 204 int res = 0;
@@ -243,7 +238,7 @@ out:
243 238
244static int proc_pid_auxv(struct task_struct *task, char *buffer) 239static int proc_pid_auxv(struct task_struct *task, char *buffer)
245{ 240{
246 struct mm_struct *mm = mm_for_maps(task); 241 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
247 int res = PTR_ERR(mm); 242 int res = PTR_ERR(mm);
248 if (mm && !IS_ERR(mm)) { 243 if (mm && !IS_ERR(mm)) {
249 unsigned int nwords = 0; 244 unsigned int nwords = 0;
@@ -679,7 +674,7 @@ static const struct file_operations proc_single_file_operations = {
679 .release = single_release, 674 .release = single_release,
680}; 675};
681 676
682static int mem_open(struct inode* inode, struct file* file) 677static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
683{ 678{
684 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode); 679 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
685 struct mm_struct *mm; 680 struct mm_struct *mm;
@@ -687,7 +682,7 @@ static int mem_open(struct inode* inode, struct file* file)
687 if (!task) 682 if (!task)
688 return -ESRCH; 683 return -ESRCH;
689 684
690 mm = mm_access(task, PTRACE_MODE_ATTACH); 685 mm = mm_access(task, mode);
691 put_task_struct(task); 686 put_task_struct(task);
692 687
693 if (IS_ERR(mm)) 688 if (IS_ERR(mm))
@@ -707,6 +702,11 @@ static int mem_open(struct inode* inode, struct file* file)
707 return 0; 702 return 0;
708} 703}
709 704
705static int mem_open(struct inode *inode, struct file *file)
706{
707 return __mem_open(inode, file, PTRACE_MODE_ATTACH);
708}
709
710static ssize_t mem_rw(struct file *file, char __user *buf, 710static ssize_t mem_rw(struct file *file, char __user *buf,
711 size_t count, loff_t *ppos, int write) 711 size_t count, loff_t *ppos, int write)
712{ 712{
@@ -803,30 +803,29 @@ static const struct file_operations proc_mem_operations = {
803 .release = mem_release, 803 .release = mem_release,
804}; 804};
805 805
806static int environ_open(struct inode *inode, struct file *file)
807{
808 return __mem_open(inode, file, PTRACE_MODE_READ);
809}
810
806static ssize_t environ_read(struct file *file, char __user *buf, 811static ssize_t environ_read(struct file *file, char __user *buf,
807 size_t count, loff_t *ppos) 812 size_t count, loff_t *ppos)
808{ 813{
809 struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
810 char *page; 814 char *page;
811 unsigned long src = *ppos; 815 unsigned long src = *ppos;
812 int ret = -ESRCH; 816 int ret = 0;
813 struct mm_struct *mm; 817 struct mm_struct *mm = file->private_data;
814 818
815 if (!task) 819 if (!mm)
816 goto out_no_task; 820 return 0;
817 821
818 ret = -ENOMEM;
819 page = (char *)__get_free_page(GFP_TEMPORARY); 822 page = (char *)__get_free_page(GFP_TEMPORARY);
820 if (!page) 823 if (!page)
821 goto out; 824 return -ENOMEM;
822
823
824 mm = mm_for_maps(task);
825 ret = PTR_ERR(mm);
826 if (!mm || IS_ERR(mm))
827 goto out_free;
828 825
829 ret = 0; 826 ret = 0;
827 if (!atomic_inc_not_zero(&mm->mm_users))
828 goto free;
830 while (count > 0) { 829 while (count > 0) {
831 int this_len, retval, max_len; 830 int this_len, retval, max_len;
832 831
@@ -838,7 +837,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
838 max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count; 837 max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
839 this_len = (this_len > max_len) ? max_len : this_len; 838 this_len = (this_len > max_len) ? max_len : this_len;
840 839
841 retval = access_process_vm(task, (mm->env_start + src), 840 retval = access_remote_vm(mm, (mm->env_start + src),
842 page, this_len, 0); 841 page, this_len, 0);
843 842
844 if (retval <= 0) { 843 if (retval <= 0) {
@@ -857,19 +856,18 @@ static ssize_t environ_read(struct file *file, char __user *buf,
857 count -= retval; 856 count -= retval;
858 } 857 }
859 *ppos = src; 858 *ppos = src;
860
861 mmput(mm); 859 mmput(mm);
862out_free: 860
861free:
863 free_page((unsigned long) page); 862 free_page((unsigned long) page);
864out:
865 put_task_struct(task);
866out_no_task:
867 return ret; 863 return ret;
868} 864}
869 865
870static const struct file_operations proc_environ_operations = { 866static const struct file_operations proc_environ_operations = {
867 .open = environ_open,
871 .read = environ_read, 868 .read = environ_read,
872 .llseek = generic_file_llseek, 869 .llseek = generic_file_llseek,
870 .release = mem_release,
873}; 871};
874 872
875static ssize_t oom_adjust_read(struct file *file, char __user *buf, 873static ssize_t oom_adjust_read(struct file *file, char __user *buf,
@@ -1850,7 +1848,7 @@ static const struct dentry_operations tid_fd_dentry_operations =
1850static struct dentry *proc_fd_instantiate(struct inode *dir, 1848static struct dentry *proc_fd_instantiate(struct inode *dir,
1851 struct dentry *dentry, struct task_struct *task, const void *ptr) 1849 struct dentry *dentry, struct task_struct *task, const void *ptr)
1852{ 1850{
1853 unsigned fd = *(const unsigned *)ptr; 1851 unsigned fd = (unsigned long)ptr;
1854 struct inode *inode; 1852 struct inode *inode;
1855 struct proc_inode *ei; 1853 struct proc_inode *ei;
1856 struct dentry *error = ERR_PTR(-ENOENT); 1854 struct dentry *error = ERR_PTR(-ENOENT);
@@ -1887,7 +1885,7 @@ static struct dentry *proc_lookupfd_common(struct inode *dir,
1887 if (fd == ~0U) 1885 if (fd == ~0U)
1888 goto out; 1886 goto out;
1889 1887
1890 result = instantiate(dir, dentry, task, &fd); 1888 result = instantiate(dir, dentry, task, (void *)(unsigned long)fd);
1891out: 1889out:
1892 put_task_struct(task); 1890 put_task_struct(task);
1893out_no_task: 1891out_no_task:
@@ -1930,21 +1928,22 @@ static int proc_readfd_common(struct file * filp, void * dirent,
1930 fd++, filp->f_pos++) { 1928 fd++, filp->f_pos++) {
1931 char name[PROC_NUMBUF]; 1929 char name[PROC_NUMBUF];
1932 int len; 1930 int len;
1931 int rv;
1933 1932
1934 if (!fcheck_files(files, fd)) 1933 if (!fcheck_files(files, fd))
1935 continue; 1934 continue;
1936 rcu_read_unlock(); 1935 rcu_read_unlock();
1937 1936
1938 len = snprintf(name, sizeof(name), "%d", fd); 1937 len = snprintf(name, sizeof(name), "%d", fd);
1939 if (proc_fill_cache(filp, dirent, filldir, 1938 rv = proc_fill_cache(filp, dirent, filldir,
1940 name, len, instantiate, 1939 name, len, instantiate, p,
1941 p, &fd) < 0) { 1940 (void *)(unsigned long)fd);
1942 rcu_read_lock(); 1941 if (rv < 0)
1943 break; 1942 goto out_fd_loop;
1944 }
1945 rcu_read_lock(); 1943 rcu_read_lock();
1946 } 1944 }
1947 rcu_read_unlock(); 1945 rcu_read_unlock();
1946out_fd_loop:
1948 put_files_struct(files); 1947 put_files_struct(files);
1949 } 1948 }
1950out: 1949out:
@@ -2024,11 +2023,8 @@ static int map_files_d_revalidate(struct dentry *dentry, struct nameidata *nd)
2024 if (!task) 2023 if (!task)
2025 goto out_notask; 2024 goto out_notask;
2026 2025
2027 if (!ptrace_may_access(task, PTRACE_MODE_READ)) 2026 mm = mm_access(task, PTRACE_MODE_READ);
2028 goto out; 2027 if (IS_ERR_OR_NULL(mm))
2029
2030 mm = get_task_mm(task);
2031 if (!mm)
2032 goto out; 2028 goto out;
2033 2029
2034 if (!dname_to_vma_addr(dentry, &vm_start, &vm_end)) { 2030 if (!dname_to_vma_addr(dentry, &vm_start, &vm_end)) {
@@ -2357,7 +2353,7 @@ static const struct inode_operations proc_fd_inode_operations = {
2357static struct dentry *proc_fdinfo_instantiate(struct inode *dir, 2353static struct dentry *proc_fdinfo_instantiate(struct inode *dir,
2358 struct dentry *dentry, struct task_struct *task, const void *ptr) 2354 struct dentry *dentry, struct task_struct *task, const void *ptr)
2359{ 2355{
2360 unsigned fd = *(unsigned *)ptr; 2356 unsigned fd = (unsigned long)ptr;
2361 struct inode *inode; 2357 struct inode *inode;
2362 struct proc_inode *ei; 2358 struct proc_inode *ei;
2363 struct dentry *error = ERR_PTR(-ENOENT); 2359 struct dentry *error = ERR_PTR(-ENOENT);
@@ -3404,6 +3400,9 @@ static const struct pid_entry tid_base_stuff[] = {
3404 ONE("stat", S_IRUGO, proc_tid_stat), 3400 ONE("stat", S_IRUGO, proc_tid_stat),
3405 ONE("statm", S_IRUGO, proc_pid_statm), 3401 ONE("statm", S_IRUGO, proc_pid_statm),
3406 REG("maps", S_IRUGO, proc_tid_maps_operations), 3402 REG("maps", S_IRUGO, proc_tid_maps_operations),
3403#ifdef CONFIG_CHECKPOINT_RESTORE
3404 REG("children", S_IRUGO, proc_tid_children_operations),
3405#endif
3407#ifdef CONFIG_NUMA 3406#ifdef CONFIG_NUMA
3408 REG("numa_maps", S_IRUGO, proc_tid_numa_maps_operations), 3407 REG("numa_maps", S_IRUGO, proc_tid_numa_maps_operations),
3409#endif 3408#endif
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 5f79bb8b4c60..eca4aca5b6e2 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -31,8 +31,6 @@ struct vmalloc_info {
31 unsigned long largest_chunk; 31 unsigned long largest_chunk;
32}; 32};
33 33
34extern struct mm_struct *mm_for_maps(struct task_struct *);
35
36#ifdef CONFIG_MMU 34#ifdef CONFIG_MMU
37#define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START) 35#define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
38extern void get_vmalloc_info(struct vmalloc_info *vmi); 36extern void get_vmalloc_info(struct vmalloc_info *vmi);
@@ -56,6 +54,7 @@ extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
56 struct pid *pid, struct task_struct *task); 54 struct pid *pid, struct task_struct *task);
57extern loff_t mem_lseek(struct file *file, loff_t offset, int orig); 55extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
58 56
57extern const struct file_operations proc_tid_children_operations;
59extern const struct file_operations proc_pid_maps_operations; 58extern const struct file_operations proc_pid_maps_operations;
60extern const struct file_operations proc_tid_maps_operations; 59extern const struct file_operations proc_tid_maps_operations;
61extern const struct file_operations proc_pid_numa_maps_operations; 60extern const struct file_operations proc_pid_numa_maps_operations;
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 7faaf2acc570..4540b8f76f16 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -125,7 +125,7 @@ static void *m_start(struct seq_file *m, loff_t *pos)
125 if (!priv->task) 125 if (!priv->task)
126 return ERR_PTR(-ESRCH); 126 return ERR_PTR(-ESRCH);
127 127
128 mm = mm_for_maps(priv->task); 128 mm = mm_access(priv->task, PTRACE_MODE_READ);
129 if (!mm || IS_ERR(mm)) 129 if (!mm || IS_ERR(mm))
130 return mm; 130 return mm;
131 down_read(&mm->mmap_sem); 131 down_read(&mm->mmap_sem);
@@ -393,6 +393,7 @@ struct mem_size_stats {
393 unsigned long anonymous; 393 unsigned long anonymous;
394 unsigned long anonymous_thp; 394 unsigned long anonymous_thp;
395 unsigned long swap; 395 unsigned long swap;
396 unsigned long nonlinear;
396 u64 pss; 397 u64 pss;
397}; 398};
398 399
@@ -402,24 +403,33 @@ static void smaps_pte_entry(pte_t ptent, unsigned long addr,
402{ 403{
403 struct mem_size_stats *mss = walk->private; 404 struct mem_size_stats *mss = walk->private;
404 struct vm_area_struct *vma = mss->vma; 405 struct vm_area_struct *vma = mss->vma;
405 struct page *page; 406 pgoff_t pgoff = linear_page_index(vma, addr);
407 struct page *page = NULL;
406 int mapcount; 408 int mapcount;
407 409
408 if (is_swap_pte(ptent)) { 410 if (pte_present(ptent)) {
409 mss->swap += ptent_size; 411 page = vm_normal_page(vma, addr, ptent);
410 return; 412 } else if (is_swap_pte(ptent)) {
413 swp_entry_t swpent = pte_to_swp_entry(ptent);
414
415 if (!non_swap_entry(swpent))
416 mss->swap += ptent_size;
417 else if (is_migration_entry(swpent))
418 page = migration_entry_to_page(swpent);
419 } else if (pte_file(ptent)) {
420 if (pte_to_pgoff(ptent) != pgoff)
421 mss->nonlinear += ptent_size;
411 } 422 }
412 423
413 if (!pte_present(ptent))
414 return;
415
416 page = vm_normal_page(vma, addr, ptent);
417 if (!page) 424 if (!page)
418 return; 425 return;
419 426
420 if (PageAnon(page)) 427 if (PageAnon(page))
421 mss->anonymous += ptent_size; 428 mss->anonymous += ptent_size;
422 429
430 if (page->index != pgoff)
431 mss->nonlinear += ptent_size;
432
423 mss->resident += ptent_size; 433 mss->resident += ptent_size;
424 /* Accumulate the size in pages that have been accessed. */ 434 /* Accumulate the size in pages that have been accessed. */
425 if (pte_young(ptent) || PageReferenced(page)) 435 if (pte_young(ptent) || PageReferenced(page))
@@ -521,6 +531,10 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
521 (vma->vm_flags & VM_LOCKED) ? 531 (vma->vm_flags & VM_LOCKED) ?
522 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)) : 0); 532 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)) : 0);
523 533
534 if (vma->vm_flags & VM_NONLINEAR)
535 seq_printf(m, "Nonlinear: %8lu kB\n",
536 mss.nonlinear >> 10);
537
524 if (m->count < m->size) /* vma is copied successfully */ 538 if (m->count < m->size) /* vma is copied successfully */
525 m->version = (vma != get_gate_vma(task->mm)) 539 m->version = (vma != get_gate_vma(task->mm))
526 ? vma->vm_start : 0; 540 ? vma->vm_start : 0;
@@ -700,6 +714,7 @@ struct pagemapread {
700 714
701#define PM_PRESENT PM_STATUS(4LL) 715#define PM_PRESENT PM_STATUS(4LL)
702#define PM_SWAP PM_STATUS(2LL) 716#define PM_SWAP PM_STATUS(2LL)
717#define PM_FILE PM_STATUS(1LL)
703#define PM_NOT_PRESENT PM_PSHIFT(PAGE_SHIFT) 718#define PM_NOT_PRESENT PM_PSHIFT(PAGE_SHIFT)
704#define PM_END_OF_BUFFER 1 719#define PM_END_OF_BUFFER 1
705 720
@@ -733,22 +748,33 @@ static int pagemap_pte_hole(unsigned long start, unsigned long end,
733 return err; 748 return err;
734} 749}
735 750
736static u64 swap_pte_to_pagemap_entry(pte_t pte) 751static void pte_to_pagemap_entry(pagemap_entry_t *pme,
752 struct vm_area_struct *vma, unsigned long addr, pte_t pte)
737{ 753{
738 swp_entry_t e = pte_to_swp_entry(pte); 754 u64 frame, flags;
739 return swp_type(e) | (swp_offset(e) << MAX_SWAPFILES_SHIFT); 755 struct page *page = NULL;
740} 756
741 757 if (pte_present(pte)) {
742static void pte_to_pagemap_entry(pagemap_entry_t *pme, pte_t pte) 758 frame = pte_pfn(pte);
743{ 759 flags = PM_PRESENT;
744 if (is_swap_pte(pte)) 760 page = vm_normal_page(vma, addr, pte);
745 *pme = make_pme(PM_PFRAME(swap_pte_to_pagemap_entry(pte)) 761 } else if (is_swap_pte(pte)) {
746 | PM_PSHIFT(PAGE_SHIFT) | PM_SWAP); 762 swp_entry_t entry = pte_to_swp_entry(pte);
747 else if (pte_present(pte)) 763
748 *pme = make_pme(PM_PFRAME(pte_pfn(pte)) 764 frame = swp_type(entry) |
749 | PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT); 765 (swp_offset(entry) << MAX_SWAPFILES_SHIFT);
750 else 766 flags = PM_SWAP;
767 if (is_migration_entry(entry))
768 page = migration_entry_to_page(entry);
769 } else {
751 *pme = make_pme(PM_NOT_PRESENT); 770 *pme = make_pme(PM_NOT_PRESENT);
771 return;
772 }
773
774 if (page && !PageAnon(page))
775 flags |= PM_FILE;
776
777 *pme = make_pme(PM_PFRAME(frame) | PM_PSHIFT(PAGE_SHIFT) | flags);
752} 778}
753 779
754#ifdef CONFIG_TRANSPARENT_HUGEPAGE 780#ifdef CONFIG_TRANSPARENT_HUGEPAGE
@@ -815,7 +841,7 @@ static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
815 if (vma && (vma->vm_start <= addr) && 841 if (vma && (vma->vm_start <= addr) &&
816 !is_vm_hugetlb_page(vma)) { 842 !is_vm_hugetlb_page(vma)) {
817 pte = pte_offset_map(pmd, addr); 843 pte = pte_offset_map(pmd, addr);
818 pte_to_pagemap_entry(&pme, *pte); 844 pte_to_pagemap_entry(&pme, vma, addr, *pte);
819 /* unmap before userspace copy */ 845 /* unmap before userspace copy */
820 pte_unmap(pte); 846 pte_unmap(pte);
821 } 847 }
@@ -869,11 +895,11 @@ static int pagemap_hugetlb_range(pte_t *pte, unsigned long hmask,
869 * For each page in the address space, this file contains one 64-bit entry 895 * For each page in the address space, this file contains one 64-bit entry
870 * consisting of the following: 896 * consisting of the following:
871 * 897 *
872 * Bits 0-55 page frame number (PFN) if present 898 * Bits 0-54 page frame number (PFN) if present
873 * Bits 0-4 swap type if swapped 899 * Bits 0-4 swap type if swapped
874 * Bits 5-55 swap offset if swapped 900 * Bits 5-54 swap offset if swapped
875 * Bits 55-60 page shift (page size = 1<<page shift) 901 * Bits 55-60 page shift (page size = 1<<page shift)
876 * Bit 61 reserved for future use 902 * Bit 61 page is file-page or shared-anon
877 * Bit 62 page swapped 903 * Bit 62 page swapped
878 * Bit 63 page present 904 * Bit 63 page present
879 * 905 *
@@ -919,7 +945,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
919 if (!pm.buffer) 945 if (!pm.buffer)
920 goto out_task; 946 goto out_task;
921 947
922 mm = mm_for_maps(task); 948 mm = mm_access(task, PTRACE_MODE_READ);
923 ret = PTR_ERR(mm); 949 ret = PTR_ERR(mm);
924 if (!mm || IS_ERR(mm)) 950 if (!mm || IS_ERR(mm))
925 goto out_free; 951 goto out_free;
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
index 74fe164d1b23..1ccfa537f5f5 100644
--- a/fs/proc/task_nommu.c
+++ b/fs/proc/task_nommu.c
@@ -223,7 +223,7 @@ static void *m_start(struct seq_file *m, loff_t *pos)
223 if (!priv->task) 223 if (!priv->task)
224 return ERR_PTR(-ESRCH); 224 return ERR_PTR(-ESRCH);
225 225
226 mm = mm_for_maps(priv->task); 226 mm = mm_access(priv->task, PTRACE_MODE_READ);
227 if (!mm || IS_ERR(mm)) { 227 if (!mm || IS_ERR(mm)) {
228 put_task_struct(priv->task); 228 put_task_struct(priv->task);
229 priv->task = NULL; 229 priv->task = NULL;
diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 12412852d88a..5e289a7cbad1 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -23,12 +23,12 @@ static unsigned mounts_poll(struct file *file, poll_table *wait)
23 23
24 poll_wait(file, &p->ns->poll, wait); 24 poll_wait(file, &p->ns->poll, wait);
25 25
26 br_read_lock(vfsmount_lock); 26 br_read_lock(&vfsmount_lock);
27 if (p->m.poll_event != ns->event) { 27 if (p->m.poll_event != ns->event) {
28 p->m.poll_event = ns->event; 28 p->m.poll_event = ns->event;
29 res |= POLLERR | POLLPRI; 29 res |= POLLERR | POLLPRI;
30 } 30 }
31 br_read_unlock(vfsmount_lock); 31 br_read_unlock(&vfsmount_lock);
32 32
33 return res; 33 return res;
34} 34}
diff --git a/fs/read_write.c b/fs/read_write.c
index ffc99d22e0a3..c20614f86c01 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -633,8 +633,7 @@ ssize_t do_loop_readv_writev(struct file *filp, struct iovec *iov,
633ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, 633ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
634 unsigned long nr_segs, unsigned long fast_segs, 634 unsigned long nr_segs, unsigned long fast_segs,
635 struct iovec *fast_pointer, 635 struct iovec *fast_pointer,
636 struct iovec **ret_pointer, 636 struct iovec **ret_pointer)
637 int check_access)
638{ 637{
639 unsigned long seg; 638 unsigned long seg;
640 ssize_t ret; 639 ssize_t ret;
@@ -690,7 +689,7 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
690 ret = -EINVAL; 689 ret = -EINVAL;
691 goto out; 690 goto out;
692 } 691 }
693 if (check_access 692 if (type >= 0
694 && unlikely(!access_ok(vrfy_dir(type), buf, len))) { 693 && unlikely(!access_ok(vrfy_dir(type), buf, len))) {
695 ret = -EFAULT; 694 ret = -EFAULT;
696 goto out; 695 goto out;
@@ -723,7 +722,7 @@ static ssize_t do_readv_writev(int type, struct file *file,
723 } 722 }
724 723
725 ret = rw_copy_check_uvector(type, uvector, nr_segs, 724 ret = rw_copy_check_uvector(type, uvector, nr_segs,
726 ARRAY_SIZE(iovstack), iovstack, &iov, 1); 725 ARRAY_SIZE(iovstack), iovstack, &iov);
727 if (ret <= 0) 726 if (ret <= 0)
728 goto out; 727 goto out;
729 728
diff --git a/fs/readdir.c b/fs/readdir.c
index cc0a8227cddf..39e3370d79cf 100644
--- a/fs/readdir.c
+++ b/fs/readdir.c
@@ -108,11 +108,11 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
108 int error; 108 int error;
109 struct file * file; 109 struct file * file;
110 struct readdir_callback buf; 110 struct readdir_callback buf;
111 int fput_needed;
111 112
112 error = -EBADF; 113 file = fget_light(fd, &fput_needed);
113 file = fget(fd);
114 if (!file) 114 if (!file)
115 goto out; 115 return -EBADF;
116 116
117 buf.result = 0; 117 buf.result = 0;
118 buf.dirent = dirent; 118 buf.dirent = dirent;
@@ -121,8 +121,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
121 if (buf.result) 121 if (buf.result)
122 error = buf.result; 122 error = buf.result;
123 123
124 fput(file); 124 fput_light(file, fput_needed);
125out:
126 return error; 125 return error;
127} 126}
128 127
@@ -195,16 +194,15 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
195 struct file * file; 194 struct file * file;
196 struct linux_dirent __user * lastdirent; 195 struct linux_dirent __user * lastdirent;
197 struct getdents_callback buf; 196 struct getdents_callback buf;
197 int fput_needed;
198 int error; 198 int error;
199 199
200 error = -EFAULT;
201 if (!access_ok(VERIFY_WRITE, dirent, count)) 200 if (!access_ok(VERIFY_WRITE, dirent, count))
202 goto out; 201 return -EFAULT;
203 202
204 error = -EBADF; 203 file = fget_light(fd, &fput_needed);
205 file = fget(fd);
206 if (!file) 204 if (!file)
207 goto out; 205 return -EBADF;
208 206
209 buf.current_dir = dirent; 207 buf.current_dir = dirent;
210 buf.previous = NULL; 208 buf.previous = NULL;
@@ -221,8 +219,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
221 else 219 else
222 error = count - buf.count; 220 error = count - buf.count;
223 } 221 }
224 fput(file); 222 fput_light(file, fput_needed);
225out:
226 return error; 223 return error;
227} 224}
228 225
@@ -278,16 +275,15 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
278 struct file * file; 275 struct file * file;
279 struct linux_dirent64 __user * lastdirent; 276 struct linux_dirent64 __user * lastdirent;
280 struct getdents_callback64 buf; 277 struct getdents_callback64 buf;
278 int fput_needed;
281 int error; 279 int error;
282 280
283 error = -EFAULT;
284 if (!access_ok(VERIFY_WRITE, dirent, count)) 281 if (!access_ok(VERIFY_WRITE, dirent, count))
285 goto out; 282 return -EFAULT;
286 283
287 error = -EBADF; 284 file = fget_light(fd, &fput_needed);
288 file = fget(fd);
289 if (!file) 285 if (!file)
290 goto out; 286 return -EBADF;
291 287
292 buf.current_dir = dirent; 288 buf.current_dir = dirent;
293 buf.previous = NULL; 289 buf.previous = NULL;
@@ -305,7 +301,6 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
305 else 301 else
306 error = count - buf.count; 302 error = count - buf.count;
307 } 303 }
308 fput(file); 304 fput_light(file, fput_needed);
309out:
310 return error; 305 return error;
311} 306}
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 59d06871a850..a6d4268fb6c1 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -1592,13 +1592,12 @@ struct dentry *reiserfs_fh_to_parent(struct super_block *sb, struct fid *fid,
1592 (fh_type == 6) ? fid->raw[5] : 0); 1592 (fh_type == 6) ? fid->raw[5] : 0);
1593} 1593}
1594 1594
1595int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp, 1595int reiserfs_encode_fh(struct inode *inode, __u32 * data, int *lenp,
1596 int need_parent) 1596 struct inode *parent)
1597{ 1597{
1598 struct inode *inode = dentry->d_inode;
1599 int maxlen = *lenp; 1598 int maxlen = *lenp;
1600 1599
1601 if (need_parent && (maxlen < 5)) { 1600 if (parent && (maxlen < 5)) {
1602 *lenp = 5; 1601 *lenp = 5;
1603 return 255; 1602 return 255;
1604 } else if (maxlen < 3) { 1603 } else if (maxlen < 3) {
@@ -1610,20 +1609,15 @@ int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp,
1610 data[1] = le32_to_cpu(INODE_PKEY(inode)->k_dir_id); 1609 data[1] = le32_to_cpu(INODE_PKEY(inode)->k_dir_id);
1611 data[2] = inode->i_generation; 1610 data[2] = inode->i_generation;
1612 *lenp = 3; 1611 *lenp = 3;
1613 /* no room for directory info? return what we've stored so far */ 1612 if (parent) {
1614 if (maxlen < 5 || !need_parent) 1613 data[3] = parent->i_ino;
1615 return 3; 1614 data[4] = le32_to_cpu(INODE_PKEY(parent)->k_dir_id);
1616 1615 *lenp = 5;
1617 spin_lock(&dentry->d_lock); 1616 if (maxlen >= 6) {
1618 inode = dentry->d_parent->d_inode; 1617 data[5] = parent->i_generation;
1619 data[3] = inode->i_ino; 1618 *lenp = 6;
1620 data[4] = le32_to_cpu(INODE_PKEY(inode)->k_dir_id); 1619 }
1621 *lenp = 5; 1620 }
1622 if (maxlen >= 6) {
1623 data[5] = inode->i_generation;
1624 *lenp = 6;
1625 }
1626 spin_unlock(&dentry->d_lock);
1627 return *lenp; 1621 return *lenp;
1628} 1622}
1629 1623
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index b1a08573fe14..afcadcc03e8a 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -1923,6 +1923,8 @@ static int do_journal_release(struct reiserfs_transaction_handle *th,
1923 * the workqueue job (flush_async_commit) needs this lock 1923 * the workqueue job (flush_async_commit) needs this lock
1924 */ 1924 */
1925 reiserfs_write_unlock(sb); 1925 reiserfs_write_unlock(sb);
1926
1927 cancel_delayed_work_sync(&REISERFS_SB(sb)->old_work);
1926 flush_workqueue(commit_wq); 1928 flush_workqueue(commit_wq);
1927 1929
1928 if (!reiserfs_mounted_fs_count) { 1930 if (!reiserfs_mounted_fs_count) {
@@ -3231,8 +3233,6 @@ int journal_mark_dirty(struct reiserfs_transaction_handle *th,
3231 th->t_trans_id, journal->j_trans_id); 3233 th->t_trans_id, journal->j_trans_id);
3232 } 3234 }
3233 3235
3234 sb->s_dirt = 1;
3235
3236 prepared = test_clear_buffer_journal_prepared(bh); 3236 prepared = test_clear_buffer_journal_prepared(bh);
3237 clear_buffer_journal_restore_dirty(bh); 3237 clear_buffer_journal_restore_dirty(bh);
3238 /* already in this transaction, we are done */ 3238 /* already in this transaction, we are done */
@@ -3316,6 +3316,7 @@ int journal_mark_dirty(struct reiserfs_transaction_handle *th,
3316 journal->j_first = cn; 3316 journal->j_first = cn;
3317 journal->j_last = cn; 3317 journal->j_last = cn;
3318 } 3318 }
3319 reiserfs_schedule_old_flush(sb);
3319 return 0; 3320 return 0;
3320} 3321}
3321 3322
@@ -3492,7 +3493,7 @@ static void flush_async_commits(struct work_struct *work)
3492** flushes any old transactions to disk 3493** flushes any old transactions to disk
3493** ends the current transaction if it is too old 3494** ends the current transaction if it is too old
3494*/ 3495*/
3495int reiserfs_flush_old_commits(struct super_block *sb) 3496void reiserfs_flush_old_commits(struct super_block *sb)
3496{ 3497{
3497 time_t now; 3498 time_t now;
3498 struct reiserfs_transaction_handle th; 3499 struct reiserfs_transaction_handle th;
@@ -3502,9 +3503,8 @@ int reiserfs_flush_old_commits(struct super_block *sb)
3502 /* safety check so we don't flush while we are replaying the log during 3503 /* safety check so we don't flush while we are replaying the log during
3503 * mount 3504 * mount
3504 */ 3505 */
3505 if (list_empty(&journal->j_journal_list)) { 3506 if (list_empty(&journal->j_journal_list))
3506 return 0; 3507 return;
3507 }
3508 3508
3509 /* check the current transaction. If there are no writers, and it is 3509 /* check the current transaction. If there are no writers, and it is
3510 * too old, finish it, and force the commit blocks to disk 3510 * too old, finish it, and force the commit blocks to disk
@@ -3526,7 +3526,6 @@ int reiserfs_flush_old_commits(struct super_block *sb)
3526 do_journal_end(&th, sb, 1, COMMIT_NOW | WAIT); 3526 do_journal_end(&th, sb, 1, COMMIT_NOW | WAIT);
3527 } 3527 }
3528 } 3528 }
3529 return sb->s_dirt;
3530} 3529}
3531 3530
3532/* 3531/*
@@ -3955,7 +3954,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
3955 ** it tells us if we should continue with the journal_end, or just return 3954 ** it tells us if we should continue with the journal_end, or just return
3956 */ 3955 */
3957 if (!check_journal_end(th, sb, nblocks, flags)) { 3956 if (!check_journal_end(th, sb, nblocks, flags)) {
3958 sb->s_dirt = 1; 3957 reiserfs_schedule_old_flush(sb);
3959 wake_queued_writers(sb); 3958 wake_queued_writers(sb);
3960 reiserfs_async_progress_wait(sb); 3959 reiserfs_async_progress_wait(sb);
3961 goto out; 3960 goto out;
diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
index a59d27126338..33215f57ea06 100644
--- a/fs/reiserfs/reiserfs.h
+++ b/fs/reiserfs/reiserfs.h
@@ -480,6 +480,11 @@ struct reiserfs_sb_info {
480 struct dentry *priv_root; /* root of /.reiserfs_priv */ 480 struct dentry *priv_root; /* root of /.reiserfs_priv */
481 struct dentry *xattr_root; /* root of /.reiserfs_priv/xattrs */ 481 struct dentry *xattr_root; /* root of /.reiserfs_priv/xattrs */
482 int j_errno; 482 int j_errno;
483
484 int work_queued; /* non-zero delayed work is queued */
485 struct delayed_work old_work; /* old transactions flush delayed work */
486 spinlock_t old_work_lock; /* protects old_work and work_queued */
487
483#ifdef CONFIG_QUOTA 488#ifdef CONFIG_QUOTA
484 char *s_qf_names[MAXQUOTAS]; 489 char *s_qf_names[MAXQUOTAS];
485 int s_jquota_fmt; 490 int s_jquota_fmt;
@@ -2452,7 +2457,7 @@ struct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct
2452int reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *); 2457int reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *);
2453int reiserfs_commit_page(struct inode *inode, struct page *page, 2458int reiserfs_commit_page(struct inode *inode, struct page *page,
2454 unsigned from, unsigned to); 2459 unsigned from, unsigned to);
2455int reiserfs_flush_old_commits(struct super_block *); 2460void reiserfs_flush_old_commits(struct super_block *);
2456int reiserfs_commit_for_inode(struct inode *); 2461int reiserfs_commit_for_inode(struct inode *);
2457int reiserfs_inode_needs_commit(struct inode *); 2462int reiserfs_inode_needs_commit(struct inode *);
2458void reiserfs_update_inode_transaction(struct inode *); 2463void reiserfs_update_inode_transaction(struct inode *);
@@ -2487,6 +2492,7 @@ void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...);
2487int reiserfs_allocate_list_bitmaps(struct super_block *s, 2492int reiserfs_allocate_list_bitmaps(struct super_block *s,
2488 struct reiserfs_list_bitmap *, unsigned int); 2493 struct reiserfs_list_bitmap *, unsigned int);
2489 2494
2495void reiserfs_schedule_old_flush(struct super_block *s);
2490void add_save_link(struct reiserfs_transaction_handle *th, 2496void add_save_link(struct reiserfs_transaction_handle *th,
2491 struct inode *inode, int truncate); 2497 struct inode *inode, int truncate);
2492int remove_save_link(struct inode *inode, int truncate); 2498int remove_save_link(struct inode *inode, int truncate);
@@ -2611,8 +2617,8 @@ struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
2611 int fh_len, int fh_type); 2617 int fh_len, int fh_type);
2612struct dentry *reiserfs_fh_to_parent(struct super_block *sb, struct fid *fid, 2618struct dentry *reiserfs_fh_to_parent(struct super_block *sb, struct fid *fid,
2613 int fh_len, int fh_type); 2619 int fh_len, int fh_type);
2614int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp, 2620int reiserfs_encode_fh(struct inode *inode, __u32 * data, int *lenp,
2615 int connectable); 2621 struct inode *parent);
2616 2622
2617int reiserfs_truncate_file(struct inode *, int update_timestamps); 2623int reiserfs_truncate_file(struct inode *, int update_timestamps);
2618void make_cpu_key(struct cpu_key *cpu_key, struct inode *inode, loff_t offset, 2624void make_cpu_key(struct cpu_key *cpu_key, struct inode *inode, loff_t offset,
diff --git a/fs/reiserfs/resize.c b/fs/reiserfs/resize.c
index 9a17f63c3fd7..3ce02cff5e90 100644
--- a/fs/reiserfs/resize.c
+++ b/fs/reiserfs/resize.c
@@ -200,7 +200,6 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
200 (bmap_nr_new - bmap_nr))); 200 (bmap_nr_new - bmap_nr)));
201 PUT_SB_BLOCK_COUNT(s, block_count_new); 201 PUT_SB_BLOCK_COUNT(s, block_count_new);
202 PUT_SB_BMAP_NR(s, bmap_would_wrap(bmap_nr_new) ? : bmap_nr_new); 202 PUT_SB_BMAP_NR(s, bmap_would_wrap(bmap_nr_new) ? : bmap_nr_new);
203 s->s_dirt = 1;
204 203
205 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s)); 204 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
206 205
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index c07b7d709447..651ce767b55d 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -72,20 +72,58 @@ static int reiserfs_sync_fs(struct super_block *s, int wait)
72 if (!journal_begin(&th, s, 1)) 72 if (!journal_begin(&th, s, 1))
73 if (!journal_end_sync(&th, s, 1)) 73 if (!journal_end_sync(&th, s, 1))
74 reiserfs_flush_old_commits(s); 74 reiserfs_flush_old_commits(s);
75 s->s_dirt = 0; /* Even if it's not true.
76 * We'll loop forever in sync_supers otherwise */
77 reiserfs_write_unlock(s); 75 reiserfs_write_unlock(s);
78 return 0; 76 return 0;
79} 77}
80 78
81static void reiserfs_write_super(struct super_block *s) 79static void flush_old_commits(struct work_struct *work)
82{ 80{
81 struct reiserfs_sb_info *sbi;
82 struct super_block *s;
83
84 sbi = container_of(work, struct reiserfs_sb_info, old_work.work);
85 s = sbi->s_journal->j_work_sb;
86
87 spin_lock(&sbi->old_work_lock);
88 sbi->work_queued = 0;
89 spin_unlock(&sbi->old_work_lock);
90
83 reiserfs_sync_fs(s, 1); 91 reiserfs_sync_fs(s, 1);
84} 92}
85 93
94void reiserfs_schedule_old_flush(struct super_block *s)
95{
96 struct reiserfs_sb_info *sbi = REISERFS_SB(s);
97 unsigned long delay;
98
99 if (s->s_flags & MS_RDONLY)
100 return;
101
102 spin_lock(&sbi->old_work_lock);
103 if (!sbi->work_queued) {
104 delay = msecs_to_jiffies(dirty_writeback_interval * 10);
105 queue_delayed_work(system_long_wq, &sbi->old_work, delay);
106 sbi->work_queued = 1;
107 }
108 spin_unlock(&sbi->old_work_lock);
109}
110
111static void cancel_old_flush(struct super_block *s)
112{
113 struct reiserfs_sb_info *sbi = REISERFS_SB(s);
114
115 cancel_delayed_work_sync(&REISERFS_SB(s)->old_work);
116 spin_lock(&sbi->old_work_lock);
117 sbi->work_queued = 0;
118 spin_unlock(&sbi->old_work_lock);
119}
120
86static int reiserfs_freeze(struct super_block *s) 121static int reiserfs_freeze(struct super_block *s)
87{ 122{
88 struct reiserfs_transaction_handle th; 123 struct reiserfs_transaction_handle th;
124
125 cancel_old_flush(s);
126
89 reiserfs_write_lock(s); 127 reiserfs_write_lock(s);
90 if (!(s->s_flags & MS_RDONLY)) { 128 if (!(s->s_flags & MS_RDONLY)) {
91 int err = journal_begin(&th, s, 1); 129 int err = journal_begin(&th, s, 1);
@@ -99,7 +137,6 @@ static int reiserfs_freeze(struct super_block *s)
99 journal_end_sync(&th, s, 1); 137 journal_end_sync(&th, s, 1);
100 } 138 }
101 } 139 }
102 s->s_dirt = 0;
103 reiserfs_write_unlock(s); 140 reiserfs_write_unlock(s);
104 return 0; 141 return 0;
105} 142}
@@ -483,9 +520,6 @@ static void reiserfs_put_super(struct super_block *s)
483 520
484 reiserfs_write_lock(s); 521 reiserfs_write_lock(s);
485 522
486 if (s->s_dirt)
487 reiserfs_write_super(s);
488
489 /* change file system state to current state if it was mounted with read-write permissions */ 523 /* change file system state to current state if it was mounted with read-write permissions */
490 if (!(s->s_flags & MS_RDONLY)) { 524 if (!(s->s_flags & MS_RDONLY)) {
491 if (!journal_begin(&th, s, 10)) { 525 if (!journal_begin(&th, s, 10)) {
@@ -692,7 +726,6 @@ static const struct super_operations reiserfs_sops = {
692 .dirty_inode = reiserfs_dirty_inode, 726 .dirty_inode = reiserfs_dirty_inode,
693 .evict_inode = reiserfs_evict_inode, 727 .evict_inode = reiserfs_evict_inode,
694 .put_super = reiserfs_put_super, 728 .put_super = reiserfs_put_super,
695 .write_super = reiserfs_write_super,
696 .sync_fs = reiserfs_sync_fs, 729 .sync_fs = reiserfs_sync_fs,
697 .freeze_fs = reiserfs_freeze, 730 .freeze_fs = reiserfs_freeze,
698 .unfreeze_fs = reiserfs_unfreeze, 731 .unfreeze_fs = reiserfs_unfreeze,
@@ -1400,7 +1433,6 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
1400 err = journal_end(&th, s, 10); 1433 err = journal_end(&th, s, 10);
1401 if (err) 1434 if (err)
1402 goto out_err; 1435 goto out_err;
1403 s->s_dirt = 0;
1404 1436
1405 if (!(*mount_flags & MS_RDONLY)) { 1437 if (!(*mount_flags & MS_RDONLY)) {
1406 dquot_resume(s, -1); 1438 dquot_resume(s, -1);
@@ -1730,19 +1762,21 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1730 return -ENOMEM; 1762 return -ENOMEM;
1731 s->s_fs_info = sbi; 1763 s->s_fs_info = sbi;
1732 /* Set default values for options: non-aggressive tails, RO on errors */ 1764 /* Set default values for options: non-aggressive tails, RO on errors */
1733 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_SMALLTAIL); 1765 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
1734 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_ERROR_RO); 1766 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
1735 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH); 1767 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
1736 /* no preallocation minimum, be smart in 1768 /* no preallocation minimum, be smart in
1737 reiserfs_file_write instead */ 1769 reiserfs_file_write instead */
1738 REISERFS_SB(s)->s_alloc_options.preallocmin = 0; 1770 sbi->s_alloc_options.preallocmin = 0;
1739 /* Preallocate by 16 blocks (17-1) at once */ 1771 /* Preallocate by 16 blocks (17-1) at once */
1740 REISERFS_SB(s)->s_alloc_options.preallocsize = 17; 1772 sbi->s_alloc_options.preallocsize = 17;
1741 /* setup default block allocator options */ 1773 /* setup default block allocator options */
1742 reiserfs_init_alloc_options(s); 1774 reiserfs_init_alloc_options(s);
1743 1775
1744 mutex_init(&REISERFS_SB(s)->lock); 1776 spin_lock_init(&sbi->old_work_lock);
1745 REISERFS_SB(s)->lock_depth = -1; 1777 INIT_DELAYED_WORK(&sbi->old_work, flush_old_commits);
1778 mutex_init(&sbi->lock);
1779 sbi->lock_depth = -1;
1746 1780
1747 jdev_name = NULL; 1781 jdev_name = NULL;
1748 if (reiserfs_parse_options 1782 if (reiserfs_parse_options
@@ -1751,8 +1785,8 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1751 goto error_unlocked; 1785 goto error_unlocked;
1752 } 1786 }
1753 if (jdev_name && jdev_name[0]) { 1787 if (jdev_name && jdev_name[0]) {
1754 REISERFS_SB(s)->s_jdev = kstrdup(jdev_name, GFP_KERNEL); 1788 sbi->s_jdev = kstrdup(jdev_name, GFP_KERNEL);
1755 if (!REISERFS_SB(s)->s_jdev) { 1789 if (!sbi->s_jdev) {
1756 SWARN(silent, s, "", "Cannot allocate memory for " 1790 SWARN(silent, s, "", "Cannot allocate memory for "
1757 "journal device name"); 1791 "journal device name");
1758 goto error; 1792 goto error;
@@ -1810,7 +1844,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1810 /* make data=ordered the default */ 1844 /* make data=ordered the default */
1811 if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) && 1845 if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
1812 !reiserfs_data_writeback(s)) { 1846 !reiserfs_data_writeback(s)) {
1813 REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED); 1847 sbi->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
1814 } 1848 }
1815 1849
1816 if (reiserfs_data_log(s)) { 1850 if (reiserfs_data_log(s)) {
@@ -2003,6 +2037,8 @@ error_unlocked:
2003 reiserfs_write_unlock(s); 2037 reiserfs_write_unlock(s);
2004 } 2038 }
2005 2039
2040 cancel_delayed_work_sync(&REISERFS_SB(s)->old_work);
2041
2006 reiserfs_free_bitmap_cache(s); 2042 reiserfs_free_bitmap_cache(s);
2007 if (SB_BUFFER_WITH_SB(s)) 2043 if (SB_BUFFER_WITH_SB(s))
2008 brelse(SB_BUFFER_WITH_SB(s)); 2044 brelse(SB_BUFFER_WITH_SB(s));
diff --git a/fs/select.c b/fs/select.c
index 17d33d09fc16..bae321569dfa 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -614,7 +614,6 @@ SYSCALL_DEFINE5(select, int, n, fd_set __user *, inp, fd_set __user *, outp,
614 return ret; 614 return ret;
615} 615}
616 616
617#ifdef HAVE_SET_RESTORE_SIGMASK
618static long do_pselect(int n, fd_set __user *inp, fd_set __user *outp, 617static long do_pselect(int n, fd_set __user *inp, fd_set __user *outp,
619 fd_set __user *exp, struct timespec __user *tsp, 618 fd_set __user *exp, struct timespec __user *tsp,
620 const sigset_t __user *sigmask, size_t sigsetsize) 619 const sigset_t __user *sigmask, size_t sigsetsize)
@@ -686,7 +685,6 @@ SYSCALL_DEFINE6(pselect6, int, n, fd_set __user *, inp, fd_set __user *, outp,
686 685
687 return do_pselect(n, inp, outp, exp, tsp, up, sigsetsize); 686 return do_pselect(n, inp, outp, exp, tsp, up, sigsetsize);
688} 687}
689#endif /* HAVE_SET_RESTORE_SIGMASK */
690 688
691#ifdef __ARCH_WANT_SYS_OLD_SELECT 689#ifdef __ARCH_WANT_SYS_OLD_SELECT
692struct sel_arg_struct { 690struct sel_arg_struct {
@@ -941,7 +939,6 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds,
941 return ret; 939 return ret;
942} 940}
943 941
944#ifdef HAVE_SET_RESTORE_SIGMASK
945SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, unsigned int, nfds, 942SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, unsigned int, nfds,
946 struct timespec __user *, tsp, const sigset_t __user *, sigmask, 943 struct timespec __user *, tsp, const sigset_t __user *, sigmask,
947 size_t, sigsetsize) 944 size_t, sigsetsize)
@@ -992,4 +989,3 @@ SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, unsigned int, nfds,
992 989
993 return ret; 990 return ret;
994} 991}
995#endif /* HAVE_SET_RESTORE_SIGMASK */
diff --git a/fs/signalfd.c b/fs/signalfd.c
index 7ae2a574cb25..9f35a37173de 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -269,12 +269,13 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
269 if (ufd < 0) 269 if (ufd < 0)
270 kfree(ctx); 270 kfree(ctx);
271 } else { 271 } else {
272 struct file *file = fget(ufd); 272 int fput_needed;
273 struct file *file = fget_light(ufd, &fput_needed);
273 if (!file) 274 if (!file)
274 return -EBADF; 275 return -EBADF;
275 ctx = file->private_data; 276 ctx = file->private_data;
276 if (file->f_op != &signalfd_fops) { 277 if (file->f_op != &signalfd_fops) {
277 fput(file); 278 fput_light(file, fput_needed);
278 return -EINVAL; 279 return -EINVAL;
279 } 280 }
280 spin_lock_irq(&current->sighand->siglock); 281 spin_lock_irq(&current->sighand->siglock);
@@ -282,7 +283,7 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
282 spin_unlock_irq(&current->sighand->siglock); 283 spin_unlock_irq(&current->sighand->siglock);
283 284
284 wake_up(&current->sighand->signalfd_wqh); 285 wake_up(&current->sighand->signalfd_wqh);
285 fput(file); 286 fput_light(file, fput_needed);
286 } 287 }
287 288
288 return ufd; 289 return ufd;
diff --git a/fs/splice.c b/fs/splice.c
index 406ef2b792c2..c9f1318a3b82 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1003,8 +1003,10 @@ generic_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
1003 mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD); 1003 mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD);
1004 ret = file_remove_suid(out); 1004 ret = file_remove_suid(out);
1005 if (!ret) { 1005 if (!ret) {
1006 file_update_time(out); 1006 ret = file_update_time(out);
1007 ret = splice_from_pipe_feed(pipe, &sd, pipe_to_file); 1007 if (!ret)
1008 ret = splice_from_pipe_feed(pipe, &sd,
1009 pipe_to_file);
1008 } 1010 }
1009 mutex_unlock(&inode->i_mutex); 1011 mutex_unlock(&inode->i_mutex);
1010 } while (ret > 0); 1012 } while (ret > 0);
diff --git a/fs/statfs.c b/fs/statfs.c
index 43e6b6fe4e85..95ad5c0e586c 100644
--- a/fs/statfs.c
+++ b/fs/statfs.c
@@ -87,11 +87,12 @@ int user_statfs(const char __user *pathname, struct kstatfs *st)
87 87
88int fd_statfs(int fd, struct kstatfs *st) 88int fd_statfs(int fd, struct kstatfs *st)
89{ 89{
90 struct file *file = fget(fd); 90 int fput_needed;
91 struct file *file = fget_light(fd, &fput_needed);
91 int error = -EBADF; 92 int error = -EBADF;
92 if (file) { 93 if (file) {
93 error = vfs_statfs(&file->f_path, st); 94 error = vfs_statfs(&file->f_path, st);
94 fput(file); 95 fput_light(file, fput_needed);
95 } 96 }
96 return error; 97 return error;
97} 98}
diff --git a/fs/sync.c b/fs/sync.c
index 0e8db939d96f..11e3d1c44901 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -188,11 +188,12 @@ static int do_fsync(unsigned int fd, int datasync)
188{ 188{
189 struct file *file; 189 struct file *file;
190 int ret = -EBADF; 190 int ret = -EBADF;
191 int fput_needed;
191 192
192 file = fget(fd); 193 file = fget_light(fd, &fput_needed);
193 if (file) { 194 if (file) {
194 ret = vfs_fsync(file, datasync); 195 ret = vfs_fsync(file, datasync);
195 fput(file); 196 fput_light(file, fput_needed);
196 } 197 }
197 return ret; 198 return ret;
198} 199}
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 62a2727f4ecf..a6d42efc76d2 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -1127,16 +1127,7 @@ int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
1127 struct ubifs_inode *ui = ubifs_inode(inode); 1127 struct ubifs_inode *ui = ubifs_inode(inode);
1128 1128
1129 mutex_lock(&ui->ui_mutex); 1129 mutex_lock(&ui->ui_mutex);
1130 stat->dev = inode->i_sb->s_dev; 1130 generic_fillattr(inode, stat);
1131 stat->ino = inode->i_ino;
1132 stat->mode = inode->i_mode;
1133 stat->nlink = inode->i_nlink;
1134 stat->uid = inode->i_uid;
1135 stat->gid = inode->i_gid;
1136 stat->rdev = inode->i_rdev;
1137 stat->atime = inode->i_atime;
1138 stat->mtime = inode->i_mtime;
1139 stat->ctime = inode->i_ctime;
1140 stat->blksize = UBIFS_BLOCK_SIZE; 1131 stat->blksize = UBIFS_BLOCK_SIZE;
1141 stat->size = ui->ui_size; 1132 stat->size = ui->ui_size;
1142 1133
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index a165c66e3eef..18024178ac4c 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -1260,16 +1260,15 @@ static struct dentry *udf_fh_to_parent(struct super_block *sb,
1260 fid->udf.parent_partref, 1260 fid->udf.parent_partref,
1261 fid->udf.parent_generation); 1261 fid->udf.parent_generation);
1262} 1262}
1263static int udf_encode_fh(struct dentry *de, __u32 *fh, int *lenp, 1263static int udf_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
1264 int connectable) 1264 struct inode *parent)
1265{ 1265{
1266 int len = *lenp; 1266 int len = *lenp;
1267 struct inode *inode = de->d_inode;
1268 struct kernel_lb_addr location = UDF_I(inode)->i_location; 1267 struct kernel_lb_addr location = UDF_I(inode)->i_location;
1269 struct fid *fid = (struct fid *)fh; 1268 struct fid *fid = (struct fid *)fh;
1270 int type = FILEID_UDF_WITHOUT_PARENT; 1269 int type = FILEID_UDF_WITHOUT_PARENT;
1271 1270
1272 if (connectable && (len < 5)) { 1271 if (parent && (len < 5)) {
1273 *lenp = 5; 1272 *lenp = 5;
1274 return 255; 1273 return 255;
1275 } else if (len < 3) { 1274 } else if (len < 3) {
@@ -1282,14 +1281,11 @@ static int udf_encode_fh(struct dentry *de, __u32 *fh, int *lenp,
1282 fid->udf.partref = location.partitionReferenceNum; 1281 fid->udf.partref = location.partitionReferenceNum;
1283 fid->udf.generation = inode->i_generation; 1282 fid->udf.generation = inode->i_generation;
1284 1283
1285 if (connectable && !S_ISDIR(inode->i_mode)) { 1284 if (parent) {
1286 spin_lock(&de->d_lock); 1285 location = UDF_I(parent)->i_location;
1287 inode = de->d_parent->d_inode;
1288 location = UDF_I(inode)->i_location;
1289 fid->udf.parent_block = location.logicalBlockNum; 1286 fid->udf.parent_block = location.logicalBlockNum;
1290 fid->udf.parent_partref = location.partitionReferenceNum; 1287 fid->udf.parent_partref = location.partitionReferenceNum;
1291 fid->udf.parent_generation = inode->i_generation; 1288 fid->udf.parent_generation = inode->i_generation;
1292 spin_unlock(&de->d_lock);
1293 *lenp = 5; 1289 *lenp = 5;
1294 type = FILEID_UDF_WITH_PARENT; 1290 type = FILEID_UDF_WITH_PARENT;
1295 } 1291 }
diff --git a/fs/utimes.c b/fs/utimes.c
index ba653f3dc1bc..fa4dbe451e27 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -140,18 +140,19 @@ long do_utimes(int dfd, const char __user *filename, struct timespec *times,
140 goto out; 140 goto out;
141 141
142 if (filename == NULL && dfd != AT_FDCWD) { 142 if (filename == NULL && dfd != AT_FDCWD) {
143 int fput_needed;
143 struct file *file; 144 struct file *file;
144 145
145 if (flags & AT_SYMLINK_NOFOLLOW) 146 if (flags & AT_SYMLINK_NOFOLLOW)
146 goto out; 147 goto out;
147 148
148 file = fget(dfd); 149 file = fget_light(dfd, &fput_needed);
149 error = -EBADF; 150 error = -EBADF;
150 if (!file) 151 if (!file)
151 goto out; 152 goto out;
152 153
153 error = utimes_common(&file->f_path, times); 154 error = utimes_common(&file->f_path, times);
154 fput(file); 155 fput_light(file, fput_needed);
155 } else { 156 } else {
156 struct path path; 157 struct path path;
157 int lookup_flags = 0; 158 int lookup_flags = 0;
diff --git a/fs/xattr.c b/fs/xattr.c
index 3c8c1cc333c7..1d7ac3790458 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -399,11 +399,12 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
399SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name, 399SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
400 const void __user *,value, size_t, size, int, flags) 400 const void __user *,value, size_t, size, int, flags)
401{ 401{
402 int fput_needed;
402 struct file *f; 403 struct file *f;
403 struct dentry *dentry; 404 struct dentry *dentry;
404 int error = -EBADF; 405 int error = -EBADF;
405 406
406 f = fget(fd); 407 f = fget_light(fd, &fput_needed);
407 if (!f) 408 if (!f)
408 return error; 409 return error;
409 dentry = f->f_path.dentry; 410 dentry = f->f_path.dentry;
@@ -413,7 +414,7 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
413 error = setxattr(dentry, name, value, size, flags); 414 error = setxattr(dentry, name, value, size, flags);
414 mnt_drop_write_file(f); 415 mnt_drop_write_file(f);
415 } 416 }
416 fput(f); 417 fput_light(f, fput_needed);
417 return error; 418 return error;
418} 419}
419 420
@@ -486,15 +487,16 @@ SYSCALL_DEFINE4(lgetxattr, const char __user *, pathname,
486SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name, 487SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
487 void __user *, value, size_t, size) 488 void __user *, value, size_t, size)
488{ 489{
490 int fput_needed;
489 struct file *f; 491 struct file *f;
490 ssize_t error = -EBADF; 492 ssize_t error = -EBADF;
491 493
492 f = fget(fd); 494 f = fget_light(fd, &fput_needed);
493 if (!f) 495 if (!f)
494 return error; 496 return error;
495 audit_inode(NULL, f->f_path.dentry); 497 audit_inode(NULL, f->f_path.dentry);
496 error = getxattr(f->f_path.dentry, name, value, size); 498 error = getxattr(f->f_path.dentry, name, value, size);
497 fput(f); 499 fput_light(f, fput_needed);
498 return error; 500 return error;
499} 501}
500 502
@@ -566,15 +568,16 @@ SYSCALL_DEFINE3(llistxattr, const char __user *, pathname, char __user *, list,
566 568
567SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size) 569SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
568{ 570{
571 int fput_needed;
569 struct file *f; 572 struct file *f;
570 ssize_t error = -EBADF; 573 ssize_t error = -EBADF;
571 574
572 f = fget(fd); 575 f = fget_light(fd, &fput_needed);
573 if (!f) 576 if (!f)
574 return error; 577 return error;
575 audit_inode(NULL, f->f_path.dentry); 578 audit_inode(NULL, f->f_path.dentry);
576 error = listxattr(f->f_path.dentry, list, size); 579 error = listxattr(f->f_path.dentry, list, size);
577 fput(f); 580 fput_light(f, fput_needed);
578 return error; 581 return error;
579} 582}
580 583
@@ -634,11 +637,12 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
634 637
635SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name) 638SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
636{ 639{
640 int fput_needed;
637 struct file *f; 641 struct file *f;
638 struct dentry *dentry; 642 struct dentry *dentry;
639 int error = -EBADF; 643 int error = -EBADF;
640 644
641 f = fget(fd); 645 f = fget_light(fd, &fput_needed);
642 if (!f) 646 if (!f)
643 return error; 647 return error;
644 dentry = f->f_path.dentry; 648 dentry = f->f_path.dentry;
@@ -648,7 +652,7 @@ SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
648 error = removexattr(dentry, name); 652 error = removexattr(dentry, name);
649 mnt_drop_write_file(f); 653 mnt_drop_write_file(f);
650 } 654 }
651 fput(f); 655 fput_light(f, fput_needed);
652 return error; 656 return error;
653} 657}
654 658
diff --git a/fs/xfs/kmem.c b/fs/xfs/kmem.c
index a907de565db3..4a7286c1dc80 100644
--- a/fs/xfs/kmem.c
+++ b/fs/xfs/kmem.c
@@ -46,7 +46,7 @@ kmem_zalloc_greedy(size_t *size, size_t minsize, size_t maxsize)
46} 46}
47 47
48void * 48void *
49kmem_alloc(size_t size, unsigned int __nocast flags) 49kmem_alloc(size_t size, xfs_km_flags_t flags)
50{ 50{
51 int retries = 0; 51 int retries = 0;
52 gfp_t lflags = kmem_flags_convert(flags); 52 gfp_t lflags = kmem_flags_convert(flags);
@@ -65,7 +65,7 @@ kmem_alloc(size_t size, unsigned int __nocast flags)
65} 65}
66 66
67void * 67void *
68kmem_zalloc(size_t size, unsigned int __nocast flags) 68kmem_zalloc(size_t size, xfs_km_flags_t flags)
69{ 69{
70 void *ptr; 70 void *ptr;
71 71
@@ -87,7 +87,7 @@ kmem_free(const void *ptr)
87 87
88void * 88void *
89kmem_realloc(const void *ptr, size_t newsize, size_t oldsize, 89kmem_realloc(const void *ptr, size_t newsize, size_t oldsize,
90 unsigned int __nocast flags) 90 xfs_km_flags_t flags)
91{ 91{
92 void *new; 92 void *new;
93 93
@@ -102,7 +102,7 @@ kmem_realloc(const void *ptr, size_t newsize, size_t oldsize,
102} 102}
103 103
104void * 104void *
105kmem_zone_alloc(kmem_zone_t *zone, unsigned int __nocast flags) 105kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags)
106{ 106{
107 int retries = 0; 107 int retries = 0;
108 gfp_t lflags = kmem_flags_convert(flags); 108 gfp_t lflags = kmem_flags_convert(flags);
@@ -121,7 +121,7 @@ kmem_zone_alloc(kmem_zone_t *zone, unsigned int __nocast flags)
121} 121}
122 122
123void * 123void *
124kmem_zone_zalloc(kmem_zone_t *zone, unsigned int __nocast flags) 124kmem_zone_zalloc(kmem_zone_t *zone, xfs_km_flags_t flags)
125{ 125{
126 void *ptr; 126 void *ptr;
127 127
diff --git a/fs/xfs/kmem.h b/fs/xfs/kmem.h
index ab7c53fe346e..b2f2620f9a87 100644
--- a/fs/xfs/kmem.h
+++ b/fs/xfs/kmem.h
@@ -27,10 +27,11 @@
27 * General memory allocation interfaces 27 * General memory allocation interfaces
28 */ 28 */
29 29
30#define KM_SLEEP 0x0001u 30typedef unsigned __bitwise xfs_km_flags_t;
31#define KM_NOSLEEP 0x0002u 31#define KM_SLEEP ((__force xfs_km_flags_t)0x0001u)
32#define KM_NOFS 0x0004u 32#define KM_NOSLEEP ((__force xfs_km_flags_t)0x0002u)
33#define KM_MAYFAIL 0x0008u 33#define KM_NOFS ((__force xfs_km_flags_t)0x0004u)
34#define KM_MAYFAIL ((__force xfs_km_flags_t)0x0008u)
34 35
35/* 36/*
36 * We use a special process flag to avoid recursive callbacks into 37 * We use a special process flag to avoid recursive callbacks into
@@ -38,7 +39,7 @@
38 * warnings, so we explicitly skip any generic ones (silly of us). 39 * warnings, so we explicitly skip any generic ones (silly of us).
39 */ 40 */
40static inline gfp_t 41static inline gfp_t
41kmem_flags_convert(unsigned int __nocast flags) 42kmem_flags_convert(xfs_km_flags_t flags)
42{ 43{
43 gfp_t lflags; 44 gfp_t lflags;
44 45
@@ -54,9 +55,9 @@ kmem_flags_convert(unsigned int __nocast flags)
54 return lflags; 55 return lflags;
55} 56}
56 57
57extern void *kmem_alloc(size_t, unsigned int __nocast); 58extern void *kmem_alloc(size_t, xfs_km_flags_t);
58extern void *kmem_zalloc(size_t, unsigned int __nocast); 59extern void *kmem_zalloc(size_t, xfs_km_flags_t);
59extern void *kmem_realloc(const void *, size_t, size_t, unsigned int __nocast); 60extern void *kmem_realloc(const void *, size_t, size_t, xfs_km_flags_t);
60extern void kmem_free(const void *); 61extern void kmem_free(const void *);
61 62
62static inline void *kmem_zalloc_large(size_t size) 63static inline void *kmem_zalloc_large(size_t size)
@@ -107,7 +108,7 @@ kmem_zone_destroy(kmem_zone_t *zone)
107 kmem_cache_destroy(zone); 108 kmem_cache_destroy(zone);
108} 109}
109 110
110extern void *kmem_zone_alloc(kmem_zone_t *, unsigned int __nocast); 111extern void *kmem_zone_alloc(kmem_zone_t *, xfs_km_flags_t);
111extern void *kmem_zone_zalloc(kmem_zone_t *, unsigned int __nocast); 112extern void *kmem_zone_zalloc(kmem_zone_t *, xfs_km_flags_t);
112 113
113#endif /* __XFS_SUPPORT_KMEM_H__ */ 114#endif /* __XFS_SUPPORT_KMEM_H__ */
diff --git a/fs/xfs/xfs_export.c b/fs/xfs/xfs_export.c
index 2d25d19c4ea1..42679223a0fd 100644
--- a/fs/xfs/xfs_export.c
+++ b/fs/xfs/xfs_export.c
@@ -52,19 +52,18 @@ static int xfs_fileid_length(int fileid_type)
52 52
53STATIC int 53STATIC int
54xfs_fs_encode_fh( 54xfs_fs_encode_fh(
55 struct dentry *dentry, 55 struct inode *inode,
56 __u32 *fh, 56 __u32 *fh,
57 int *max_len, 57 int *max_len,
58 int connectable) 58 struct inode *parent)
59{ 59{
60 struct fid *fid = (struct fid *)fh; 60 struct fid *fid = (struct fid *)fh;
61 struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fh; 61 struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fh;
62 struct inode *inode = dentry->d_inode;
63 int fileid_type; 62 int fileid_type;
64 int len; 63 int len;
65 64
66 /* Directories don't need their parent encoded, they have ".." */ 65 /* Directories don't need their parent encoded, they have ".." */
67 if (S_ISDIR(inode->i_mode) || !connectable) 66 if (!parent)
68 fileid_type = FILEID_INO32_GEN; 67 fileid_type = FILEID_INO32_GEN;
69 else 68 else
70 fileid_type = FILEID_INO32_GEN_PARENT; 69 fileid_type = FILEID_INO32_GEN_PARENT;
@@ -96,20 +95,16 @@ xfs_fs_encode_fh(
96 95
97 switch (fileid_type) { 96 switch (fileid_type) {
98 case FILEID_INO32_GEN_PARENT: 97 case FILEID_INO32_GEN_PARENT:
99 spin_lock(&dentry->d_lock); 98 fid->i32.parent_ino = XFS_I(parent)->i_ino;
100 fid->i32.parent_ino = XFS_I(dentry->d_parent->d_inode)->i_ino; 99 fid->i32.parent_gen = parent->i_generation;
101 fid->i32.parent_gen = dentry->d_parent->d_inode->i_generation;
102 spin_unlock(&dentry->d_lock);
103 /*FALLTHRU*/ 100 /*FALLTHRU*/
104 case FILEID_INO32_GEN: 101 case FILEID_INO32_GEN:
105 fid->i32.ino = XFS_I(inode)->i_ino; 102 fid->i32.ino = XFS_I(inode)->i_ino;
106 fid->i32.gen = inode->i_generation; 103 fid->i32.gen = inode->i_generation;
107 break; 104 break;
108 case FILEID_INO32_GEN_PARENT | XFS_FILEID_TYPE_64FLAG: 105 case FILEID_INO32_GEN_PARENT | XFS_FILEID_TYPE_64FLAG:
109 spin_lock(&dentry->d_lock); 106 fid64->parent_ino = XFS_I(parent)->i_ino;
110 fid64->parent_ino = XFS_I(dentry->d_parent->d_inode)->i_ino; 107 fid64->parent_gen = parent->i_generation;
111 fid64->parent_gen = dentry->d_parent->d_inode->i_generation;
112 spin_unlock(&dentry->d_lock);
113 /*FALLTHRU*/ 108 /*FALLTHRU*/
114 case FILEID_INO32_GEN | XFS_FILEID_TYPE_64FLAG: 109 case FILEID_INO32_GEN | XFS_FILEID_TYPE_64FLAG:
115 fid64->ino = XFS_I(inode)->i_ino; 110 fid64->ino = XFS_I(inode)->i_ino;
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 8d214b87f6bb..9f7ec15a6522 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -586,8 +586,11 @@ restart:
586 * lock above. Eventually we should look into a way to avoid 586 * lock above. Eventually we should look into a way to avoid
587 * the pointless lock roundtrip. 587 * the pointless lock roundtrip.
588 */ 588 */
589 if (likely(!(file->f_mode & FMODE_NOCMTIME))) 589 if (likely(!(file->f_mode & FMODE_NOCMTIME))) {
590 file_update_time(file); 590 error = file_update_time(file);
591 if (error)
592 return error;
593 }
591 594
592 /* 595 /*
593 * If we're writing the file then make sure to clear the setuid and 596 * If we're writing the file then make sure to clear the setuid and
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index 6b965bf450e4..f30d9807dc48 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -3152,7 +3152,7 @@ xlog_ticket_alloc(
3152 int cnt, 3152 int cnt,
3153 char client, 3153 char client,
3154 bool permanent, 3154 bool permanent,
3155 int alloc_flags) 3155 xfs_km_flags_t alloc_flags)
3156{ 3156{
3157 struct xlog_ticket *tic; 3157 struct xlog_ticket *tic;
3158 uint num_headers; 3158 uint num_headers;
diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h
index 735ff1ee53da..5bc33261f5be 100644
--- a/fs/xfs/xfs_log_priv.h
+++ b/fs/xfs/xfs_log_priv.h
@@ -555,7 +555,7 @@ extern void xlog_pack_data(xlog_t *log, xlog_in_core_t *iclog, int);
555extern kmem_zone_t *xfs_log_ticket_zone; 555extern kmem_zone_t *xfs_log_ticket_zone;
556struct xlog_ticket *xlog_ticket_alloc(struct log *log, int unit_bytes, 556struct xlog_ticket *xlog_ticket_alloc(struct log *log, int unit_bytes,
557 int count, char client, bool permanent, 557 int count, char client, bool permanent,
558 int alloc_flags); 558 xfs_km_flags_t alloc_flags);
559 559
560 560
561static inline void 561static inline void
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index cdf896fcbfa4..fdf324508c5e 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -584,7 +584,7 @@ xfs_trans_t *
584_xfs_trans_alloc( 584_xfs_trans_alloc(
585 xfs_mount_t *mp, 585 xfs_mount_t *mp,
586 uint type, 586 uint type,
587 uint memflags) 587 xfs_km_flags_t memflags)
588{ 588{
589 xfs_trans_t *tp; 589 xfs_trans_t *tp;
590 590
diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h
index 7ab99e1898c8..7c37b533aa8e 100644
--- a/fs/xfs/xfs_trans.h
+++ b/fs/xfs/xfs_trans.h
@@ -443,7 +443,7 @@ typedef struct xfs_trans {
443 * XFS transaction mechanism exported interfaces. 443 * XFS transaction mechanism exported interfaces.
444 */ 444 */
445xfs_trans_t *xfs_trans_alloc(struct xfs_mount *, uint); 445xfs_trans_t *xfs_trans_alloc(struct xfs_mount *, uint);
446xfs_trans_t *_xfs_trans_alloc(struct xfs_mount *, uint, uint); 446xfs_trans_t *_xfs_trans_alloc(struct xfs_mount *, uint, xfs_km_flags_t);
447xfs_trans_t *xfs_trans_dup(xfs_trans_t *); 447xfs_trans_t *xfs_trans_dup(xfs_trans_t *);
448int xfs_trans_reserve(xfs_trans_t *, uint, uint, uint, 448int xfs_trans_reserve(xfs_trans_t *, uint, uint, uint,
449 uint, uint); 449 uint, uint);
diff --git a/include/asm-generic/bitsperlong.h b/include/asm-generic/bitsperlong.h
index 4ae54e07de83..a7b0914348fd 100644
--- a/include/asm-generic/bitsperlong.h
+++ b/include/asm-generic/bitsperlong.h
@@ -28,5 +28,9 @@
28#error Inconsistent word size. Check asm/bitsperlong.h 28#error Inconsistent word size. Check asm/bitsperlong.h
29#endif 29#endif
30 30
31#ifndef BITS_PER_LONG_LONG
32#define BITS_PER_LONG_LONG 64
33#endif
34
31#endif /* __KERNEL__ */ 35#endif /* __KERNEL__ */
32#endif /* __ASM_GENERIC_BITS_PER_LONG */ 36#endif /* __ASM_GENERIC_BITS_PER_LONG */
diff --git a/include/asm-generic/posix_types.h b/include/asm-generic/posix_types.h
index 91d44bd4dde3..fe74fccf18db 100644
--- a/include/asm-generic/posix_types.h
+++ b/include/asm-generic/posix_types.h
@@ -23,10 +23,6 @@ typedef __kernel_ulong_t __kernel_ino_t;
23typedef unsigned int __kernel_mode_t; 23typedef unsigned int __kernel_mode_t;
24#endif 24#endif
25 25
26#ifndef __kernel_nlink_t
27typedef __kernel_ulong_t __kernel_nlink_t;
28#endif
29
30#ifndef __kernel_pid_t 26#ifndef __kernel_pid_t
31typedef int __kernel_pid_t; 27typedef int __kernel_pid_t;
32#endif 28#endif
diff --git a/include/drm/drm_mem_util.h b/include/drm/drm_mem_util.h
index 6bd325fedc87..19a240446fca 100644
--- a/include/drm/drm_mem_util.h
+++ b/include/drm/drm_mem_util.h
@@ -31,7 +31,7 @@
31 31
32static __inline__ void *drm_calloc_large(size_t nmemb, size_t size) 32static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
33{ 33{
34 if (size != 0 && nmemb > ULONG_MAX / size) 34 if (size != 0 && nmemb > SIZE_MAX / size)
35 return NULL; 35 return NULL;
36 36
37 if (size * nmemb <= PAGE_SIZE) 37 if (size * nmemb <= PAGE_SIZE)
@@ -44,7 +44,7 @@ static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
44/* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */ 44/* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */
45static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size) 45static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size)
46{ 46{
47 if (size != 0 && nmemb > ULONG_MAX / size) 47 if (size != 0 && nmemb > SIZE_MAX / size)
48 return NULL; 48 return NULL;
49 49
50 if (size * nmemb <= PAGE_SIZE) 50 if (size * nmemb <= PAGE_SIZE)
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index 7185b8f15ced..8760be30b375 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -226,6 +226,7 @@ header-y += kdev_t.h
226header-y += kernel.h 226header-y += kernel.h
227header-y += kernelcapi.h 227header-y += kernelcapi.h
228header-y += kernel-page-flags.h 228header-y += kernel-page-flags.h
229header-y += kexec.h
229header-y += keyboard.h 230header-y += keyboard.h
230header-y += keyctl.h 231header-y += keyctl.h
231header-y += l2tp.h 232header-y += l2tp.h
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 5d46217f84ad..4e890394ef99 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -577,8 +577,7 @@ extern ssize_t compat_rw_copy_check_uvector(int type,
577 const struct compat_iovec __user *uvector, 577 const struct compat_iovec __user *uvector,
578 unsigned long nr_segs, 578 unsigned long nr_segs,
579 unsigned long fast_segs, struct iovec *fast_pointer, 579 unsigned long fast_segs, struct iovec *fast_pointer,
580 struct iovec **ret_pointer, 580 struct iovec **ret_pointer);
581 int check_access);
582 581
583extern void __user *compat_alloc_user_space(unsigned long len); 582extern void __user *compat_alloc_user_space(unsigned long len);
584 583
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 7230bb59a06f..2e9b9ebbeb78 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -177,6 +177,7 @@ extern void put_online_cpus(void);
177#define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri) 177#define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
178#define register_hotcpu_notifier(nb) register_cpu_notifier(nb) 178#define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
179#define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb) 179#define unregister_hotcpu_notifier(nb) unregister_cpu_notifier(nb)
180void clear_tasks_mm_cpumask(int cpu);
180int cpu_down(unsigned int cpu); 181int cpu_down(unsigned int cpu);
181 182
182#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE 183#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
diff --git a/include/linux/cred.h b/include/linux/cred.h
index 917dc5aeb1d4..ebbed2ce6637 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -277,17 +277,13 @@ static inline void put_cred(const struct cred *_cred)
277 * @task: The task to query 277 * @task: The task to query
278 * 278 *
279 * Access the objective credentials of a task. The caller must hold the RCU 279 * Access the objective credentials of a task. The caller must hold the RCU
280 * readlock or the task must be dead and unable to change its own credentials. 280 * readlock.
281 * 281 *
282 * The result of this function should not be passed directly to get_cred(); 282 * The result of this function should not be passed directly to get_cred();
283 * rather get_task_cred() should be used instead. 283 * rather get_task_cred() should be used instead.
284 */ 284 */
285#define __task_cred(task) \ 285#define __task_cred(task) \
286 ({ \ 286 rcu_dereference((task)->real_cred)
287 const struct task_struct *__t = (task); \
288 rcu_dereference_check(__t->real_cred, \
289 task_is_dead(__t)); \
290 })
291 287
292/** 288/**
293 * get_current_cred - Get the current task's subjective credentials 289 * get_current_cred - Get the current task's subjective credentials
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index d3fec584e8c3..56377df39124 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -635,6 +635,18 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_sg(
635 dir, flags, NULL); 635 dir, flags, NULL);
636} 636}
637 637
638#ifdef CONFIG_RAPIDIO_DMA_ENGINE
639struct rio_dma_ext;
640static inline struct dma_async_tx_descriptor *dmaengine_prep_rio_sg(
641 struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len,
642 enum dma_transfer_direction dir, unsigned long flags,
643 struct rio_dma_ext *rio_ext)
644{
645 return chan->device->device_prep_slave_sg(chan, sgl, sg_len,
646 dir, flags, rio_ext);
647}
648#endif
649
638static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic( 650static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic(
639 struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, 651 struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
640 size_t period_len, enum dma_transfer_direction dir) 652 size_t period_len, enum dma_transfer_direction dir)
diff --git a/include/linux/errno.h b/include/linux/errno.h
index 2d09bfa5c262..e0de516374da 100644
--- a/include/linux/errno.h
+++ b/include/linux/errno.h
@@ -17,6 +17,7 @@
17#define ENOIOCTLCMD 515 /* No ioctl command */ 17#define ENOIOCTLCMD 515 /* No ioctl command */
18#define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */ 18#define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
19#define EPROBE_DEFER 517 /* Driver requests probe retry */ 19#define EPROBE_DEFER 517 /* Driver requests probe retry */
20#define EOPENSTALE 518 /* open found a stale dentry */
20 21
21/* Defined for the NFSv3 protocol */ 22/* Defined for the NFSv3 protocol */
22#define EBADHANDLE 521 /* Illegal NFS file handle */ 23#define EBADHANDLE 521 /* Illegal NFS file handle */
diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
index 91bb4f27238c..3c3ef19a625a 100644
--- a/include/linux/eventfd.h
+++ b/include/linux/eventfd.h
@@ -34,7 +34,7 @@ void eventfd_ctx_put(struct eventfd_ctx *ctx);
34struct file *eventfd_fget(int fd); 34struct file *eventfd_fget(int fd);
35struct eventfd_ctx *eventfd_ctx_fdget(int fd); 35struct eventfd_ctx *eventfd_ctx_fdget(int fd);
36struct eventfd_ctx *eventfd_ctx_fileget(struct file *file); 36struct eventfd_ctx *eventfd_ctx_fileget(struct file *file);
37int eventfd_signal(struct eventfd_ctx *ctx, int n); 37__u64 eventfd_signal(struct eventfd_ctx *ctx, __u64 n);
38ssize_t eventfd_ctx_read(struct eventfd_ctx *ctx, int no_wait, __u64 *cnt); 38ssize_t eventfd_ctx_read(struct eventfd_ctx *ctx, int no_wait, __u64 *cnt);
39int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_t *wait, 39int eventfd_ctx_remove_wait_queue(struct eventfd_ctx *ctx, wait_queue_t *wait,
40 __u64 *cnt); 40 __u64 *cnt);
diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h
index 3a4cef5322dc..12291a7ee275 100644
--- a/include/linux/exportfs.h
+++ b/include/linux/exportfs.h
@@ -165,8 +165,8 @@ struct fid {
165 */ 165 */
166 166
167struct export_operations { 167struct export_operations {
168 int (*encode_fh)(struct dentry *de, __u32 *fh, int *max_len, 168 int (*encode_fh)(struct inode *inode, __u32 *fh, int *max_len,
169 int connectable); 169 struct inode *parent);
170 struct dentry * (*fh_to_dentry)(struct super_block *sb, struct fid *fid, 170 struct dentry * (*fh_to_dentry)(struct super_block *sb, struct fid *fid,
171 int fh_len, int fh_type); 171 int fh_len, int fh_type);
172 struct dentry * (*fh_to_parent)(struct super_block *sb, struct fid *fid, 172 struct dentry * (*fh_to_parent)(struct super_block *sb, struct fid *fid,
diff --git a/include/linux/fb.h b/include/linux/fb.h
index a3229d7ab9f2..ac3f1c605843 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -611,6 +611,7 @@ struct fb_deferred_io {
611 struct mutex lock; /* mutex that protects the page list */ 611 struct mutex lock; /* mutex that protects the page list */
612 struct list_head pagelist; /* list of touched pages */ 612 struct list_head pagelist; /* list of touched pages */
613 /* callback */ 613 /* callback */
614 void (*first_io)(struct fb_info *info);
614 void (*deferred_io)(struct fb_info *info, struct list_head *pagelist); 615 void (*deferred_io)(struct fb_info *info, struct list_head *pagelist);
615}; 616};
616#endif 617#endif
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 598a5892ff2b..51978ed43e97 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -173,6 +173,15 @@ struct inodes_stat_t {
173#define WRITE_FUA (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FUA) 173#define WRITE_FUA (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FUA)
174#define WRITE_FLUSH_FUA (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FLUSH | REQ_FUA) 174#define WRITE_FLUSH_FUA (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FLUSH | REQ_FUA)
175 175
176
177/*
178 * Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector
179 * that indicates that they should check the contents of the iovec are
180 * valid, but not check the memory that the iovec elements
181 * points too.
182 */
183#define CHECK_IOVEC_ONLY -1
184
176#define SEL_IN 1 185#define SEL_IN 1
177#define SEL_OUT 2 186#define SEL_OUT 2
178#define SEL_EX 4 187#define SEL_EX 4
@@ -1683,6 +1692,7 @@ struct inode_operations {
1683 int (*removexattr) (struct dentry *, const char *); 1692 int (*removexattr) (struct dentry *, const char *);
1684 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, 1693 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
1685 u64 len); 1694 u64 len);
1695 int (*update_time)(struct inode *, struct timespec *, int);
1686} ____cacheline_aligned; 1696} ____cacheline_aligned;
1687 1697
1688struct seq_file; 1698struct seq_file;
@@ -1690,8 +1700,7 @@ struct seq_file;
1690ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, 1700ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
1691 unsigned long nr_segs, unsigned long fast_segs, 1701 unsigned long nr_segs, unsigned long fast_segs,
1692 struct iovec *fast_pointer, 1702 struct iovec *fast_pointer,
1693 struct iovec **ret_pointer, 1703 struct iovec **ret_pointer);
1694 int check_access);
1695 1704
1696extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); 1705extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
1697extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); 1706extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
@@ -1842,6 +1851,13 @@ static inline void inode_inc_iversion(struct inode *inode)
1842 spin_unlock(&inode->i_lock); 1851 spin_unlock(&inode->i_lock);
1843} 1852}
1844 1853
1854enum file_time_flags {
1855 S_ATIME = 1,
1856 S_MTIME = 2,
1857 S_CTIME = 4,
1858 S_VERSION = 8,
1859};
1860
1845extern void touch_atime(struct path *); 1861extern void touch_atime(struct path *);
1846static inline void file_accessed(struct file *file) 1862static inline void file_accessed(struct file *file)
1847{ 1863{
@@ -2575,7 +2591,7 @@ extern int inode_change_ok(const struct inode *, struct iattr *);
2575extern int inode_newsize_ok(const struct inode *, loff_t offset); 2591extern int inode_newsize_ok(const struct inode *, loff_t offset);
2576extern void setattr_copy(struct inode *inode, const struct iattr *attr); 2592extern void setattr_copy(struct inode *inode, const struct iattr *attr);
2577 2593
2578extern void file_update_time(struct file *file); 2594extern int file_update_time(struct file *file);
2579 2595
2580extern int generic_show_options(struct seq_file *m, struct dentry *root); 2596extern int generic_show_options(struct seq_file *m, struct dentry *root);
2581extern void save_mount_options(struct super_block *sb, char *options); 2597extern void save_mount_options(struct super_block *sb, char *options);
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 91d0e0a34ef3..63d966d5c2ea 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -60,7 +60,7 @@
60#define FS_EVENTS_POSS_ON_CHILD (FS_ACCESS | FS_MODIFY | FS_ATTRIB |\ 60#define FS_EVENTS_POSS_ON_CHILD (FS_ACCESS | FS_MODIFY | FS_ATTRIB |\
61 FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN |\ 61 FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN |\
62 FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE |\ 62 FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE |\
63 FS_DELETE) 63 FS_DELETE | FS_OPEN_PERM | FS_ACCESS_PERM)
64 64
65#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) 65#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO)
66 66
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index c91171599cb6..e68a8e53bb59 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -142,8 +142,6 @@ request_any_context_irq(unsigned int irq, irq_handler_t handler,
142extern int __must_check 142extern int __must_check
143request_percpu_irq(unsigned int irq, irq_handler_t handler, 143request_percpu_irq(unsigned int irq, irq_handler_t handler,
144 const char *devname, void __percpu *percpu_dev_id); 144 const char *devname, void __percpu *percpu_dev_id);
145
146extern void exit_irq_thread(void);
147#else 145#else
148 146
149extern int __must_check 147extern int __must_check
@@ -177,8 +175,6 @@ request_percpu_irq(unsigned int irq, irq_handler_t handler,
177{ 175{
178 return request_irq(irq, handler, 0, devname, percpu_dev_id); 176 return request_irq(irq, handler, 0, devname, percpu_dev_id);
179} 177}
180
181static inline void exit_irq_thread(void) { }
182#endif 178#endif
183 179
184extern void free_irq(unsigned int, void *); 180extern void free_irq(unsigned int, void *);
diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
index 8a297a5e794c..5499c92a9153 100644
--- a/include/linux/ipc_namespace.h
+++ b/include/linux/ipc_namespace.h
@@ -62,6 +62,8 @@ struct ipc_namespace {
62 unsigned int mq_queues_max; /* initialized to DFLT_QUEUESMAX */ 62 unsigned int mq_queues_max; /* initialized to DFLT_QUEUESMAX */
63 unsigned int mq_msg_max; /* initialized to DFLT_MSGMAX */ 63 unsigned int mq_msg_max; /* initialized to DFLT_MSGMAX */
64 unsigned int mq_msgsize_max; /* initialized to DFLT_MSGSIZEMAX */ 64 unsigned int mq_msgsize_max; /* initialized to DFLT_MSGSIZEMAX */
65 unsigned int mq_msg_default;
66 unsigned int mq_msgsize_default;
65 67
66 /* user_ns which owns the ipc ns */ 68 /* user_ns which owns the ipc ns */
67 struct user_namespace *user_ns; 69 struct user_namespace *user_ns;
@@ -90,11 +92,41 @@ static inline void shm_destroy_orphaned(struct ipc_namespace *ns) {}
90 92
91#ifdef CONFIG_POSIX_MQUEUE 93#ifdef CONFIG_POSIX_MQUEUE
92extern int mq_init_ns(struct ipc_namespace *ns); 94extern int mq_init_ns(struct ipc_namespace *ns);
93/* default values */ 95/*
94#define DFLT_QUEUESMAX 256 /* max number of message queues */ 96 * POSIX Message Queue default values:
95#define DFLT_MSGMAX 10 /* max number of messages in each queue */ 97 *
96#define HARD_MSGMAX (32768*sizeof(void *)/4) 98 * MIN_*: Lowest value an admin can set the maximum unprivileged limit to
97#define DFLT_MSGSIZEMAX 8192 /* max message size */ 99 * DFLT_*MAX: Default values for the maximum unprivileged limits
100 * DFLT_{MSG,MSGSIZE}: Default values used when the user doesn't supply
101 * an attribute to the open call and the queue must be created
102 * HARD_*: Highest value the maximums can be set to. These are enforced
103 * on CAP_SYS_RESOURCE apps as well making them inviolate (so make them
104 * suitably high)
105 *
106 * POSIX Requirements:
107 * Per app minimum openable message queues - 8. This does not map well
108 * to the fact that we limit the number of queues on a per namespace
109 * basis instead of a per app basis. So, make the default high enough
110 * that no given app should have a hard time opening 8 queues.
111 * Minimum maximum for HARD_MSGMAX - 32767. I bumped this to 65536.
112 * Minimum maximum for HARD_MSGSIZEMAX - POSIX is silent on this. However,
113 * we have run into a situation where running applications in the wild
114 * require this to be at least 5MB, and preferably 10MB, so I set the
115 * value to 16MB in hopes that this user is the worst of the bunch and
116 * the new maximum will handle anyone else. I may have to revisit this
117 * in the future.
118 */
119#define MIN_QUEUESMAX 1
120#define DFLT_QUEUESMAX 256
121#define HARD_QUEUESMAX 1024
122#define MIN_MSGMAX 1
123#define DFLT_MSG 10U
124#define DFLT_MSGMAX 10
125#define HARD_MSGMAX 65536
126#define MIN_MSGSIZEMAX 128
127#define DFLT_MSGSIZE 8192U
128#define DFLT_MSGSIZEMAX 8192
129#define HARD_MSGSIZEMAX (16*1024*1024)
98#else 130#else
99static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; } 131static inline int mq_init_ns(struct ipc_namespace *ns) { return 0; }
100#endif 132#endif
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index 912c30a8ddb1..f334c7fab967 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -31,6 +31,7 @@
31#include <linux/mutex.h> 31#include <linux/mutex.h>
32#include <linux/timer.h> 32#include <linux/timer.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <crypto/hash.h>
34#endif 35#endif
35 36
36#define journal_oom_retry 1 37#define journal_oom_retry 1
@@ -147,12 +148,24 @@ typedef struct journal_header_s
147#define JBD2_CRC32_CHKSUM 1 148#define JBD2_CRC32_CHKSUM 1
148#define JBD2_MD5_CHKSUM 2 149#define JBD2_MD5_CHKSUM 2
149#define JBD2_SHA1_CHKSUM 3 150#define JBD2_SHA1_CHKSUM 3
151#define JBD2_CRC32C_CHKSUM 4
150 152
151#define JBD2_CRC32_CHKSUM_SIZE 4 153#define JBD2_CRC32_CHKSUM_SIZE 4
152 154
153#define JBD2_CHECKSUM_BYTES (32 / sizeof(u32)) 155#define JBD2_CHECKSUM_BYTES (32 / sizeof(u32))
154/* 156/*
155 * Commit block header for storing transactional checksums: 157 * Commit block header for storing transactional checksums:
158 *
159 * NOTE: If FEATURE_COMPAT_CHECKSUM (checksum v1) is set, the h_chksum*
160 * fields are used to store a checksum of the descriptor and data blocks.
161 *
162 * If FEATURE_INCOMPAT_CSUM_V2 (checksum v2) is set, then the h_chksum
163 * field is used to store crc32c(uuid+commit_block). Each journal metadata
164 * block gets its own checksum, and data block checksums are stored in
165 * journal_block_tag (in the descriptor). The other h_chksum* fields are
166 * not used.
167 *
168 * Checksum v1 and v2 are mutually exclusive features.
156 */ 169 */
157struct commit_header { 170struct commit_header {
158 __be32 h_magic; 171 __be32 h_magic;
@@ -175,13 +188,19 @@ struct commit_header {
175typedef struct journal_block_tag_s 188typedef struct journal_block_tag_s
176{ 189{
177 __be32 t_blocknr; /* The on-disk block number */ 190 __be32 t_blocknr; /* The on-disk block number */
178 __be32 t_flags; /* See below */ 191 __be16 t_checksum; /* truncated crc32c(uuid+seq+block) */
192 __be16 t_flags; /* See below */
179 __be32 t_blocknr_high; /* most-significant high 32bits. */ 193 __be32 t_blocknr_high; /* most-significant high 32bits. */
180} journal_block_tag_t; 194} journal_block_tag_t;
181 195
182#define JBD2_TAG_SIZE32 (offsetof(journal_block_tag_t, t_blocknr_high)) 196#define JBD2_TAG_SIZE32 (offsetof(journal_block_tag_t, t_blocknr_high))
183#define JBD2_TAG_SIZE64 (sizeof(journal_block_tag_t)) 197#define JBD2_TAG_SIZE64 (sizeof(journal_block_tag_t))
184 198
199/* Tail of descriptor block, for checksumming */
200struct jbd2_journal_block_tail {
201 __be32 t_checksum; /* crc32c(uuid+descr_block) */
202};
203
185/* 204/*
186 * The revoke descriptor: used on disk to describe a series of blocks to 205 * The revoke descriptor: used on disk to describe a series of blocks to
187 * be revoked from the log 206 * be revoked from the log
@@ -192,6 +211,10 @@ typedef struct jbd2_journal_revoke_header_s
192 __be32 r_count; /* Count of bytes used in the block */ 211 __be32 r_count; /* Count of bytes used in the block */
193} jbd2_journal_revoke_header_t; 212} jbd2_journal_revoke_header_t;
194 213
214/* Tail of revoke block, for checksumming */
215struct jbd2_journal_revoke_tail {
216 __be32 r_checksum; /* crc32c(uuid+revoke_block) */
217};
195 218
196/* Definitions for the journal tag flags word: */ 219/* Definitions for the journal tag flags word: */
197#define JBD2_FLAG_ESCAPE 1 /* on-disk block is escaped */ 220#define JBD2_FLAG_ESCAPE 1 /* on-disk block is escaped */
@@ -241,7 +264,10 @@ typedef struct journal_superblock_s
241 __be32 s_max_trans_data; /* Limit of data blocks per trans. */ 264 __be32 s_max_trans_data; /* Limit of data blocks per trans. */
242 265
243/* 0x0050 */ 266/* 0x0050 */
244 __u32 s_padding[44]; 267 __u8 s_checksum_type; /* checksum type */
268 __u8 s_padding2[3];
269 __u32 s_padding[42];
270 __be32 s_checksum; /* crc32c(superblock) */
245 271
246/* 0x0100 */ 272/* 0x0100 */
247 __u8 s_users[16*48]; /* ids of all fs'es sharing the log */ 273 __u8 s_users[16*48]; /* ids of all fs'es sharing the log */
@@ -263,13 +289,15 @@ typedef struct journal_superblock_s
263#define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001 289#define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001
264#define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002 290#define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002
265#define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004 291#define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004
292#define JBD2_FEATURE_INCOMPAT_CSUM_V2 0x00000008
266 293
267/* Features known to this kernel version: */ 294/* Features known to this kernel version: */
268#define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM 295#define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM
269#define JBD2_KNOWN_ROCOMPAT_FEATURES 0 296#define JBD2_KNOWN_ROCOMPAT_FEATURES 0
270#define JBD2_KNOWN_INCOMPAT_FEATURES (JBD2_FEATURE_INCOMPAT_REVOKE | \ 297#define JBD2_KNOWN_INCOMPAT_FEATURES (JBD2_FEATURE_INCOMPAT_REVOKE | \
271 JBD2_FEATURE_INCOMPAT_64BIT | \ 298 JBD2_FEATURE_INCOMPAT_64BIT | \
272 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) 299 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT | \
300 JBD2_FEATURE_INCOMPAT_CSUM_V2)
273 301
274#ifdef __KERNEL__ 302#ifdef __KERNEL__
275 303
@@ -939,6 +967,12 @@ struct journal_s
939 * superblock pointer here 967 * superblock pointer here
940 */ 968 */
941 void *j_private; 969 void *j_private;
970
971 /* Reference to checksum algorithm driver via cryptoapi */
972 struct crypto_shash *j_chksum_driver;
973
974 /* Precomputed journal UUID checksum for seeding other checksums */
975 __u32 j_csum_seed;
942}; 976};
943 977
944/* 978/*
@@ -1268,6 +1302,25 @@ static inline int jbd_space_needed(journal_t *journal)
1268 1302
1269extern int jbd_blocks_per_page(struct inode *inode); 1303extern int jbd_blocks_per_page(struct inode *inode);
1270 1304
1305static inline u32 jbd2_chksum(journal_t *journal, u32 crc,
1306 const void *address, unsigned int length)
1307{
1308 struct {
1309 struct shash_desc shash;
1310 char ctx[crypto_shash_descsize(journal->j_chksum_driver)];
1311 } desc;
1312 int err;
1313
1314 desc.shash.tfm = journal->j_chksum_driver;
1315 desc.shash.flags = 0;
1316 *(u32 *)desc.ctx = crc;
1317
1318 err = crypto_shash_update(&desc.shash, address, length);
1319 BUG_ON(err);
1320
1321 return *(u32 *)desc.ctx;
1322}
1323
1271#ifdef __KERNEL__ 1324#ifdef __KERNEL__
1272 1325
1273#define buffer_trace_init(bh) do {} while (0) 1326#define buffer_trace_init(bh) do {} while (0)
diff --git a/include/linux/jbd_common.h b/include/linux/jbd_common.h
index 6230f8556a4e..6133679bc4c0 100644
--- a/include/linux/jbd_common.h
+++ b/include/linux/jbd_common.h
@@ -12,6 +12,7 @@ enum jbd_state_bits {
12 BH_State, /* Pins most journal_head state */ 12 BH_State, /* Pins most journal_head state */
13 BH_JournalHead, /* Pins bh->b_private and jh->b_bh */ 13 BH_JournalHead, /* Pins bh->b_private and jh->b_bh */
14 BH_Unshadow, /* Dummy bit, for BJ_Shadow wakeup filtering */ 14 BH_Unshadow, /* Dummy bit, for BJ_Shadow wakeup filtering */
15 BH_Verified, /* Metadata block has been verified ok */
15 BH_JBDPrivateStart, /* First bit available for private use by FS */ 16 BH_JBDPrivateStart, /* First bit available for private use by FS */
16}; 17};
17 18
@@ -24,6 +25,7 @@ TAS_BUFFER_FNS(Revoked, revoked)
24BUFFER_FNS(RevokeValid, revokevalid) 25BUFFER_FNS(RevokeValid, revokevalid)
25TAS_BUFFER_FNS(RevokeValid, revokevalid) 26TAS_BUFFER_FNS(RevokeValid, revokevalid)
26BUFFER_FNS(Freed, freed) 27BUFFER_FNS(Freed, freed)
28BUFFER_FNS(Verified, verified)
27 29
28static inline struct buffer_head *jh2bh(struct journal_head *jh) 30static inline struct buffer_head *jh2bh(struct journal_head *jh)
29{ 31{
diff --git a/include/linux/kcmp.h b/include/linux/kcmp.h
new file mode 100644
index 000000000000..2dcd1b3aafc8
--- /dev/null
+++ b/include/linux/kcmp.h
@@ -0,0 +1,17 @@
1#ifndef _LINUX_KCMP_H
2#define _LINUX_KCMP_H
3
4/* Comparison type */
5enum kcmp_type {
6 KCMP_FILE,
7 KCMP_VM,
8 KCMP_FILES,
9 KCMP_FS,
10 KCMP_SIGHAND,
11 KCMP_IO,
12 KCMP_SYSVSEM,
13
14 KCMP_TYPES,
15};
16
17#endif /* _LINUX_KCMP_H */
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index ec55a3c8ba77..e07f5e0c5df4 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -35,6 +35,7 @@
35#define LLONG_MAX ((long long)(~0ULL>>1)) 35#define LLONG_MAX ((long long)(~0ULL>>1))
36#define LLONG_MIN (-LLONG_MAX - 1) 36#define LLONG_MIN (-LLONG_MAX - 1)
37#define ULLONG_MAX (~0ULL) 37#define ULLONG_MAX (~0ULL)
38#define SIZE_MAX (~(size_t)0)
38 39
39#define STACK_MAGIC 0xdeadbeef 40#define STACK_MAGIC 0xdeadbeef
40 41
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index 0d7d6a1b172f..37c5f7261142 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -1,8 +1,58 @@
1#ifndef LINUX_KEXEC_H 1#ifndef LINUX_KEXEC_H
2#define LINUX_KEXEC_H 2#define LINUX_KEXEC_H
3 3
4#ifdef CONFIG_KEXEC 4/* kexec system call - It loads the new kernel to boot into.
5 * kexec does not sync, or unmount filesystems so if you need
6 * that to happen you need to do that yourself.
7 */
8
5#include <linux/types.h> 9#include <linux/types.h>
10
11/* kexec flags for different usage scenarios */
12#define KEXEC_ON_CRASH 0x00000001
13#define KEXEC_PRESERVE_CONTEXT 0x00000002
14#define KEXEC_ARCH_MASK 0xffff0000
15
16/* These values match the ELF architecture values.
17 * Unless there is a good reason that should continue to be the case.
18 */
19#define KEXEC_ARCH_DEFAULT ( 0 << 16)
20#define KEXEC_ARCH_386 ( 3 << 16)
21#define KEXEC_ARCH_X86_64 (62 << 16)
22#define KEXEC_ARCH_PPC (20 << 16)
23#define KEXEC_ARCH_PPC64 (21 << 16)
24#define KEXEC_ARCH_IA_64 (50 << 16)
25#define KEXEC_ARCH_ARM (40 << 16)
26#define KEXEC_ARCH_S390 (22 << 16)
27#define KEXEC_ARCH_SH (42 << 16)
28#define KEXEC_ARCH_MIPS_LE (10 << 16)
29#define KEXEC_ARCH_MIPS ( 8 << 16)
30
31/* The artificial cap on the number of segments passed to kexec_load. */
32#define KEXEC_SEGMENT_MAX 16
33
34#ifndef __KERNEL__
35/*
36 * This structure is used to hold the arguments that are used when
37 * loading kernel binaries.
38 */
39struct kexec_segment {
40 const void *buf;
41 size_t bufsz;
42 const void *mem;
43 size_t memsz;
44};
45
46/* Load a new kernel image as described by the kexec_segment array
47 * consisting of passed number of segments at the entry-point address.
48 * The flags allow different useage types.
49 */
50extern int kexec_load(void *, size_t, struct kexec_segment *,
51 unsigned long int);
52#endif /* __KERNEL__ */
53
54#ifdef __KERNEL__
55#ifdef CONFIG_KEXEC
6#include <linux/list.h> 56#include <linux/list.h>
7#include <linux/linkage.h> 57#include <linux/linkage.h>
8#include <linux/compat.h> 58#include <linux/compat.h>
@@ -67,11 +117,10 @@ typedef unsigned long kimage_entry_t;
67#define IND_DONE 0x4 117#define IND_DONE 0x4
68#define IND_SOURCE 0x8 118#define IND_SOURCE 0x8
69 119
70#define KEXEC_SEGMENT_MAX 16
71struct kexec_segment { 120struct kexec_segment {
72 void __user *buf; 121 void __user *buf;
73 size_t bufsz; 122 size_t bufsz;
74 unsigned long mem; /* User space sees this as a (void *) ... */ 123 unsigned long mem;
75 size_t memsz; 124 size_t memsz;
76}; 125};
77 126
@@ -175,25 +224,6 @@ extern struct kimage *kexec_crash_image;
175#define kexec_flush_icache_page(page) 224#define kexec_flush_icache_page(page)
176#endif 225#endif
177 226
178#define KEXEC_ON_CRASH 0x00000001
179#define KEXEC_PRESERVE_CONTEXT 0x00000002
180#define KEXEC_ARCH_MASK 0xffff0000
181
182/* These values match the ELF architecture values.
183 * Unless there is a good reason that should continue to be the case.
184 */
185#define KEXEC_ARCH_DEFAULT ( 0 << 16)
186#define KEXEC_ARCH_386 ( 3 << 16)
187#define KEXEC_ARCH_X86_64 (62 << 16)
188#define KEXEC_ARCH_PPC (20 << 16)
189#define KEXEC_ARCH_PPC64 (21 << 16)
190#define KEXEC_ARCH_IA_64 (50 << 16)
191#define KEXEC_ARCH_ARM (40 << 16)
192#define KEXEC_ARCH_S390 (22 << 16)
193#define KEXEC_ARCH_SH (42 << 16)
194#define KEXEC_ARCH_MIPS_LE (10 << 16)
195#define KEXEC_ARCH_MIPS ( 8 << 16)
196
197/* List of defined/legal kexec flags */ 227/* List of defined/legal kexec flags */
198#ifndef CONFIG_KEXEC_JUMP 228#ifndef CONFIG_KEXEC_JUMP
199#define KEXEC_FLAGS KEXEC_ON_CRASH 229#define KEXEC_FLAGS KEXEC_ON_CRASH
@@ -228,4 +258,5 @@ struct task_struct;
228static inline void crash_kexec(struct pt_regs *regs) { } 258static inline void crash_kexec(struct pt_regs *regs) { }
229static inline int kexec_should_crash(struct task_struct *p) { return 0; } 259static inline int kexec_should_crash(struct task_struct *p) { return 0; }
230#endif /* CONFIG_KEXEC */ 260#endif /* CONFIG_KEXEC */
261#endif /* __KERNEL__ */
231#endif /* LINUX_KEXEC_H */ 262#endif /* LINUX_KEXEC_H */
diff --git a/include/linux/key.h b/include/linux/key.h
index 5231800770e1..4cd22ed627ef 100644
--- a/include/linux/key.h
+++ b/include/linux/key.h
@@ -308,9 +308,6 @@ static inline bool key_is_instantiated(const struct key *key)
308#ifdef CONFIG_SYSCTL 308#ifdef CONFIG_SYSCTL
309extern ctl_table key_sysctls[]; 309extern ctl_table key_sysctls[];
310#endif 310#endif
311
312extern void key_replace_session_keyring(void);
313
314/* 311/*
315 * the userspace interface 312 * the userspace interface
316 */ 313 */
@@ -334,7 +331,6 @@ extern void key_init(void);
334#define key_fsuid_changed(t) do { } while(0) 331#define key_fsuid_changed(t) do { } while(0)
335#define key_fsgid_changed(t) do { } while(0) 332#define key_fsgid_changed(t) do { } while(0)
336#define key_init() do { } while(0) 333#define key_init() do { } while(0)
337#define key_replace_session_keyring() do { } while(0)
338 334
339#endif /* CONFIG_KEYS */ 335#endif /* CONFIG_KEYS */
340#endif /* __KERNEL__ */ 336#endif /* __KERNEL__ */
diff --git a/include/linux/kmod.h b/include/linux/kmod.h
index dd99c329e161..5398d5807075 100644
--- a/include/linux/kmod.h
+++ b/include/linux/kmod.h
@@ -66,40 +66,10 @@ struct subprocess_info {
66 void *data; 66 void *data;
67}; 67};
68 68
69/* Allocate a subprocess_info structure */ 69extern int
70struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
71 char **envp, gfp_t gfp_mask);
72
73/* Set various pieces of state into the subprocess_info structure */
74void call_usermodehelper_setfns(struct subprocess_info *info,
75 int (*init)(struct subprocess_info *info, struct cred *new),
76 void (*cleanup)(struct subprocess_info *info),
77 void *data);
78
79/* Actually execute the sub-process */
80int call_usermodehelper_exec(struct subprocess_info *info, int wait);
81
82/* Free the subprocess_info. This is only needed if you're not going
83 to call call_usermodehelper_exec */
84void call_usermodehelper_freeinfo(struct subprocess_info *info);
85
86static inline int
87call_usermodehelper_fns(char *path, char **argv, char **envp, int wait, 70call_usermodehelper_fns(char *path, char **argv, char **envp, int wait,
88 int (*init)(struct subprocess_info *info, struct cred *new), 71 int (*init)(struct subprocess_info *info, struct cred *new),
89 void (*cleanup)(struct subprocess_info *), void *data) 72 void (*cleanup)(struct subprocess_info *), void *data);
90{
91 struct subprocess_info *info;
92 gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
93
94 info = call_usermodehelper_setup(path, argv, envp, gfp_mask);
95
96 if (info == NULL)
97 return -ENOMEM;
98
99 call_usermodehelper_setfns(info, init, cleanup, data);
100
101 return call_usermodehelper_exec(info, wait);
102}
103 73
104static inline int 74static inline int
105call_usermodehelper(char *path, char **argv, char **envp, int wait) 75call_usermodehelper(char *path, char **argv, char **envp, int wait)
diff --git a/include/linux/lglock.h b/include/linux/lglock.h
index 87f402ccec55..f01e5f6d1f07 100644
--- a/include/linux/lglock.h
+++ b/include/linux/lglock.h
@@ -23,28 +23,17 @@
23#include <linux/lockdep.h> 23#include <linux/lockdep.h>
24#include <linux/percpu.h> 24#include <linux/percpu.h>
25#include <linux/cpu.h> 25#include <linux/cpu.h>
26#include <linux/notifier.h>
26 27
27/* can make br locks by using local lock for read side, global lock for write */ 28/* can make br locks by using local lock for read side, global lock for write */
28#define br_lock_init(name) name##_lock_init() 29#define br_lock_init(name) lg_lock_init(name, #name)
29#define br_read_lock(name) name##_local_lock() 30#define br_read_lock(name) lg_local_lock(name)
30#define br_read_unlock(name) name##_local_unlock() 31#define br_read_unlock(name) lg_local_unlock(name)
31#define br_write_lock(name) name##_global_lock_online() 32#define br_write_lock(name) lg_global_lock(name)
32#define br_write_unlock(name) name##_global_unlock_online() 33#define br_write_unlock(name) lg_global_unlock(name)
33 34
34#define DECLARE_BRLOCK(name) DECLARE_LGLOCK(name)
35#define DEFINE_BRLOCK(name) DEFINE_LGLOCK(name) 35#define DEFINE_BRLOCK(name) DEFINE_LGLOCK(name)
36 36
37
38#define lg_lock_init(name) name##_lock_init()
39#define lg_local_lock(name) name##_local_lock()
40#define lg_local_unlock(name) name##_local_unlock()
41#define lg_local_lock_cpu(name, cpu) name##_local_lock_cpu(cpu)
42#define lg_local_unlock_cpu(name, cpu) name##_local_unlock_cpu(cpu)
43#define lg_global_lock(name) name##_global_lock()
44#define lg_global_unlock(name) name##_global_unlock()
45#define lg_global_lock_online(name) name##_global_lock_online()
46#define lg_global_unlock_online(name) name##_global_unlock_online()
47
48#ifdef CONFIG_DEBUG_LOCK_ALLOC 37#ifdef CONFIG_DEBUG_LOCK_ALLOC
49#define LOCKDEP_INIT_MAP lockdep_init_map 38#define LOCKDEP_INIT_MAP lockdep_init_map
50 39
@@ -59,142 +48,26 @@
59#define DEFINE_LGLOCK_LOCKDEP(name) 48#define DEFINE_LGLOCK_LOCKDEP(name)
60#endif 49#endif
61 50
62 51struct lglock {
63#define DECLARE_LGLOCK(name) \ 52 arch_spinlock_t __percpu *lock;
64 extern void name##_lock_init(void); \ 53#ifdef CONFIG_DEBUG_LOCK_ALLOC
65 extern void name##_local_lock(void); \ 54 struct lock_class_key lock_key;
66 extern void name##_local_unlock(void); \ 55 struct lockdep_map lock_dep_map;
67 extern void name##_local_lock_cpu(int cpu); \ 56#endif
68 extern void name##_local_unlock_cpu(int cpu); \ 57};
69 extern void name##_global_lock(void); \
70 extern void name##_global_unlock(void); \
71 extern void name##_global_lock_online(void); \
72 extern void name##_global_unlock_online(void); \
73 58
74#define DEFINE_LGLOCK(name) \ 59#define DEFINE_LGLOCK(name) \
75 \ 60 DEFINE_LGLOCK_LOCKDEP(name); \
76 DEFINE_SPINLOCK(name##_cpu_lock); \ 61 DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
77 cpumask_t name##_cpus __read_mostly; \ 62 = __ARCH_SPIN_LOCK_UNLOCKED; \
78 DEFINE_PER_CPU(arch_spinlock_t, name##_lock); \ 63 struct lglock name = { .lock = &name ## _lock }
79 DEFINE_LGLOCK_LOCKDEP(name); \ 64
80 \ 65void lg_lock_init(struct lglock *lg, char *name);
81 static int \ 66void lg_local_lock(struct lglock *lg);
82 name##_lg_cpu_callback(struct notifier_block *nb, \ 67void lg_local_unlock(struct lglock *lg);
83 unsigned long action, void *hcpu) \ 68void lg_local_lock_cpu(struct lglock *lg, int cpu);
84 { \ 69void lg_local_unlock_cpu(struct lglock *lg, int cpu);
85 switch (action & ~CPU_TASKS_FROZEN) { \ 70void lg_global_lock(struct lglock *lg);
86 case CPU_UP_PREPARE: \ 71void lg_global_unlock(struct lglock *lg);
87 spin_lock(&name##_cpu_lock); \ 72
88 cpu_set((unsigned long)hcpu, name##_cpus); \
89 spin_unlock(&name##_cpu_lock); \
90 break; \
91 case CPU_UP_CANCELED: case CPU_DEAD: \
92 spin_lock(&name##_cpu_lock); \
93 cpu_clear((unsigned long)hcpu, name##_cpus); \
94 spin_unlock(&name##_cpu_lock); \
95 } \
96 return NOTIFY_OK; \
97 } \
98 static struct notifier_block name##_lg_cpu_notifier = { \
99 .notifier_call = name##_lg_cpu_callback, \
100 }; \
101 void name##_lock_init(void) { \
102 int i; \
103 LOCKDEP_INIT_MAP(&name##_lock_dep_map, #name, &name##_lock_key, 0); \
104 for_each_possible_cpu(i) { \
105 arch_spinlock_t *lock; \
106 lock = &per_cpu(name##_lock, i); \
107 *lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED; \
108 } \
109 register_hotcpu_notifier(&name##_lg_cpu_notifier); \
110 get_online_cpus(); \
111 for_each_online_cpu(i) \
112 cpu_set(i, name##_cpus); \
113 put_online_cpus(); \
114 } \
115 EXPORT_SYMBOL(name##_lock_init); \
116 \
117 void name##_local_lock(void) { \
118 arch_spinlock_t *lock; \
119 preempt_disable(); \
120 rwlock_acquire_read(&name##_lock_dep_map, 0, 0, _THIS_IP_); \
121 lock = &__get_cpu_var(name##_lock); \
122 arch_spin_lock(lock); \
123 } \
124 EXPORT_SYMBOL(name##_local_lock); \
125 \
126 void name##_local_unlock(void) { \
127 arch_spinlock_t *lock; \
128 rwlock_release(&name##_lock_dep_map, 1, _THIS_IP_); \
129 lock = &__get_cpu_var(name##_lock); \
130 arch_spin_unlock(lock); \
131 preempt_enable(); \
132 } \
133 EXPORT_SYMBOL(name##_local_unlock); \
134 \
135 void name##_local_lock_cpu(int cpu) { \
136 arch_spinlock_t *lock; \
137 preempt_disable(); \
138 rwlock_acquire_read(&name##_lock_dep_map, 0, 0, _THIS_IP_); \
139 lock = &per_cpu(name##_lock, cpu); \
140 arch_spin_lock(lock); \
141 } \
142 EXPORT_SYMBOL(name##_local_lock_cpu); \
143 \
144 void name##_local_unlock_cpu(int cpu) { \
145 arch_spinlock_t *lock; \
146 rwlock_release(&name##_lock_dep_map, 1, _THIS_IP_); \
147 lock = &per_cpu(name##_lock, cpu); \
148 arch_spin_unlock(lock); \
149 preempt_enable(); \
150 } \
151 EXPORT_SYMBOL(name##_local_unlock_cpu); \
152 \
153 void name##_global_lock_online(void) { \
154 int i; \
155 spin_lock(&name##_cpu_lock); \
156 rwlock_acquire(&name##_lock_dep_map, 0, 0, _RET_IP_); \
157 for_each_cpu(i, &name##_cpus) { \
158 arch_spinlock_t *lock; \
159 lock = &per_cpu(name##_lock, i); \
160 arch_spin_lock(lock); \
161 } \
162 } \
163 EXPORT_SYMBOL(name##_global_lock_online); \
164 \
165 void name##_global_unlock_online(void) { \
166 int i; \
167 rwlock_release(&name##_lock_dep_map, 1, _RET_IP_); \
168 for_each_cpu(i, &name##_cpus) { \
169 arch_spinlock_t *lock; \
170 lock = &per_cpu(name##_lock, i); \
171 arch_spin_unlock(lock); \
172 } \
173 spin_unlock(&name##_cpu_lock); \
174 } \
175 EXPORT_SYMBOL(name##_global_unlock_online); \
176 \
177 void name##_global_lock(void) { \
178 int i; \
179 preempt_disable(); \
180 rwlock_acquire(&name##_lock_dep_map, 0, 0, _RET_IP_); \
181 for_each_possible_cpu(i) { \
182 arch_spinlock_t *lock; \
183 lock = &per_cpu(name##_lock, i); \
184 arch_spin_lock(lock); \
185 } \
186 } \
187 EXPORT_SYMBOL(name##_global_lock); \
188 \
189 void name##_global_unlock(void) { \
190 int i; \
191 rwlock_release(&name##_lock_dep_map, 1, _RET_IP_); \
192 for_each_possible_cpu(i) { \
193 arch_spinlock_t *lock; \
194 lock = &per_cpu(name##_lock, i); \
195 arch_spin_unlock(lock); \
196 } \
197 preempt_enable(); \
198 } \
199 EXPORT_SYMBOL(name##_global_unlock);
200#endif 73#endif
diff --git a/include/linux/lockd/bind.h b/include/linux/lockd/bind.h
index 11a966e5f829..4d24d64578c4 100644
--- a/include/linux/lockd/bind.h
+++ b/include/linux/lockd/bind.h
@@ -54,7 +54,7 @@ extern void nlmclnt_done(struct nlm_host *host);
54 54
55extern int nlmclnt_proc(struct nlm_host *host, int cmd, 55extern int nlmclnt_proc(struct nlm_host *host, int cmd,
56 struct file_lock *fl); 56 struct file_lock *fl);
57extern int lockd_up(void); 57extern int lockd_up(struct net *net);
58extern void lockd_down(void); 58extern void lockd_down(struct net *net);
59 59
60#endif /* LINUX_LOCKD_BIND_H */ 60#endif /* LINUX_LOCKD_BIND_H */
diff --git a/include/linux/mm.h b/include/linux/mm.h
index ce26716238c3..b36d08ce5c57 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1392,7 +1392,7 @@ extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned lo
1392extern unsigned long mmap_region(struct file *file, unsigned long addr, 1392extern unsigned long mmap_region(struct file *file, unsigned long addr,
1393 unsigned long len, unsigned long flags, 1393 unsigned long len, unsigned long flags,
1394 vm_flags_t vm_flags, unsigned long pgoff); 1394 vm_flags_t vm_flags, unsigned long pgoff);
1395extern unsigned long do_mmap(struct file *, unsigned long, 1395extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
1396 unsigned long, unsigned long, 1396 unsigned long, unsigned long,
1397 unsigned long, unsigned long); 1397 unsigned long, unsigned long);
1398extern int do_munmap(struct mm_struct *, unsigned long, size_t); 1398extern int do_munmap(struct mm_struct *, unsigned long, size_t);
diff --git a/include/linux/msdos_fs.h b/include/linux/msdos_fs.h
index 34066e65fdeb..11cc2ac67e75 100644
--- a/include/linux/msdos_fs.h
+++ b/include/linux/msdos_fs.h
@@ -21,8 +21,9 @@
21#define CT_LE_W(v) cpu_to_le16(v) 21#define CT_LE_W(v) cpu_to_le16(v)
22#define CT_LE_L(v) cpu_to_le32(v) 22#define CT_LE_L(v) cpu_to_le32(v)
23 23
24#define MSDOS_ROOT_INO 1 /* The root inode number */
25#define MSDOS_FSINFO_INO 2 /* Used for managing the FSINFO block */
24 26
25#define MSDOS_ROOT_INO 1 /* == MINIX_ROOT_INO */
26#define MSDOS_DIR_BITS 5 /* log2(sizeof(struct msdos_dir_entry)) */ 27#define MSDOS_DIR_BITS 5 /* log2(sizeof(struct msdos_dir_entry)) */
27 28
28/* directory limit */ 29/* directory limit */
diff --git a/include/linux/mtd/gpmi-nand.h b/include/linux/mtd/gpmi-nand.h
index 69b6dbf46b5e..ed3c4e09f3d1 100644
--- a/include/linux/mtd/gpmi-nand.h
+++ b/include/linux/mtd/gpmi-nand.h
@@ -23,12 +23,12 @@
23#define GPMI_NAND_RES_SIZE 6 23#define GPMI_NAND_RES_SIZE 6
24 24
25/* Resource names for the GPMI NAND driver. */ 25/* Resource names for the GPMI NAND driver. */
26#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME "GPMI NAND GPMI Registers" 26#define GPMI_NAND_GPMI_REGS_ADDR_RES_NAME "gpmi-nand"
27#define GPMI_NAND_GPMI_INTERRUPT_RES_NAME "GPMI NAND GPMI Interrupt" 27#define GPMI_NAND_GPMI_INTERRUPT_RES_NAME "GPMI NAND GPMI Interrupt"
28#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME "GPMI NAND BCH Registers" 28#define GPMI_NAND_BCH_REGS_ADDR_RES_NAME "bch"
29#define GPMI_NAND_BCH_INTERRUPT_RES_NAME "GPMI NAND BCH Interrupt" 29#define GPMI_NAND_BCH_INTERRUPT_RES_NAME "bch"
30#define GPMI_NAND_DMA_CHANNELS_RES_NAME "GPMI NAND DMA Channels" 30#define GPMI_NAND_DMA_CHANNELS_RES_NAME "GPMI NAND DMA Channels"
31#define GPMI_NAND_DMA_INTERRUPT_RES_NAME "GPMI NAND DMA Interrupt" 31#define GPMI_NAND_DMA_INTERRUPT_RES_NAME "gpmi-dma"
32 32
33/** 33/**
34 * struct gpmi_nand_platform_data - GPMI NAND driver platform data. 34 * struct gpmi_nand_platform_data - GPMI NAND driver platform data.
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index cf5ea8cdcf8e..63dadc0dfb62 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -157,6 +157,15 @@ struct mtd_info {
157 unsigned int erasesize_mask; 157 unsigned int erasesize_mask;
158 unsigned int writesize_mask; 158 unsigned int writesize_mask;
159 159
160 /*
161 * read ops return -EUCLEAN if max number of bitflips corrected on any
162 * one region comprising an ecc step equals or exceeds this value.
163 * Settable by driver, else defaults to ecc_strength. User can override
164 * in sysfs. N.B. The meaning of the -EUCLEAN return code has changed;
165 * see Documentation/ABI/testing/sysfs-class-mtd for more detail.
166 */
167 unsigned int bitflip_threshold;
168
160 // Kernel-only stuff starts here. 169 // Kernel-only stuff starts here.
161 const char *name; 170 const char *name;
162 int index; 171 int index;
@@ -164,7 +173,7 @@ struct mtd_info {
164 /* ECC layout structure pointer - read only! */ 173 /* ECC layout structure pointer - read only! */
165 struct nand_ecclayout *ecclayout; 174 struct nand_ecclayout *ecclayout;
166 175
167 /* max number of correctible bit errors per writesize */ 176 /* max number of correctible bit errors per ecc step */
168 unsigned int ecc_strength; 177 unsigned int ecc_strength;
169 178
170 /* Data for variable erase regions. If numeraseregions is zero, 179 /* Data for variable erase regions. If numeraseregions is zero,
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 1482340d3d9f..57977c640529 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -161,8 +161,6 @@ typedef enum {
161 * Option constants for bizarre disfunctionality and real 161 * Option constants for bizarre disfunctionality and real
162 * features. 162 * features.
163 */ 163 */
164/* Chip can not auto increment pages */
165#define NAND_NO_AUTOINCR 0x00000001
166/* Buswidth is 16 bit */ 164/* Buswidth is 16 bit */
167#define NAND_BUSWIDTH_16 0x00000002 165#define NAND_BUSWIDTH_16 0x00000002
168/* Device supports partial programming without padding */ 166/* Device supports partial programming without padding */
@@ -207,7 +205,6 @@ typedef enum {
207 (NAND_NO_PADDING | NAND_CACHEPRG | NAND_COPYBACK) 205 (NAND_NO_PADDING | NAND_CACHEPRG | NAND_COPYBACK)
208 206
209/* Macros to identify the above */ 207/* Macros to identify the above */
210#define NAND_CANAUTOINCR(chip) (!(chip->options & NAND_NO_AUTOINCR))
211#define NAND_MUST_PAD(chip) (!(chip->options & NAND_NO_PADDING)) 208#define NAND_MUST_PAD(chip) (!(chip->options & NAND_NO_PADDING))
212#define NAND_HAS_CACHEPROG(chip) ((chip->options & NAND_CACHEPRG)) 209#define NAND_HAS_CACHEPROG(chip) ((chip->options & NAND_CACHEPRG))
213#define NAND_HAS_COPYBACK(chip) ((chip->options & NAND_COPYBACK)) 210#define NAND_HAS_COPYBACK(chip) ((chip->options & NAND_COPYBACK))
@@ -216,7 +213,7 @@ typedef enum {
216 && (chip->page_shift > 9)) 213 && (chip->page_shift > 9))
217 214
218/* Mask to zero out the chip options, which come from the id table */ 215/* Mask to zero out the chip options, which come from the id table */
219#define NAND_CHIPOPTIONS_MSK (0x0000ffff & ~NAND_NO_AUTOINCR) 216#define NAND_CHIPOPTIONS_MSK 0x0000ffff
220 217
221/* Non chip related options */ 218/* Non chip related options */
222/* This option skips the bbt scan during initialization. */ 219/* This option skips the bbt scan during initialization. */
@@ -363,21 +360,20 @@ struct nand_ecc_ctrl {
363 int (*correct)(struct mtd_info *mtd, uint8_t *dat, uint8_t *read_ecc, 360 int (*correct)(struct mtd_info *mtd, uint8_t *dat, uint8_t *read_ecc,
364 uint8_t *calc_ecc); 361 uint8_t *calc_ecc);
365 int (*read_page_raw)(struct mtd_info *mtd, struct nand_chip *chip, 362 int (*read_page_raw)(struct mtd_info *mtd, struct nand_chip *chip,
366 uint8_t *buf, int page); 363 uint8_t *buf, int oob_required, int page);
367 void (*write_page_raw)(struct mtd_info *mtd, struct nand_chip *chip, 364 void (*write_page_raw)(struct mtd_info *mtd, struct nand_chip *chip,
368 const uint8_t *buf); 365 const uint8_t *buf, int oob_required);
369 int (*read_page)(struct mtd_info *mtd, struct nand_chip *chip, 366 int (*read_page)(struct mtd_info *mtd, struct nand_chip *chip,
370 uint8_t *buf, int page); 367 uint8_t *buf, int oob_required, int page);
371 int (*read_subpage)(struct mtd_info *mtd, struct nand_chip *chip, 368 int (*read_subpage)(struct mtd_info *mtd, struct nand_chip *chip,
372 uint32_t offs, uint32_t len, uint8_t *buf); 369 uint32_t offs, uint32_t len, uint8_t *buf);
373 void (*write_page)(struct mtd_info *mtd, struct nand_chip *chip, 370 void (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
374 const uint8_t *buf); 371 const uint8_t *buf, int oob_required);
375 int (*write_oob_raw)(struct mtd_info *mtd, struct nand_chip *chip, 372 int (*write_oob_raw)(struct mtd_info *mtd, struct nand_chip *chip,
376 int page); 373 int page);
377 int (*read_oob_raw)(struct mtd_info *mtd, struct nand_chip *chip, 374 int (*read_oob_raw)(struct mtd_info *mtd, struct nand_chip *chip,
378 int page, int sndcmd); 375 int page);
379 int (*read_oob)(struct mtd_info *mtd, struct nand_chip *chip, int page, 376 int (*read_oob)(struct mtd_info *mtd, struct nand_chip *chip, int page);
380 int sndcmd);
381 int (*write_oob)(struct mtd_info *mtd, struct nand_chip *chip, 377 int (*write_oob)(struct mtd_info *mtd, struct nand_chip *chip,
382 int page); 378 int page);
383}; 379};
@@ -459,6 +455,8 @@ struct nand_buffers {
459 * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1 455 * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1
460 * @pagebuf: [INTERN] holds the pagenumber which is currently in 456 * @pagebuf: [INTERN] holds the pagenumber which is currently in
461 * data_buf. 457 * data_buf.
458 * @pagebuf_bitflips: [INTERN] holds the bitflip count for the page which is
459 * currently in data_buf.
462 * @subpagesize: [INTERN] holds the subpagesize 460 * @subpagesize: [INTERN] holds the subpagesize
463 * @onfi_version: [INTERN] holds the chip ONFI version (BCD encoded), 461 * @onfi_version: [INTERN] holds the chip ONFI version (BCD encoded),
464 * non 0 if ONFI supported. 462 * non 0 if ONFI supported.
@@ -505,7 +503,8 @@ struct nand_chip {
505 int (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state, 503 int (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state,
506 int status, int page); 504 int status, int page);
507 int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip, 505 int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
508 const uint8_t *buf, int page, int cached, int raw); 506 const uint8_t *buf, int oob_required, int page,
507 int cached, int raw);
509 508
510 int chip_delay; 509 int chip_delay;
511 unsigned int options; 510 unsigned int options;
@@ -519,6 +518,7 @@ struct nand_chip {
519 uint64_t chipsize; 518 uint64_t chipsize;
520 int pagemask; 519 int pagemask;
521 int pagebuf; 520 int pagebuf;
521 unsigned int pagebuf_bitflips;
522 int subpagesize; 522 int subpagesize;
523 uint8_t cellinfo; 523 uint8_t cellinfo;
524 int badblockpos; 524 int badblockpos;
@@ -654,6 +654,7 @@ struct platform_nand_ctrl {
654 void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl); 654 void (*cmd_ctrl)(struct mtd_info *mtd, int dat, unsigned int ctrl);
655 void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len); 655 void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);
656 void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len); 656 void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len);
657 unsigned char (*read_byte)(struct mtd_info *mtd);
657 void *priv; 658 void *priv;
658}; 659};
659 660
diff --git a/include/linux/nfsd/export.h b/include/linux/nfsd/export.h
index f85308e688fd..e33f747b173c 100644
--- a/include/linux/nfsd/export.h
+++ b/include/linux/nfsd/export.h
@@ -103,6 +103,7 @@ struct svc_export {
103 struct nfsd4_fs_locations ex_fslocs; 103 struct nfsd4_fs_locations ex_fslocs;
104 int ex_nflavors; 104 int ex_nflavors;
105 struct exp_flavor_info ex_flavors[MAX_SECINFO_LIST]; 105 struct exp_flavor_info ex_flavors[MAX_SECINFO_LIST];
106 struct cache_detail *cd;
106}; 107};
107 108
108/* an "export key" (expkey) maps a filehandlefragement to an 109/* an "export key" (expkey) maps a filehandlefragement to an
@@ -129,24 +130,22 @@ __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp);
129/* 130/*
130 * Function declarations 131 * Function declarations
131 */ 132 */
132int nfsd_export_init(void); 133int nfsd_export_init(struct net *);
133void nfsd_export_shutdown(void); 134void nfsd_export_shutdown(struct net *);
134void nfsd_export_flush(void); 135void nfsd_export_flush(struct net *);
135struct svc_export * rqst_exp_get_by_name(struct svc_rqst *, 136struct svc_export * rqst_exp_get_by_name(struct svc_rqst *,
136 struct path *); 137 struct path *);
137struct svc_export * rqst_exp_parent(struct svc_rqst *, 138struct svc_export * rqst_exp_parent(struct svc_rqst *,
138 struct path *); 139 struct path *);
139struct svc_export * rqst_find_fsidzero_export(struct svc_rqst *); 140struct svc_export * rqst_find_fsidzero_export(struct svc_rqst *);
140int exp_rootfh(struct auth_domain *, 141int exp_rootfh(struct net *, struct auth_domain *,
141 char *path, struct knfsd_fh *, int maxsize); 142 char *path, struct knfsd_fh *, int maxsize);
142__be32 exp_pseudoroot(struct svc_rqst *, struct svc_fh *); 143__be32 exp_pseudoroot(struct svc_rqst *, struct svc_fh *);
143__be32 nfserrno(int errno); 144__be32 nfserrno(int errno);
144 145
145extern struct cache_detail svc_export_cache;
146
147static inline void exp_put(struct svc_export *exp) 146static inline void exp_put(struct svc_export *exp)
148{ 147{
149 cache_put(&exp->h, &svc_export_cache); 148 cache_put(&exp->h, exp->cd);
150} 149}
151 150
152static inline void exp_get(struct svc_export *exp) 151static inline void exp_get(struct svc_export *exp)
diff --git a/include/linux/prctl.h b/include/linux/prctl.h
index 78b76e24cc7e..711e0a30aacc 100644
--- a/include/linux/prctl.h
+++ b/include/linux/prctl.h
@@ -113,6 +113,12 @@
113# define PR_SET_MM_START_STACK 5 113# define PR_SET_MM_START_STACK 5
114# define PR_SET_MM_START_BRK 6 114# define PR_SET_MM_START_BRK 6
115# define PR_SET_MM_BRK 7 115# define PR_SET_MM_BRK 7
116# define PR_SET_MM_ARG_START 8
117# define PR_SET_MM_ARG_END 9
118# define PR_SET_MM_ENV_START 10
119# define PR_SET_MM_ENV_END 11
120# define PR_SET_MM_AUXV 12
121# define PR_SET_MM_EXE_FILE 13
116 122
117/* 123/*
118 * Set specific pid that is allowed to ptrace the current task. 124 * Set specific pid that is allowed to ptrace the current task.
diff --git a/include/linux/rio.h b/include/linux/rio.h
index 4d50611112ba..a90ebadd9da0 100644
--- a/include/linux/rio.h
+++ b/include/linux/rio.h
@@ -20,6 +20,9 @@
20#include <linux/errno.h> 20#include <linux/errno.h>
21#include <linux/device.h> 21#include <linux/device.h>
22#include <linux/rio_regs.h> 22#include <linux/rio_regs.h>
23#ifdef CONFIG_RAPIDIO_DMA_ENGINE
24#include <linux/dmaengine.h>
25#endif
23 26
24#define RIO_NO_HOPCOUNT -1 27#define RIO_NO_HOPCOUNT -1
25#define RIO_INVALID_DESTID 0xffff 28#define RIO_INVALID_DESTID 0xffff
@@ -254,6 +257,9 @@ struct rio_mport {
254 u32 phys_efptr; 257 u32 phys_efptr;
255 unsigned char name[40]; 258 unsigned char name[40];
256 void *priv; /* Master port private data */ 259 void *priv; /* Master port private data */
260#ifdef CONFIG_RAPIDIO_DMA_ENGINE
261 struct dma_device dma;
262#endif
257}; 263};
258 264
259/** 265/**
@@ -395,6 +401,47 @@ union rio_pw_msg {
395 u32 raw[RIO_PW_MSG_SIZE/sizeof(u32)]; 401 u32 raw[RIO_PW_MSG_SIZE/sizeof(u32)];
396}; 402};
397 403
404#ifdef CONFIG_RAPIDIO_DMA_ENGINE
405
406/**
407 * enum rio_write_type - RIO write transaction types used in DMA transfers
408 *
409 * Note: RapidIO specification defines write (NWRITE) and
410 * write-with-response (NWRITE_R) data transfer operations.
411 * Existing DMA controllers that service RapidIO may use one of these operations
412 * for entire data transfer or their combination with only the last data packet
413 * requires response.
414 */
415enum rio_write_type {
416 RDW_DEFAULT, /* default method used by DMA driver */
417 RDW_ALL_NWRITE, /* all packets use NWRITE */
418 RDW_ALL_NWRITE_R, /* all packets use NWRITE_R */
419 RDW_LAST_NWRITE_R, /* last packet uses NWRITE_R, others - NWRITE */
420};
421
422struct rio_dma_ext {
423 u16 destid;
424 u64 rio_addr; /* low 64-bits of 66-bit RapidIO address */
425 u8 rio_addr_u; /* upper 2-bits of 66-bit RapidIO address */
426 enum rio_write_type wr_type; /* preferred RIO write operation type */
427};
428
429struct rio_dma_data {
430 /* Local data (as scatterlist) */
431 struct scatterlist *sg; /* I/O scatter list */
432 unsigned int sg_len; /* size of scatter list */
433 /* Remote device address (flat buffer) */
434 u64 rio_addr; /* low 64-bits of 66-bit RapidIO address */
435 u8 rio_addr_u; /* upper 2-bits of 66-bit RapidIO address */
436 enum rio_write_type wr_type; /* preferred RIO write operation type */
437};
438
439static inline struct rio_mport *dma_to_mport(struct dma_device *ddev)
440{
441 return container_of(ddev, struct rio_mport, dma);
442}
443#endif /* CONFIG_RAPIDIO_DMA_ENGINE */
444
398/* Architecture and hardware-specific functions */ 445/* Architecture and hardware-specific functions */
399extern int rio_register_mport(struct rio_mport *); 446extern int rio_register_mport(struct rio_mport *);
400extern int rio_open_inb_mbox(struct rio_mport *, void *, int, int); 447extern int rio_open_inb_mbox(struct rio_mport *, void *, int, int);
diff --git a/include/linux/rio_drv.h b/include/linux/rio_drv.h
index 7f07470e1ed9..31ad146be316 100644
--- a/include/linux/rio_drv.h
+++ b/include/linux/rio_drv.h
@@ -377,6 +377,15 @@ void rio_unregister_driver(struct rio_driver *);
377struct rio_dev *rio_dev_get(struct rio_dev *); 377struct rio_dev *rio_dev_get(struct rio_dev *);
378void rio_dev_put(struct rio_dev *); 378void rio_dev_put(struct rio_dev *);
379 379
380#ifdef CONFIG_RAPIDIO_DMA_ENGINE
381extern struct dma_chan *rio_request_dma(struct rio_dev *rdev);
382extern void rio_release_dma(struct dma_chan *dchan);
383extern struct dma_async_tx_descriptor *rio_dma_prep_slave_sg(
384 struct rio_dev *rdev, struct dma_chan *dchan,
385 struct rio_dma_data *data,
386 enum dma_transfer_direction direction, unsigned long flags);
387#endif
388
380/** 389/**
381 * rio_name - Get the unique RIO device identifier 390 * rio_name - Get the unique RIO device identifier
382 * @rdev: RIO device 391 * @rdev: RIO device
diff --git a/include/linux/sched.h b/include/linux/sched.h
index f45c0b280b5d..f34437e835a7 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1301,11 +1301,6 @@ struct task_struct {
1301 unsigned sched_reset_on_fork:1; 1301 unsigned sched_reset_on_fork:1;
1302 unsigned sched_contributes_to_load:1; 1302 unsigned sched_contributes_to_load:1;
1303 1303
1304#ifdef CONFIG_GENERIC_HARDIRQS
1305 /* IRQ handler threads */
1306 unsigned irq_thread:1;
1307#endif
1308
1309 pid_t pid; 1304 pid_t pid;
1310 pid_t tgid; 1305 pid_t tgid;
1311 1306
@@ -1313,10 +1308,9 @@ struct task_struct {
1313 /* Canary value for the -fstack-protector gcc feature */ 1308 /* Canary value for the -fstack-protector gcc feature */
1314 unsigned long stack_canary; 1309 unsigned long stack_canary;
1315#endif 1310#endif
1316 1311 /*
1317 /*
1318 * pointers to (original) parent process, youngest child, younger sibling, 1312 * pointers to (original) parent process, youngest child, younger sibling,
1319 * older sibling, respectively. (p->father can be replaced with 1313 * older sibling, respectively. (p->father can be replaced with
1320 * p->real_parent->pid) 1314 * p->real_parent->pid)
1321 */ 1315 */
1322 struct task_struct __rcu *real_parent; /* real parent process */ 1316 struct task_struct __rcu *real_parent; /* real parent process */
@@ -1363,8 +1357,6 @@ struct task_struct {
1363 * credentials (COW) */ 1357 * credentials (COW) */
1364 const struct cred __rcu *cred; /* effective (overridable) subjective task 1358 const struct cred __rcu *cred; /* effective (overridable) subjective task
1365 * credentials (COW) */ 1359 * credentials (COW) */
1366 struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
1367
1368 char comm[TASK_COMM_LEN]; /* executable name excluding path 1360 char comm[TASK_COMM_LEN]; /* executable name excluding path
1369 - access with [gs]et_task_comm (which lock 1361 - access with [gs]et_task_comm (which lock
1370 it with task_lock()) 1362 it with task_lock())
@@ -1400,6 +1392,8 @@ struct task_struct {
1400 int (*notifier)(void *priv); 1392 int (*notifier)(void *priv);
1401 void *notifier_data; 1393 void *notifier_data;
1402 sigset_t *notifier_mask; 1394 sigset_t *notifier_mask;
1395 struct hlist_head task_works;
1396
1403 struct audit_context *audit_context; 1397 struct audit_context *audit_context;
1404#ifdef CONFIG_AUDITSYSCALL 1398#ifdef CONFIG_AUDITSYSCALL
1405 uid_t loginuid; 1399 uid_t loginuid;
@@ -2213,6 +2207,20 @@ extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group);
2213extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); 2207extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
2214extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long); 2208extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
2215 2209
2210static inline void restore_saved_sigmask(void)
2211{
2212 if (test_and_clear_restore_sigmask())
2213 __set_current_blocked(&current->saved_sigmask);
2214}
2215
2216static inline sigset_t *sigmask_to_save(void)
2217{
2218 sigset_t *res = &current->blocked;
2219 if (unlikely(test_restore_sigmask()))
2220 res = &current->saved_sigmask;
2221 return res;
2222}
2223
2216static inline int kill_cad_pid(int sig, int priv) 2224static inline int kill_cad_pid(int sig, int priv)
2217{ 2225{
2218 return kill_pid(cad_pid, sig, priv); 2226 return kill_pid(cad_pid, sig, priv);
diff --git a/include/linux/security.h b/include/linux/security.h
index ab0e091ce5fa..4e5a73cdbbef 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -86,9 +86,9 @@ extern int cap_inode_setxattr(struct dentry *dentry, const char *name,
86extern int cap_inode_removexattr(struct dentry *dentry, const char *name); 86extern int cap_inode_removexattr(struct dentry *dentry, const char *name);
87extern int cap_inode_need_killpriv(struct dentry *dentry); 87extern int cap_inode_need_killpriv(struct dentry *dentry);
88extern int cap_inode_killpriv(struct dentry *dentry); 88extern int cap_inode_killpriv(struct dentry *dentry);
89extern int cap_file_mmap(struct file *file, unsigned long reqprot, 89extern int cap_mmap_addr(unsigned long addr);
90 unsigned long prot, unsigned long flags, 90extern int cap_mmap_file(struct file *file, unsigned long reqprot,
91 unsigned long addr, unsigned long addr_only); 91 unsigned long prot, unsigned long flags);
92extern int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags); 92extern int cap_task_fix_setuid(struct cred *new, const struct cred *old, int flags);
93extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3, 93extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
94 unsigned long arg4, unsigned long arg5); 94 unsigned long arg4, unsigned long arg5);
@@ -586,15 +586,17 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
586 * simple integer value. When @arg represents a user space pointer, it 586 * simple integer value. When @arg represents a user space pointer, it
587 * should never be used by the security module. 587 * should never be used by the security module.
588 * Return 0 if permission is granted. 588 * Return 0 if permission is granted.
589 * @file_mmap : 589 * @mmap_addr :
590 * Check permissions for a mmap operation at @addr.
591 * @addr contains virtual address that will be used for the operation.
592 * Return 0 if permission is granted.
593 * @mmap_file :
590 * Check permissions for a mmap operation. The @file may be NULL, e.g. 594 * Check permissions for a mmap operation. The @file may be NULL, e.g.
591 * if mapping anonymous memory. 595 * if mapping anonymous memory.
592 * @file contains the file structure for file to map (may be NULL). 596 * @file contains the file structure for file to map (may be NULL).
593 * @reqprot contains the protection requested by the application. 597 * @reqprot contains the protection requested by the application.
594 * @prot contains the protection that will be applied by the kernel. 598 * @prot contains the protection that will be applied by the kernel.
595 * @flags contains the operational flags. 599 * @flags contains the operational flags.
596 * @addr contains virtual address that will be used for the operation.
597 * @addr_only contains a boolean: 0 if file-backed VMA, otherwise 1.
598 * Return 0 if permission is granted. 600 * Return 0 if permission is granted.
599 * @file_mprotect: 601 * @file_mprotect:
600 * Check permissions before changing memory access permissions. 602 * Check permissions before changing memory access permissions.
@@ -1481,10 +1483,10 @@ struct security_operations {
1481 void (*file_free_security) (struct file *file); 1483 void (*file_free_security) (struct file *file);
1482 int (*file_ioctl) (struct file *file, unsigned int cmd, 1484 int (*file_ioctl) (struct file *file, unsigned int cmd,
1483 unsigned long arg); 1485 unsigned long arg);
1484 int (*file_mmap) (struct file *file, 1486 int (*mmap_addr) (unsigned long addr);
1487 int (*mmap_file) (struct file *file,
1485 unsigned long reqprot, unsigned long prot, 1488 unsigned long reqprot, unsigned long prot,
1486 unsigned long flags, unsigned long addr, 1489 unsigned long flags);
1487 unsigned long addr_only);
1488 int (*file_mprotect) (struct vm_area_struct *vma, 1490 int (*file_mprotect) (struct vm_area_struct *vma,
1489 unsigned long reqprot, 1491 unsigned long reqprot,
1490 unsigned long prot); 1492 unsigned long prot);
@@ -1743,9 +1745,9 @@ int security_file_permission(struct file *file, int mask);
1743int security_file_alloc(struct file *file); 1745int security_file_alloc(struct file *file);
1744void security_file_free(struct file *file); 1746void security_file_free(struct file *file);
1745int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 1747int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1746int security_file_mmap(struct file *file, unsigned long reqprot, 1748int security_mmap_file(struct file *file, unsigned long prot,
1747 unsigned long prot, unsigned long flags, 1749 unsigned long flags);
1748 unsigned long addr, unsigned long addr_only); 1750int security_mmap_addr(unsigned long addr);
1749int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, 1751int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
1750 unsigned long prot); 1752 unsigned long prot);
1751int security_file_lock(struct file *file, unsigned int cmd); 1753int security_file_lock(struct file *file, unsigned int cmd);
@@ -2181,13 +2183,15 @@ static inline int security_file_ioctl(struct file *file, unsigned int cmd,
2181 return 0; 2183 return 0;
2182} 2184}
2183 2185
2184static inline int security_file_mmap(struct file *file, unsigned long reqprot, 2186static inline int security_mmap_file(struct file *file, unsigned long prot,
2185 unsigned long prot, 2187 unsigned long flags)
2186 unsigned long flags, 2188{
2187 unsigned long addr, 2189 return 0;
2188 unsigned long addr_only) 2190}
2191
2192static inline int security_mmap_addr(unsigned long addr)
2189{ 2193{
2190 return cap_file_mmap(file, reqprot, prot, flags, addr, addr_only); 2194 return cap_mmap_addr(addr);
2191} 2195}
2192 2196
2193static inline int security_file_mprotect(struct vm_area_struct *vma, 2197static inline int security_file_mprotect(struct vm_area_struct *vma,
diff --git a/include/linux/signal.h b/include/linux/signal.h
index 17046cc484bc..26b424adc842 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -250,12 +250,13 @@ extern long do_sigpending(void __user *, unsigned long);
250extern int do_sigtimedwait(const sigset_t *, siginfo_t *, 250extern int do_sigtimedwait(const sigset_t *, siginfo_t *,
251 const struct timespec *); 251 const struct timespec *);
252extern int sigprocmask(int, sigset_t *, sigset_t *); 252extern int sigprocmask(int, sigset_t *, sigset_t *);
253extern void set_current_blocked(const sigset_t *); 253extern void set_current_blocked(sigset_t *);
254extern void __set_current_blocked(const sigset_t *);
254extern int show_unhandled_signals; 255extern int show_unhandled_signals;
255extern int sigsuspend(sigset_t *); 256extern int sigsuspend(sigset_t *);
256 257
257extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie); 258extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
258extern void block_sigmask(struct k_sigaction *ka, int signr); 259extern void signal_delivered(int sig, siginfo_t *info, struct k_sigaction *ka, struct pt_regs *regs, int stepping);
259extern void exit_signals(struct task_struct *tsk); 260extern void exit_signals(struct task_struct *tsk);
260 261
261extern struct kmem_cache *sighand_cachep; 262extern struct kmem_cache *sighand_cachep;
diff --git a/include/linux/slab.h b/include/linux/slab.h
index a595dce6b0c7..67d5d94b783a 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -242,7 +242,7 @@ size_t ksize(const void *);
242 */ 242 */
243static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) 243static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
244{ 244{
245 if (size != 0 && n > ULONG_MAX / size) 245 if (size != 0 && n > SIZE_MAX / size)
246 return NULL; 246 return NULL;
247 return __kmalloc(n * size, flags); 247 return __kmalloc(n * size, flags);
248} 248}
diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
index 51b29ac45a8e..40e0a273faea 100644
--- a/include/linux/sunrpc/svc.h
+++ b/include/linux/sunrpc/svc.h
@@ -232,7 +232,6 @@ struct svc_rqst {
232 struct svc_pool * rq_pool; /* thread pool */ 232 struct svc_pool * rq_pool; /* thread pool */
233 struct svc_procedure * rq_procinfo; /* procedure info */ 233 struct svc_procedure * rq_procinfo; /* procedure info */
234 struct auth_ops * rq_authop; /* authentication flavour */ 234 struct auth_ops * rq_authop; /* authentication flavour */
235 u32 rq_flavor; /* pseudoflavor */
236 struct svc_cred rq_cred; /* auth info */ 235 struct svc_cred rq_cred; /* auth info */
237 void * rq_xprt_ctxt; /* transport specific context ptr */ 236 void * rq_xprt_ctxt; /* transport specific context ptr */
238 struct svc_deferred_req*rq_deferred; /* deferred request we are replaying */ 237 struct svc_deferred_req*rq_deferred; /* deferred request we are replaying */
@@ -416,6 +415,7 @@ struct svc_procedure {
416 */ 415 */
417int svc_rpcb_setup(struct svc_serv *serv, struct net *net); 416int svc_rpcb_setup(struct svc_serv *serv, struct net *net);
418void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net); 417void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net);
418int svc_bind(struct svc_serv *serv, struct net *net);
419struct svc_serv *svc_create(struct svc_program *, unsigned int, 419struct svc_serv *svc_create(struct svc_program *, unsigned int,
420 void (*shutdown)(struct svc_serv *, struct net *net)); 420 void (*shutdown)(struct svc_serv *, struct net *net));
421struct svc_rqst *svc_prepare_thread(struct svc_serv *serv, 421struct svc_rqst *svc_prepare_thread(struct svc_serv *serv,
diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
index 548790e9113b..dd74084a9799 100644
--- a/include/linux/sunrpc/svcauth.h
+++ b/include/linux/sunrpc/svcauth.h
@@ -15,14 +15,23 @@
15#include <linux/sunrpc/msg_prot.h> 15#include <linux/sunrpc/msg_prot.h>
16#include <linux/sunrpc/cache.h> 16#include <linux/sunrpc/cache.h>
17#include <linux/hash.h> 17#include <linux/hash.h>
18#include <linux/cred.h>
18 19
19#define SVC_CRED_NGROUPS 32
20struct svc_cred { 20struct svc_cred {
21 uid_t cr_uid; 21 uid_t cr_uid;
22 gid_t cr_gid; 22 gid_t cr_gid;
23 struct group_info *cr_group_info; 23 struct group_info *cr_group_info;
24 u32 cr_flavor; /* pseudoflavor */
25 char *cr_principal; /* for gss */
24}; 26};
25 27
28static inline void free_svc_cred(struct svc_cred *cred)
29{
30 if (cred->cr_group_info)
31 put_group_info(cred->cr_group_info);
32 kfree(cred->cr_principal);
33}
34
26struct svc_rqst; /* forward decl */ 35struct svc_rqst; /* forward decl */
27struct in6_addr; 36struct in6_addr;
28 37
@@ -131,7 +140,7 @@ extern struct auth_domain *auth_domain_lookup(char *name, struct auth_domain *ne
131extern struct auth_domain *auth_domain_find(char *name); 140extern struct auth_domain *auth_domain_find(char *name);
132extern struct auth_domain *auth_unix_lookup(struct net *net, struct in6_addr *addr); 141extern struct auth_domain *auth_unix_lookup(struct net *net, struct in6_addr *addr);
133extern int auth_unix_forget_old(struct auth_domain *dom); 142extern int auth_unix_forget_old(struct auth_domain *dom);
134extern void svcauth_unix_purge(void); 143extern void svcauth_unix_purge(struct net *net);
135extern void svcauth_unix_info_release(struct svc_xprt *xpt); 144extern void svcauth_unix_info_release(struct svc_xprt *xpt);
136extern int svcauth_unix_set_client(struct svc_rqst *rqstp); 145extern int svcauth_unix_set_client(struct svc_rqst *rqstp);
137 146
diff --git a/include/linux/sunrpc/svcauth_gss.h b/include/linux/sunrpc/svcauth_gss.h
index 7c32daa025eb..726aff1a5201 100644
--- a/include/linux/sunrpc/svcauth_gss.h
+++ b/include/linux/sunrpc/svcauth_gss.h
@@ -22,7 +22,6 @@ int gss_svc_init_net(struct net *net);
22void gss_svc_shutdown_net(struct net *net); 22void gss_svc_shutdown_net(struct net *net);
23int svcauth_gss_register_pseudoflavor(u32 pseudoflavor, char * name); 23int svcauth_gss_register_pseudoflavor(u32 pseudoflavor, char * name);
24u32 svcauth_gss_flavor(struct auth_domain *dom); 24u32 svcauth_gss_flavor(struct auth_domain *dom);
25char *svc_gss_principal(struct svc_rqst *);
26 25
27#endif /* __KERNEL__ */ 26#endif /* __KERNEL__ */
28#endif /* _LINUX_SUNRPC_SVCAUTH_GSS_H */ 27#endif /* _LINUX_SUNRPC_SVCAUTH_GSS_H */
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 3de3acb84a95..19439c75c5b2 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -858,4 +858,6 @@ asmlinkage long sys_process_vm_writev(pid_t pid,
858 unsigned long riovcnt, 858 unsigned long riovcnt,
859 unsigned long flags); 859 unsigned long flags);
860 860
861asmlinkage long sys_kcmp(pid_t pid1, pid_t pid2, int type,
862 unsigned long idx1, unsigned long idx2);
861#endif 863#endif
diff --git a/include/linux/task_work.h b/include/linux/task_work.h
new file mode 100644
index 000000000000..294d5d5e90b1
--- /dev/null
+++ b/include/linux/task_work.h
@@ -0,0 +1,33 @@
1#ifndef _LINUX_TASK_WORK_H
2#define _LINUX_TASK_WORK_H
3
4#include <linux/list.h>
5#include <linux/sched.h>
6
7struct task_work;
8typedef void (*task_work_func_t)(struct task_work *);
9
10struct task_work {
11 struct hlist_node hlist;
12 task_work_func_t func;
13 void *data;
14};
15
16static inline void
17init_task_work(struct task_work *twork, task_work_func_t func, void *data)
18{
19 twork->func = func;
20 twork->data = data;
21}
22
23int task_work_add(struct task_struct *task, struct task_work *twork, bool);
24struct task_work *task_work_cancel(struct task_struct *, task_work_func_t);
25void task_work_run(void);
26
27static inline void exit_task_work(struct task_struct *task)
28{
29 if (unlikely(!hlist_empty(&task->task_works)))
30 task_work_run();
31}
32
33#endif /* _LINUX_TASK_WORK_H */
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index db78775eff3b..ccc1899bd62e 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -8,6 +8,7 @@
8#define _LINUX_THREAD_INFO_H 8#define _LINUX_THREAD_INFO_H
9 9
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/bug.h>
11 12
12struct timespec; 13struct timespec;
13struct compat_timespec; 14struct compat_timespec;
@@ -125,10 +126,26 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
125static inline void set_restore_sigmask(void) 126static inline void set_restore_sigmask(void)
126{ 127{
127 set_thread_flag(TIF_RESTORE_SIGMASK); 128 set_thread_flag(TIF_RESTORE_SIGMASK);
128 set_thread_flag(TIF_SIGPENDING); 129 WARN_ON(!test_thread_flag(TIF_SIGPENDING));
130}
131static inline void clear_restore_sigmask(void)
132{
133 clear_thread_flag(TIF_RESTORE_SIGMASK);
134}
135static inline bool test_restore_sigmask(void)
136{
137 return test_thread_flag(TIF_RESTORE_SIGMASK);
138}
139static inline bool test_and_clear_restore_sigmask(void)
140{
141 return test_and_clear_thread_flag(TIF_RESTORE_SIGMASK);
129} 142}
130#endif /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */ 143#endif /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
131 144
145#ifndef HAVE_SET_RESTORE_SIGMASK
146#error "no set_restore_sigmask() provided and default one won't work"
147#endif
148
132#endif /* __KERNEL__ */ 149#endif /* __KERNEL__ */
133 150
134#endif /* _LINUX_THREAD_INFO_H */ 151#endif /* _LINUX_THREAD_INFO_H */
diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
index 51bd91d911c3..6a4d82bedb03 100644
--- a/include/linux/tracehook.h
+++ b/include/linux/tracehook.h
@@ -49,6 +49,7 @@
49#include <linux/sched.h> 49#include <linux/sched.h>
50#include <linux/ptrace.h> 50#include <linux/ptrace.h>
51#include <linux/security.h> 51#include <linux/security.h>
52#include <linux/task_work.h>
52struct linux_binprm; 53struct linux_binprm;
53 54
54/* 55/*
@@ -153,7 +154,6 @@ static inline void tracehook_signal_handler(int sig, siginfo_t *info,
153 ptrace_notify(SIGTRAP); 154 ptrace_notify(SIGTRAP);
154} 155}
155 156
156#ifdef TIF_NOTIFY_RESUME
157/** 157/**
158 * set_notify_resume - cause tracehook_notify_resume() to be called 158 * set_notify_resume - cause tracehook_notify_resume() to be called
159 * @task: task that will call tracehook_notify_resume() 159 * @task: task that will call tracehook_notify_resume()
@@ -165,8 +165,10 @@ static inline void tracehook_signal_handler(int sig, siginfo_t *info,
165 */ 165 */
166static inline void set_notify_resume(struct task_struct *task) 166static inline void set_notify_resume(struct task_struct *task)
167{ 167{
168#ifdef TIF_NOTIFY_RESUME
168 if (!test_and_set_tsk_thread_flag(task, TIF_NOTIFY_RESUME)) 169 if (!test_and_set_tsk_thread_flag(task, TIF_NOTIFY_RESUME))
169 kick_process(task); 170 kick_process(task);
171#endif
170} 172}
171 173
172/** 174/**
@@ -184,7 +186,14 @@ static inline void set_notify_resume(struct task_struct *task)
184 */ 186 */
185static inline void tracehook_notify_resume(struct pt_regs *regs) 187static inline void tracehook_notify_resume(struct pt_regs *regs)
186{ 188{
189 /*
190 * The caller just cleared TIF_NOTIFY_RESUME. This barrier
191 * pairs with task_work_add()->set_notify_resume() after
192 * hlist_add_head(task->task_works);
193 */
194 smp_mb__after_clear_bit();
195 if (unlikely(!hlist_empty(&current->task_works)))
196 task_work_run();
187} 197}
188#endif /* TIF_NOTIFY_RESUME */
189 198
190#endif /* <linux/tracehook.h> */ 199#endif /* <linux/tracehook.h> */
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 4990ef2b1fb7..9f47ab540f65 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -268,7 +268,6 @@ struct tty_struct {
268 struct mutex ldisc_mutex; 268 struct mutex ldisc_mutex;
269 struct tty_ldisc *ldisc; 269 struct tty_ldisc *ldisc;
270 270
271 struct mutex legacy_mutex;
272 struct mutex termios_mutex; 271 struct mutex termios_mutex;
273 spinlock_t ctrl_lock; 272 spinlock_t ctrl_lock;
274 /* Termios values are protected by the termios mutex */ 273 /* Termios values are protected by the termios mutex */
@@ -606,12 +605,8 @@ extern long vt_compat_ioctl(struct tty_struct *tty,
606 605
607/* tty_mutex.c */ 606/* tty_mutex.c */
608/* functions for preparation of BKL removal */ 607/* functions for preparation of BKL removal */
609extern void __lockfunc tty_lock(struct tty_struct *tty); 608extern void __lockfunc tty_lock(void) __acquires(tty_lock);
610extern void __lockfunc tty_unlock(struct tty_struct *tty); 609extern void __lockfunc tty_unlock(void) __releases(tty_lock);
611extern void __lockfunc tty_lock_pair(struct tty_struct *tty,
612 struct tty_struct *tty2);
613extern void __lockfunc tty_unlock_pair(struct tty_struct *tty,
614 struct tty_struct *tty2);
615 610
616/* 611/*
617 * this shall be called only from where BTM is held (like close) 612 * this shall be called only from where BTM is held (like close)
@@ -626,9 +621,9 @@ extern void __lockfunc tty_unlock_pair(struct tty_struct *tty,
626static inline void tty_wait_until_sent_from_close(struct tty_struct *tty, 621static inline void tty_wait_until_sent_from_close(struct tty_struct *tty,
627 long timeout) 622 long timeout)
628{ 623{
629 tty_unlock(tty); /* tty->ops->close holds the BTM, drop it while waiting */ 624 tty_unlock(); /* tty->ops->close holds the BTM, drop it while waiting */
630 tty_wait_until_sent(tty, timeout); 625 tty_wait_until_sent(tty, timeout);
631 tty_lock(tty); 626 tty_lock();
632} 627}
633 628
634/* 629/*
@@ -643,16 +638,16 @@ static inline void tty_wait_until_sent_from_close(struct tty_struct *tty,
643 * 638 *
644 * Do not use in new code. 639 * Do not use in new code.
645 */ 640 */
646#define wait_event_interruptible_tty(tty, wq, condition) \ 641#define wait_event_interruptible_tty(wq, condition) \
647({ \ 642({ \
648 int __ret = 0; \ 643 int __ret = 0; \
649 if (!(condition)) { \ 644 if (!(condition)) { \
650 __wait_event_interruptible_tty(tty, wq, condition, __ret); \ 645 __wait_event_interruptible_tty(wq, condition, __ret); \
651 } \ 646 } \
652 __ret; \ 647 __ret; \
653}) 648})
654 649
655#define __wait_event_interruptible_tty(tty, wq, condition, ret) \ 650#define __wait_event_interruptible_tty(wq, condition, ret) \
656do { \ 651do { \
657 DEFINE_WAIT(__wait); \ 652 DEFINE_WAIT(__wait); \
658 \ 653 \
@@ -661,9 +656,9 @@ do { \
661 if (condition) \ 656 if (condition) \
662 break; \ 657 break; \
663 if (!signal_pending(current)) { \ 658 if (!signal_pending(current)) { \
664 tty_unlock(tty); \ 659 tty_unlock(); \
665 schedule(); \ 660 schedule(); \
666 tty_lock(tty); \ 661 tty_lock(); \
667 continue; \ 662 continue; \
668 } \ 663 } \
669 ret = -ERESTARTSYS; \ 664 ret = -ERESTARTSYS; \
diff --git a/include/linux/types.h b/include/linux/types.h
index 7f480db60231..9c1bd539ea70 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -25,7 +25,7 @@ typedef __kernel_dev_t dev_t;
25typedef __kernel_ino_t ino_t; 25typedef __kernel_ino_t ino_t;
26typedef __kernel_mode_t mode_t; 26typedef __kernel_mode_t mode_t;
27typedef unsigned short umode_t; 27typedef unsigned short umode_t;
28typedef __kernel_nlink_t nlink_t; 28typedef __u32 nlink_t;
29typedef __kernel_off_t off_t; 29typedef __kernel_off_t off_t;
30typedef __kernel_pid_t pid_t; 30typedef __kernel_pid_t pid_t;
31typedef __kernel_daddr_t daddr_t; 31typedef __kernel_daddr_t daddr_t;
diff --git a/include/video/auo_k190xfb.h b/include/video/auo_k190xfb.h
new file mode 100644
index 000000000000..609efe8c686e
--- /dev/null
+++ b/include/video/auo_k190xfb.h
@@ -0,0 +1,106 @@
1/*
2 * Definitions for AUO-K190X framebuffer drivers
3 *
4 * Copyright (C) 2012 Heiko Stuebner <heiko@sntech.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef _LINUX_VIDEO_AUO_K190XFB_H_
12#define _LINUX_VIDEO_AUO_K190XFB_H_
13
14/* Controller standby command needs a param */
15#define AUOK190X_QUIRK_STANDBYPARAM (1 << 0)
16
17/* Controller standby is completely broken */
18#define AUOK190X_QUIRK_STANDBYBROKEN (1 << 1)
19
20/*
21 * Resolutions for the displays
22 */
23#define AUOK190X_RESOLUTION_800_600 0
24#define AUOK190X_RESOLUTION_1024_768 1
25
26/*
27 * struct used by auok190x. board specific stuff comes from *board
28 */
29struct auok190xfb_par {
30 struct fb_info *info;
31 struct auok190x_board *board;
32
33 struct regulator *regulator;
34
35 struct mutex io_lock;
36 struct delayed_work work;
37 wait_queue_head_t waitq;
38 int resolution;
39 int rotation;
40 int consecutive_threshold;
41 int update_cnt;
42
43 /* panel and controller informations */
44 int epd_type;
45 int panel_size_int;
46 int panel_size_float;
47 int panel_model;
48 int tcon_version;
49 int lut_version;
50
51 /* individual controller callbacks */
52 void (*update_partial)(struct auok190xfb_par *par, u16 y1, u16 y2);
53 void (*update_all)(struct auok190xfb_par *par);
54 bool (*need_refresh)(struct auok190xfb_par *par);
55 void (*init)(struct auok190xfb_par *par);
56 void (*recover)(struct auok190xfb_par *par);
57
58 int update_mode; /* mode to use for updates */
59 int last_mode; /* update mode last used */
60 int flash;
61
62 /* power management */
63 int autosuspend_delay;
64 bool standby;
65 bool manual_standby;
66};
67
68/**
69 * Board specific platform-data
70 * @init: initialize the controller interface
71 * @cleanup: cleanup the controller interface
72 * @wait_for_rdy: wait until the controller is not busy anymore
73 * @set_ctl: change an interface control
74 * @set_hdb: write a value to the data register
75 * @get_hdb: read a value from the data register
76 * @setup_irq: method to setup the irq handling on the busy gpio
77 * @gpio_nsleep: sleep gpio
78 * @gpio_nrst: reset gpio
79 * @gpio_nbusy: busy gpio
80 * @resolution: one of the AUOK190X_RESOLUTION constants
81 * @rotation: rotation of the framebuffer
82 * @quirks: controller quirks to honor
83 * @fps: frames per second for defio
84 */
85struct auok190x_board {
86 int (*init)(struct auok190xfb_par *);
87 void (*cleanup)(struct auok190xfb_par *);
88 int (*wait_for_rdy)(struct auok190xfb_par *);
89
90 void (*set_ctl)(struct auok190xfb_par *, unsigned char, u8);
91 void (*set_hdb)(struct auok190xfb_par *, u16);
92 u16 (*get_hdb)(struct auok190xfb_par *);
93
94 int (*setup_irq)(struct fb_info *);
95
96 int gpio_nsleep;
97 int gpio_nrst;
98 int gpio_nbusy;
99
100 int resolution;
101 int rotation;
102 int quirks;
103 int fps;
104};
105
106#endif
diff --git a/include/video/exynos_dp.h b/include/video/exynos_dp.h
index 8847a9d6dd42..bd8cabd344db 100644
--- a/include/video/exynos_dp.h
+++ b/include/video/exynos_dp.h
@@ -14,7 +14,7 @@
14 14
15#define DP_TIMEOUT_LOOP_COUNT 100 15#define DP_TIMEOUT_LOOP_COUNT 100
16#define MAX_CR_LOOP 5 16#define MAX_CR_LOOP 5
17#define MAX_EQ_LOOP 4 17#define MAX_EQ_LOOP 5
18 18
19enum link_rate_type { 19enum link_rate_type {
20 LINK_RATE_1_62GBPS = 0x06, 20 LINK_RATE_1_62GBPS = 0x06,
diff --git a/include/video/exynos_mipi_dsim.h b/include/video/exynos_mipi_dsim.h
index 772c770535f1..83ce5e667d47 100644
--- a/include/video/exynos_mipi_dsim.h
+++ b/include/video/exynos_mipi_dsim.h
@@ -315,6 +315,7 @@ struct mipi_dsim_lcd_device {
315 int id; 315 int id;
316 int bus_id; 316 int bus_id;
317 int irq; 317 int irq;
318 int panel_reverse;
318 319
319 struct mipi_dsim_device *master; 320 struct mipi_dsim_device *master;
320 void *platform_data; 321 void *platform_data;
diff --git a/include/video/omapdss.h b/include/video/omapdss.h
index 1c46a14341dd..c8e59b4a3364 100644
--- a/include/video/omapdss.h
+++ b/include/video/omapdss.h
@@ -51,6 +51,8 @@
51 51
52struct omap_dss_device; 52struct omap_dss_device;
53struct omap_overlay_manager; 53struct omap_overlay_manager;
54struct snd_aes_iec958;
55struct snd_cea_861_aud_if;
54 56
55enum omap_display_type { 57enum omap_display_type {
56 OMAP_DISPLAY_TYPE_NONE = 0, 58 OMAP_DISPLAY_TYPE_NONE = 0,
@@ -158,6 +160,13 @@ enum omap_dss_display_state {
158 OMAP_DSS_DISPLAY_SUSPENDED, 160 OMAP_DSS_DISPLAY_SUSPENDED,
159}; 161};
160 162
163enum omap_dss_audio_state {
164 OMAP_DSS_AUDIO_DISABLED = 0,
165 OMAP_DSS_AUDIO_ENABLED,
166 OMAP_DSS_AUDIO_CONFIGURED,
167 OMAP_DSS_AUDIO_PLAYING,
168};
169
161/* XXX perhaps this should be removed */ 170/* XXX perhaps this should be removed */
162enum omap_dss_overlay_managers { 171enum omap_dss_overlay_managers {
163 OMAP_DSS_OVL_MGR_LCD, 172 OMAP_DSS_OVL_MGR_LCD,
@@ -166,8 +175,9 @@ enum omap_dss_overlay_managers {
166}; 175};
167 176
168enum omap_dss_rotation_type { 177enum omap_dss_rotation_type {
169 OMAP_DSS_ROT_DMA = 0, 178 OMAP_DSS_ROT_DMA = 1 << 0,
170 OMAP_DSS_ROT_VRFB = 1, 179 OMAP_DSS_ROT_VRFB = 1 << 1,
180 OMAP_DSS_ROT_TILER = 1 << 2,
171}; 181};
172 182
173/* clockwise rotation angle */ 183/* clockwise rotation angle */
@@ -309,6 +319,7 @@ struct omap_dss_board_info {
309 struct omap_dss_device *default_device; 319 struct omap_dss_device *default_device;
310 int (*dsi_enable_pads)(int dsi_id, unsigned lane_mask); 320 int (*dsi_enable_pads)(int dsi_id, unsigned lane_mask);
311 void (*dsi_disable_pads)(int dsi_id, unsigned lane_mask); 321 void (*dsi_disable_pads)(int dsi_id, unsigned lane_mask);
322 int (*set_min_bus_tput)(struct device *dev, unsigned long r);
312}; 323};
313 324
314/* Init with the board info */ 325/* Init with the board info */
@@ -316,11 +327,6 @@ extern int omap_display_init(struct omap_dss_board_info *board_data);
316/* HDMI mux init*/ 327/* HDMI mux init*/
317extern int omap_hdmi_init(enum omap_hdmi_flags flags); 328extern int omap_hdmi_init(enum omap_hdmi_flags flags);
318 329
319struct omap_display_platform_data {
320 struct omap_dss_board_info *board_data;
321 /* TODO: Additional members to be added when PM is considered */
322};
323
324struct omap_video_timings { 330struct omap_video_timings {
325 /* Unit: pixels */ 331 /* Unit: pixels */
326 u16 x_res; 332 u16 x_res;
@@ -587,6 +593,8 @@ struct omap_dss_device {
587 593
588 enum omap_dss_display_state state; 594 enum omap_dss_display_state state;
589 595
596 enum omap_dss_audio_state audio_state;
597
590 /* platform specific */ 598 /* platform specific */
591 int (*platform_enable)(struct omap_dss_device *dssdev); 599 int (*platform_enable)(struct omap_dss_device *dssdev);
592 void (*platform_disable)(struct omap_dss_device *dssdev); 600 void (*platform_disable)(struct omap_dss_device *dssdev);
@@ -599,6 +607,11 @@ struct omap_dss_hdmi_data
599 int hpd_gpio; 607 int hpd_gpio;
600}; 608};
601 609
610struct omap_dss_audio {
611 struct snd_aes_iec958 *iec;
612 struct snd_cea_861_aud_if *cea;
613};
614
602struct omap_dss_driver { 615struct omap_dss_driver {
603 struct device_driver driver; 616 struct device_driver driver;
604 617
@@ -646,6 +659,24 @@ struct omap_dss_driver {
646 659
647 int (*read_edid)(struct omap_dss_device *dssdev, u8 *buf, int len); 660 int (*read_edid)(struct omap_dss_device *dssdev, u8 *buf, int len);
648 bool (*detect)(struct omap_dss_device *dssdev); 661 bool (*detect)(struct omap_dss_device *dssdev);
662
663 /*
664 * For display drivers that support audio. This encompasses
665 * HDMI and DisplayPort at the moment.
666 */
667 /*
668 * Note: These functions might sleep. Do not call while
669 * holding a spinlock/readlock.
670 */
671 int (*audio_enable)(struct omap_dss_device *dssdev);
672 void (*audio_disable)(struct omap_dss_device *dssdev);
673 bool (*audio_supported)(struct omap_dss_device *dssdev);
674 int (*audio_config)(struct omap_dss_device *dssdev,
675 struct omap_dss_audio *audio);
676 /* Note: These functions may not sleep */
677 int (*audio_start)(struct omap_dss_device *dssdev);
678 void (*audio_stop)(struct omap_dss_device *dssdev);
679
649}; 680};
650 681
651int omap_dss_register_driver(struct omap_dss_driver *); 682int omap_dss_register_driver(struct omap_dss_driver *);
@@ -670,6 +701,8 @@ struct omap_overlay *omap_dss_get_overlay(int num);
670void omapdss_default_get_resolution(struct omap_dss_device *dssdev, 701void omapdss_default_get_resolution(struct omap_dss_device *dssdev,
671 u16 *xres, u16 *yres); 702 u16 *xres, u16 *yres);
672int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev); 703int omapdss_default_get_recommended_bpp(struct omap_dss_device *dssdev);
704void omapdss_default_get_timings(struct omap_dss_device *dssdev,
705 struct omap_video_timings *timings);
673 706
674typedef void (*omap_dispc_isr_t) (void *arg, u32 mask); 707typedef void (*omap_dispc_isr_t) (void *arg, u32 mask);
675int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask); 708int omap_dispc_register_isr(omap_dispc_isr_t isr, void *arg, u32 mask);
diff --git a/include/video/sh_mobile_hdmi.h b/include/video/sh_mobile_hdmi.h
index 728f9de9c258..63d20efa254a 100644
--- a/include/video/sh_mobile_hdmi.h
+++ b/include/video/sh_mobile_hdmi.h
@@ -18,9 +18,11 @@ struct clk;
18/* 18/*
19 * flags format 19 * flags format
20 * 20 *
21 * 0x0000000A 21 * 0x00000CBA
22 * 22 *
23 * A: Audio source select 23 * A: Audio source select
24 * B: Int output option
25 * C: Chip specific option
24 */ 26 */
25 27
26/* Audio source select */ 28/* Audio source select */
@@ -30,6 +32,14 @@ struct clk;
30#define HDMI_SND_SRC_DSD (2 << 0) 32#define HDMI_SND_SRC_DSD (2 << 0)
31#define HDMI_SND_SRC_HBR (3 << 0) 33#define HDMI_SND_SRC_HBR (3 << 0)
32 34
35/* Int output option */
36#define HDMI_OUTPUT_PUSH_PULL (1 << 4) /* System control : output mode */
37#define HDMI_OUTPUT_POLARITY_HI (1 << 5) /* System control : output polarity */
38
39/* Chip specific option */
40#define HDMI_32BIT_REG (1 << 8)
41#define HDMI_HAS_HTOP1 (1 << 9)
42
33struct sh_mobile_hdmi_info { 43struct sh_mobile_hdmi_info {
34 unsigned int flags; 44 unsigned int flags;
35 long (*clk_optimize_parent)(unsigned long target, unsigned long *best_freq, 45 long (*clk_optimize_parent)(unsigned long target, unsigned long *best_freq,
diff --git a/init/Kconfig b/init/Kconfig
index 1e004d057468..d07dcf9fc8a9 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -167,7 +167,7 @@ config KERNEL_BZIP2
167 depends on HAVE_KERNEL_BZIP2 167 depends on HAVE_KERNEL_BZIP2
168 help 168 help
169 Its compression ratio and speed is intermediate. 169 Its compression ratio and speed is intermediate.
170 Decompression speed is slowest among the three. The kernel 170 Decompression speed is slowest among the choices. The kernel
171 size is about 10% smaller with bzip2, in comparison to gzip. 171 size is about 10% smaller with bzip2, in comparison to gzip.
172 Bzip2 uses a large amount of memory. For modern kernels you 172 Bzip2 uses a large amount of memory. For modern kernels you
173 will need at least 8MB RAM or more for booting. 173 will need at least 8MB RAM or more for booting.
@@ -176,10 +176,9 @@ config KERNEL_LZMA
176 bool "LZMA" 176 bool "LZMA"
177 depends on HAVE_KERNEL_LZMA 177 depends on HAVE_KERNEL_LZMA
178 help 178 help
179 The most recent compression algorithm. 179 This compression algorithm's ratio is best. Decompression speed
180 Its ratio is best, decompression speed is between the other 180 is between gzip and bzip2. Compression is slowest.
181 two. Compression is slowest. The kernel size is about 33% 181 The kernel size is about 33% smaller with LZMA in comparison to gzip.
182 smaller with LZMA in comparison to gzip.
183 182
184config KERNEL_XZ 183config KERNEL_XZ
185 bool "XZ" 184 bool "XZ"
@@ -200,7 +199,7 @@ config KERNEL_LZO
200 bool "LZO" 199 bool "LZO"
201 depends on HAVE_KERNEL_LZO 200 depends on HAVE_KERNEL_LZO
202 help 201 help
203 Its compression ratio is the poorest among the 4. The kernel 202 Its compression ratio is the poorest among the choices. The kernel
204 size is about 10% bigger than gzip; however its speed 203 size is about 10% bigger than gzip; however its speed
205 (both compression and decompression) is the fastest. 204 (both compression and decompression) is the fastest.
206 205
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 42b0707c3481..d3f0aeed2d39 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -1,3 +1,13 @@
1/*
2 * Many of the syscalls used in this file expect some of the arguments
3 * to be __user pointers not __kernel pointers. To limit the sparse
4 * noise, turn off sparse checking for this file.
5 */
6#ifdef __CHECKER__
7#undef __CHECKER__
8#warning "Sparse checking disabled for this file"
9#endif
10
1#include <linux/module.h> 11#include <linux/module.h>
2#include <linux/sched.h> 12#include <linux/sched.h>
3#include <linux/ctype.h> 13#include <linux/ctype.h>
@@ -330,7 +340,7 @@ static int __init do_mount_root(char *name, char *fs, int flags, void *data)
330 if (err) 340 if (err)
331 return err; 341 return err;
332 342
333 sys_chdir((const char __user __force *)"/root"); 343 sys_chdir("/root");
334 s = current->fs->pwd.dentry->d_sb; 344 s = current->fs->pwd.dentry->d_sb;
335 ROOT_DEV = s->s_dev; 345 ROOT_DEV = s->s_dev;
336 printk(KERN_INFO 346 printk(KERN_INFO
@@ -556,5 +566,5 @@ void __init prepare_namespace(void)
556out: 566out:
557 devtmpfs_mount("dev"); 567 devtmpfs_mount("dev");
558 sys_mount(".", "/", NULL, MS_MOVE, NULL); 568 sys_mount(".", "/", NULL, MS_MOVE, NULL);
559 sys_chroot((const char __user __force *)"."); 569 sys_chroot(".");
560} 570}
diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index 9047330c73e9..135959a276be 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -1,3 +1,13 @@
1/*
2 * Many of the syscalls used in this file expect some of the arguments
3 * to be __user pointers not __kernel pointers. To limit the sparse
4 * noise, turn off sparse checking for this file.
5 */
6#ifdef __CHECKER__
7#undef __CHECKER__
8#warning "Sparse checking disabled for this file"
9#endif
10
1#include <linux/unistd.h> 11#include <linux/unistd.h>
2#include <linux/kernel.h> 12#include <linux/kernel.h>
3#include <linux/fs.h> 13#include <linux/fs.h>
diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
index 32c4799b8c91..8cb6db54285b 100644
--- a/init/do_mounts_md.c
+++ b/init/do_mounts_md.c
@@ -1,3 +1,13 @@
1/*
2 * Many of the syscalls used in this file expect some of the arguments
3 * to be __user pointers not __kernel pointers. To limit the sparse
4 * noise, turn off sparse checking for this file.
5 */
6#ifdef __CHECKER__
7#undef __CHECKER__
8#warning "Sparse checking disabled for this file"
9#endif
10
1#include <linux/delay.h> 11#include <linux/delay.h>
2#include <linux/raid/md_u.h> 12#include <linux/raid/md_u.h>
3#include <linux/raid/md_p.h> 13#include <linux/raid/md_p.h>
@@ -283,7 +293,7 @@ static void __init autodetect_raid(void)
283 293
284 wait_for_device_probe(); 294 wait_for_device_probe();
285 295
286 fd = sys_open((const char __user __force *) "/dev/md0", 0, 0); 296 fd = sys_open("/dev/md0", 0, 0);
287 if (fd >= 0) { 297 if (fd >= 0) {
288 sys_ioctl(fd, RAID_AUTORUN, raid_autopart); 298 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
289 sys_close(fd); 299 sys_close(fd);
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
index 6212586df29a..6be2879cca66 100644
--- a/init/do_mounts_rd.c
+++ b/init/do_mounts_rd.c
@@ -1,3 +1,12 @@
1/*
2 * Many of the syscalls used in this file expect some of the arguments
3 * to be __user pointers not __kernel pointers. To limit the sparse
4 * noise, turn off sparse checking for this file.
5 */
6#ifdef __CHECKER__
7#undef __CHECKER__
8#warning "Sparse checking disabled for this file"
9#endif
1 10
2#include <linux/kernel.h> 11#include <linux/kernel.h>
3#include <linux/fs.h> 12#include <linux/fs.h>
@@ -181,7 +190,7 @@ int __init rd_load_image(char *from)
181 char rotator[4] = { '|' , '/' , '-' , '\\' }; 190 char rotator[4] = { '|' , '/' , '-' , '\\' };
182#endif 191#endif
183 192
184 out_fd = sys_open((const char __user __force *) "/dev/ram", O_RDWR, 0); 193 out_fd = sys_open("/dev/ram", O_RDWR, 0);
185 if (out_fd < 0) 194 if (out_fd < 0)
186 goto out; 195 goto out;
187 196
@@ -280,7 +289,7 @@ noclose_input:
280 sys_close(out_fd); 289 sys_close(out_fd);
281out: 290out:
282 kfree(buf); 291 kfree(buf);
283 sys_unlink((const char __user __force *) "/dev/ram"); 292 sys_unlink("/dev/ram");
284 return res; 293 return res;
285} 294}
286 295
diff --git a/init/initramfs.c b/init/initramfs.c
index 8216c303b082..84c6bf111300 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -1,3 +1,13 @@
1/*
2 * Many of the syscalls used in this file expect some of the arguments
3 * to be __user pointers not __kernel pointers. To limit the sparse
4 * noise, turn off sparse checking for this file.
5 */
6#ifdef __CHECKER__
7#undef __CHECKER__
8#warning "Sparse checking disabled for this file"
9#endif
10
1#include <linux/init.h> 11#include <linux/init.h>
2#include <linux/fs.h> 12#include <linux/fs.h>
3#include <linux/slab.h> 13#include <linux/slab.h>
@@ -74,7 +84,7 @@ static void __init free_hash(void)
74 } 84 }
75} 85}
76 86
77static long __init do_utime(char __user *filename, time_t mtime) 87static long __init do_utime(char *filename, time_t mtime)
78{ 88{
79 struct timespec t[2]; 89 struct timespec t[2];
80 90
@@ -529,7 +539,7 @@ static void __init clean_rootfs(void)
529 struct linux_dirent64 *dirp; 539 struct linux_dirent64 *dirp;
530 int num; 540 int num;
531 541
532 fd = sys_open((const char __user __force *) "/", O_RDONLY, 0); 542 fd = sys_open("/", O_RDONLY, 0);
533 WARN_ON(fd < 0); 543 WARN_ON(fd < 0);
534 if (fd < 0) 544 if (fd < 0)
535 return; 545 return;
@@ -589,7 +599,7 @@ static int __init populate_rootfs(void)
589 } 599 }
590 printk(KERN_INFO "rootfs image is not initramfs (%s)" 600 printk(KERN_INFO "rootfs image is not initramfs (%s)"
591 "; looks like an initrd\n", err); 601 "; looks like an initrd\n", err);
592 fd = sys_open((const char __user __force *) "/initrd.image", 602 fd = sys_open("/initrd.image",
593 O_WRONLY|O_CREAT, 0700); 603 O_WRONLY|O_CREAT, 0700);
594 if (fd >= 0) { 604 if (fd >= 0) {
595 sys_write(fd, (char *)initrd_start, 605 sys_write(fd, (char *)initrd_start,
diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
index 0c09366b96f3..383d638340b8 100644
--- a/ipc/mq_sysctl.c
+++ b/ipc/mq_sysctl.c
@@ -13,15 +13,6 @@
13#include <linux/ipc_namespace.h> 13#include <linux/ipc_namespace.h>
14#include <linux/sysctl.h> 14#include <linux/sysctl.h>
15 15
16/*
17 * Define the ranges various user-specified maximum values can
18 * be set to.
19 */
20#define MIN_MSGMAX 1 /* min value for msg_max */
21#define MAX_MSGMAX HARD_MSGMAX /* max value for msg_max */
22#define MIN_MSGSIZEMAX 128 /* min value for msgsize_max */
23#define MAX_MSGSIZEMAX (8192*128) /* max value for msgsize_max */
24
25#ifdef CONFIG_PROC_SYSCTL 16#ifdef CONFIG_PROC_SYSCTL
26static void *get_mq(ctl_table *table) 17static void *get_mq(ctl_table *table)
27{ 18{
@@ -31,16 +22,6 @@ static void *get_mq(ctl_table *table)
31 return which; 22 return which;
32} 23}
33 24
34static int proc_mq_dointvec(ctl_table *table, int write,
35 void __user *buffer, size_t *lenp, loff_t *ppos)
36{
37 struct ctl_table mq_table;
38 memcpy(&mq_table, table, sizeof(mq_table));
39 mq_table.data = get_mq(table);
40
41 return proc_dointvec(&mq_table, write, buffer, lenp, ppos);
42}
43
44static int proc_mq_dointvec_minmax(ctl_table *table, int write, 25static int proc_mq_dointvec_minmax(ctl_table *table, int write,
45 void __user *buffer, size_t *lenp, loff_t *ppos) 26 void __user *buffer, size_t *lenp, loff_t *ppos)
46{ 27{
@@ -52,15 +33,17 @@ static int proc_mq_dointvec_minmax(ctl_table *table, int write,
52 lenp, ppos); 33 lenp, ppos);
53} 34}
54#else 35#else
55#define proc_mq_dointvec NULL
56#define proc_mq_dointvec_minmax NULL 36#define proc_mq_dointvec_minmax NULL
57#endif 37#endif
58 38
39static int msg_queues_limit_min = MIN_QUEUESMAX;
40static int msg_queues_limit_max = HARD_QUEUESMAX;
41
59static int msg_max_limit_min = MIN_MSGMAX; 42static int msg_max_limit_min = MIN_MSGMAX;
60static int msg_max_limit_max = MAX_MSGMAX; 43static int msg_max_limit_max = HARD_MSGMAX;
61 44
62static int msg_maxsize_limit_min = MIN_MSGSIZEMAX; 45static int msg_maxsize_limit_min = MIN_MSGSIZEMAX;
63static int msg_maxsize_limit_max = MAX_MSGSIZEMAX; 46static int msg_maxsize_limit_max = HARD_MSGSIZEMAX;
64 47
65static ctl_table mq_sysctls[] = { 48static ctl_table mq_sysctls[] = {
66 { 49 {
@@ -68,7 +51,9 @@ static ctl_table mq_sysctls[] = {
68 .data = &init_ipc_ns.mq_queues_max, 51 .data = &init_ipc_ns.mq_queues_max,
69 .maxlen = sizeof(int), 52 .maxlen = sizeof(int),
70 .mode = 0644, 53 .mode = 0644,
71 .proc_handler = proc_mq_dointvec, 54 .proc_handler = proc_mq_dointvec_minmax,
55 .extra1 = &msg_queues_limit_min,
56 .extra2 = &msg_queues_limit_max,
72 }, 57 },
73 { 58 {
74 .procname = "msg_max", 59 .procname = "msg_max",
@@ -88,6 +73,24 @@ static ctl_table mq_sysctls[] = {
88 .extra1 = &msg_maxsize_limit_min, 73 .extra1 = &msg_maxsize_limit_min,
89 .extra2 = &msg_maxsize_limit_max, 74 .extra2 = &msg_maxsize_limit_max,
90 }, 75 },
76 {
77 .procname = "msg_default",
78 .data = &init_ipc_ns.mq_msg_default,
79 .maxlen = sizeof(int),
80 .mode = 0644,
81 .proc_handler = proc_mq_dointvec_minmax,
82 .extra1 = &msg_max_limit_min,
83 .extra2 = &msg_max_limit_max,
84 },
85 {
86 .procname = "msgsize_default",
87 .data = &init_ipc_ns.mq_msgsize_default,
88 .maxlen = sizeof(int),
89 .mode = 0644,
90 .proc_handler = proc_mq_dointvec_minmax,
91 .extra1 = &msg_maxsize_limit_min,
92 .extra2 = &msg_maxsize_limit_max,
93 },
91 {} 94 {}
92}; 95};
93 96
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index a2757d4ab773..8ce57691e7b6 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -24,6 +24,7 @@
24#include <linux/mqueue.h> 24#include <linux/mqueue.h>
25#include <linux/msg.h> 25#include <linux/msg.h>
26#include <linux/skbuff.h> 26#include <linux/skbuff.h>
27#include <linux/vmalloc.h>
27#include <linux/netlink.h> 28#include <linux/netlink.h>
28#include <linux/syscalls.h> 29#include <linux/syscalls.h>
29#include <linux/audit.h> 30#include <linux/audit.h>
@@ -49,6 +50,12 @@
49#define STATE_PENDING 1 50#define STATE_PENDING 1
50#define STATE_READY 2 51#define STATE_READY 2
51 52
53struct posix_msg_tree_node {
54 struct rb_node rb_node;
55 struct list_head msg_list;
56 int priority;
57};
58
52struct ext_wait_queue { /* queue of sleeping tasks */ 59struct ext_wait_queue { /* queue of sleeping tasks */
53 struct task_struct *task; 60 struct task_struct *task;
54 struct list_head list; 61 struct list_head list;
@@ -61,7 +68,8 @@ struct mqueue_inode_info {
61 struct inode vfs_inode; 68 struct inode vfs_inode;
62 wait_queue_head_t wait_q; 69 wait_queue_head_t wait_q;
63 70
64 struct msg_msg **messages; 71 struct rb_root msg_tree;
72 struct posix_msg_tree_node *node_cache;
65 struct mq_attr attr; 73 struct mq_attr attr;
66 74
67 struct sigevent notify; 75 struct sigevent notify;
@@ -109,6 +117,103 @@ static struct ipc_namespace *get_ns_from_inode(struct inode *inode)
109 return ns; 117 return ns;
110} 118}
111 119
120/* Auxiliary functions to manipulate messages' list */
121static int msg_insert(struct msg_msg *msg, struct mqueue_inode_info *info)
122{
123 struct rb_node **p, *parent = NULL;
124 struct posix_msg_tree_node *leaf;
125
126 p = &info->msg_tree.rb_node;
127 while (*p) {
128 parent = *p;
129 leaf = rb_entry(parent, struct posix_msg_tree_node, rb_node);
130
131 if (likely(leaf->priority == msg->m_type))
132 goto insert_msg;
133 else if (msg->m_type < leaf->priority)
134 p = &(*p)->rb_left;
135 else
136 p = &(*p)->rb_right;
137 }
138 if (info->node_cache) {
139 leaf = info->node_cache;
140 info->node_cache = NULL;
141 } else {
142 leaf = kmalloc(sizeof(*leaf), GFP_ATOMIC);
143 if (!leaf)
144 return -ENOMEM;
145 rb_init_node(&leaf->rb_node);
146 INIT_LIST_HEAD(&leaf->msg_list);
147 info->qsize += sizeof(*leaf);
148 }
149 leaf->priority = msg->m_type;
150 rb_link_node(&leaf->rb_node, parent, p);
151 rb_insert_color(&leaf->rb_node, &info->msg_tree);
152insert_msg:
153 info->attr.mq_curmsgs++;
154 info->qsize += msg->m_ts;
155 list_add_tail(&msg->m_list, &leaf->msg_list);
156 return 0;
157}
158
159static inline struct msg_msg *msg_get(struct mqueue_inode_info *info)
160{
161 struct rb_node **p, *parent = NULL;
162 struct posix_msg_tree_node *leaf;
163 struct msg_msg *msg;
164
165try_again:
166 p = &info->msg_tree.rb_node;
167 while (*p) {
168 parent = *p;
169 /*
170 * During insert, low priorities go to the left and high to the
171 * right. On receive, we want the highest priorities first, so
172 * walk all the way to the right.
173 */
174 p = &(*p)->rb_right;
175 }
176 if (!parent) {
177 if (info->attr.mq_curmsgs) {
178 pr_warn_once("Inconsistency in POSIX message queue, "
179 "no tree element, but supposedly messages "
180 "should exist!\n");
181 info->attr.mq_curmsgs = 0;
182 }
183 return NULL;
184 }
185 leaf = rb_entry(parent, struct posix_msg_tree_node, rb_node);
186 if (unlikely(list_empty(&leaf->msg_list))) {
187 pr_warn_once("Inconsistency in POSIX message queue, "
188 "empty leaf node but we haven't implemented "
189 "lazy leaf delete!\n");
190 rb_erase(&leaf->rb_node, &info->msg_tree);
191 if (info->node_cache) {
192 info->qsize -= sizeof(*leaf);
193 kfree(leaf);
194 } else {
195 info->node_cache = leaf;
196 }
197 goto try_again;
198 } else {
199 msg = list_first_entry(&leaf->msg_list,
200 struct msg_msg, m_list);
201 list_del(&msg->m_list);
202 if (list_empty(&leaf->msg_list)) {
203 rb_erase(&leaf->rb_node, &info->msg_tree);
204 if (info->node_cache) {
205 info->qsize -= sizeof(*leaf);
206 kfree(leaf);
207 } else {
208 info->node_cache = leaf;
209 }
210 }
211 }
212 info->attr.mq_curmsgs--;
213 info->qsize -= msg->m_ts;
214 return msg;
215}
216
112static struct inode *mqueue_get_inode(struct super_block *sb, 217static struct inode *mqueue_get_inode(struct super_block *sb,
113 struct ipc_namespace *ipc_ns, umode_t mode, 218 struct ipc_namespace *ipc_ns, umode_t mode,
114 struct mq_attr *attr) 219 struct mq_attr *attr)
@@ -129,7 +234,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
129 234
130 if (S_ISREG(mode)) { 235 if (S_ISREG(mode)) {
131 struct mqueue_inode_info *info; 236 struct mqueue_inode_info *info;
132 unsigned long mq_bytes, mq_msg_tblsz; 237 unsigned long mq_bytes, mq_treesize;
133 238
134 inode->i_fop = &mqueue_file_operations; 239 inode->i_fop = &mqueue_file_operations;
135 inode->i_size = FILENT_SIZE; 240 inode->i_size = FILENT_SIZE;
@@ -143,20 +248,36 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
143 info->notify_user_ns = NULL; 248 info->notify_user_ns = NULL;
144 info->qsize = 0; 249 info->qsize = 0;
145 info->user = NULL; /* set when all is ok */ 250 info->user = NULL; /* set when all is ok */
251 info->msg_tree = RB_ROOT;
252 info->node_cache = NULL;
146 memset(&info->attr, 0, sizeof(info->attr)); 253 memset(&info->attr, 0, sizeof(info->attr));
147 info->attr.mq_maxmsg = ipc_ns->mq_msg_max; 254 info->attr.mq_maxmsg = min(ipc_ns->mq_msg_max,
148 info->attr.mq_msgsize = ipc_ns->mq_msgsize_max; 255 ipc_ns->mq_msg_default);
256 info->attr.mq_msgsize = min(ipc_ns->mq_msgsize_max,
257 ipc_ns->mq_msgsize_default);
149 if (attr) { 258 if (attr) {
150 info->attr.mq_maxmsg = attr->mq_maxmsg; 259 info->attr.mq_maxmsg = attr->mq_maxmsg;
151 info->attr.mq_msgsize = attr->mq_msgsize; 260 info->attr.mq_msgsize = attr->mq_msgsize;
152 } 261 }
153 mq_msg_tblsz = info->attr.mq_maxmsg * sizeof(struct msg_msg *); 262 /*
154 info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL); 263 * We used to allocate a static array of pointers and account
155 if (!info->messages) 264 * the size of that array as well as one msg_msg struct per
156 goto out_inode; 265 * possible message into the queue size. That's no longer
266 * accurate as the queue is now an rbtree and will grow and
267 * shrink depending on usage patterns. We can, however, still
268 * account one msg_msg struct per message, but the nodes are
269 * allocated depending on priority usage, and most programs
270 * only use one, or a handful, of priorities. However, since
271 * this is pinned memory, we need to assume worst case, so
272 * that means the min(mq_maxmsg, max_priorities) * struct
273 * posix_msg_tree_node.
274 */
275 mq_treesize = info->attr.mq_maxmsg * sizeof(struct msg_msg) +
276 min_t(unsigned int, info->attr.mq_maxmsg, MQ_PRIO_MAX) *
277 sizeof(struct posix_msg_tree_node);
157 278
158 mq_bytes = (mq_msg_tblsz + 279 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
159 (info->attr.mq_maxmsg * info->attr.mq_msgsize)); 280 info->attr.mq_msgsize);
160 281
161 spin_lock(&mq_lock); 282 spin_lock(&mq_lock);
162 if (u->mq_bytes + mq_bytes < u->mq_bytes || 283 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
@@ -247,9 +368,9 @@ static void mqueue_evict_inode(struct inode *inode)
247{ 368{
248 struct mqueue_inode_info *info; 369 struct mqueue_inode_info *info;
249 struct user_struct *user; 370 struct user_struct *user;
250 unsigned long mq_bytes; 371 unsigned long mq_bytes, mq_treesize;
251 int i;
252 struct ipc_namespace *ipc_ns; 372 struct ipc_namespace *ipc_ns;
373 struct msg_msg *msg;
253 374
254 clear_inode(inode); 375 clear_inode(inode);
255 376
@@ -259,14 +380,19 @@ static void mqueue_evict_inode(struct inode *inode)
259 ipc_ns = get_ns_from_inode(inode); 380 ipc_ns = get_ns_from_inode(inode);
260 info = MQUEUE_I(inode); 381 info = MQUEUE_I(inode);
261 spin_lock(&info->lock); 382 spin_lock(&info->lock);
262 for (i = 0; i < info->attr.mq_curmsgs; i++) 383 while ((msg = msg_get(info)) != NULL)
263 free_msg(info->messages[i]); 384 free_msg(msg);
264 kfree(info->messages); 385 kfree(info->node_cache);
265 spin_unlock(&info->lock); 386 spin_unlock(&info->lock);
266 387
267 /* Total amount of bytes accounted for the mqueue */ 388 /* Total amount of bytes accounted for the mqueue */
268 mq_bytes = info->attr.mq_maxmsg * (sizeof(struct msg_msg *) 389 mq_treesize = info->attr.mq_maxmsg * sizeof(struct msg_msg) +
269 + info->attr.mq_msgsize); 390 min_t(unsigned int, info->attr.mq_maxmsg, MQ_PRIO_MAX) *
391 sizeof(struct posix_msg_tree_node);
392
393 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
394 info->attr.mq_msgsize);
395
270 user = info->user; 396 user = info->user;
271 if (user) { 397 if (user) {
272 spin_lock(&mq_lock); 398 spin_lock(&mq_lock);
@@ -300,8 +426,9 @@ static int mqueue_create(struct inode *dir, struct dentry *dentry,
300 error = -EACCES; 426 error = -EACCES;
301 goto out_unlock; 427 goto out_unlock;
302 } 428 }
303 if (ipc_ns->mq_queues_count >= ipc_ns->mq_queues_max && 429 if (ipc_ns->mq_queues_count >= HARD_QUEUESMAX ||
304 !capable(CAP_SYS_RESOURCE)) { 430 (ipc_ns->mq_queues_count >= ipc_ns->mq_queues_max &&
431 !capable(CAP_SYS_RESOURCE))) {
305 error = -ENOSPC; 432 error = -ENOSPC;
306 goto out_unlock; 433 goto out_unlock;
307 } 434 }
@@ -485,26 +612,6 @@ static struct ext_wait_queue *wq_get_first_waiter(
485 return list_entry(ptr, struct ext_wait_queue, list); 612 return list_entry(ptr, struct ext_wait_queue, list);
486} 613}
487 614
488/* Auxiliary functions to manipulate messages' list */
489static void msg_insert(struct msg_msg *ptr, struct mqueue_inode_info *info)
490{
491 int k;
492
493 k = info->attr.mq_curmsgs - 1;
494 while (k >= 0 && info->messages[k]->m_type >= ptr->m_type) {
495 info->messages[k + 1] = info->messages[k];
496 k--;
497 }
498 info->attr.mq_curmsgs++;
499 info->qsize += ptr->m_ts;
500 info->messages[k + 1] = ptr;
501}
502
503static inline struct msg_msg *msg_get(struct mqueue_inode_info *info)
504{
505 info->qsize -= info->messages[--info->attr.mq_curmsgs]->m_ts;
506 return info->messages[info->attr.mq_curmsgs];
507}
508 615
509static inline void set_cookie(struct sk_buff *skb, char code) 616static inline void set_cookie(struct sk_buff *skb, char code)
510{ 617{
@@ -585,24 +692,30 @@ static void remove_notification(struct mqueue_inode_info *info)
585 692
586static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr) 693static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr)
587{ 694{
695 int mq_treesize;
696 unsigned long total_size;
697
588 if (attr->mq_maxmsg <= 0 || attr->mq_msgsize <= 0) 698 if (attr->mq_maxmsg <= 0 || attr->mq_msgsize <= 0)
589 return 0; 699 return -EINVAL;
590 if (capable(CAP_SYS_RESOURCE)) { 700 if (capable(CAP_SYS_RESOURCE)) {
591 if (attr->mq_maxmsg > HARD_MSGMAX) 701 if (attr->mq_maxmsg > HARD_MSGMAX ||
592 return 0; 702 attr->mq_msgsize > HARD_MSGSIZEMAX)
703 return -EINVAL;
593 } else { 704 } else {
594 if (attr->mq_maxmsg > ipc_ns->mq_msg_max || 705 if (attr->mq_maxmsg > ipc_ns->mq_msg_max ||
595 attr->mq_msgsize > ipc_ns->mq_msgsize_max) 706 attr->mq_msgsize > ipc_ns->mq_msgsize_max)
596 return 0; 707 return -EINVAL;
597 } 708 }
598 /* check for overflow */ 709 /* check for overflow */
599 if (attr->mq_msgsize > ULONG_MAX/attr->mq_maxmsg) 710 if (attr->mq_msgsize > ULONG_MAX/attr->mq_maxmsg)
600 return 0; 711 return -EOVERFLOW;
601 if ((unsigned long)(attr->mq_maxmsg * (attr->mq_msgsize 712 mq_treesize = attr->mq_maxmsg * sizeof(struct msg_msg) +
602 + sizeof (struct msg_msg *))) < 713 min_t(unsigned int, attr->mq_maxmsg, MQ_PRIO_MAX) *
603 (unsigned long)(attr->mq_maxmsg * attr->mq_msgsize)) 714 sizeof(struct posix_msg_tree_node);
604 return 0; 715 total_size = attr->mq_maxmsg * attr->mq_msgsize;
605 return 1; 716 if (total_size + mq_treesize < total_size)
717 return -EOVERFLOW;
718 return 0;
606} 719}
607 720
608/* 721/*
@@ -617,12 +730,21 @@ static struct file *do_create(struct ipc_namespace *ipc_ns, struct dentry *dir,
617 int ret; 730 int ret;
618 731
619 if (attr) { 732 if (attr) {
620 if (!mq_attr_ok(ipc_ns, attr)) { 733 ret = mq_attr_ok(ipc_ns, attr);
621 ret = -EINVAL; 734 if (ret)
622 goto out; 735 goto out;
623 }
624 /* store for use during create */ 736 /* store for use during create */
625 dentry->d_fsdata = attr; 737 dentry->d_fsdata = attr;
738 } else {
739 struct mq_attr def_attr;
740
741 def_attr.mq_maxmsg = min(ipc_ns->mq_msg_max,
742 ipc_ns->mq_msg_default);
743 def_attr.mq_msgsize = min(ipc_ns->mq_msgsize_max,
744 ipc_ns->mq_msgsize_default);
745 ret = mq_attr_ok(ipc_ns, &def_attr);
746 if (ret)
747 goto out;
626 } 748 }
627 749
628 mode &= ~current_umask(); 750 mode &= ~current_umask();
@@ -837,7 +959,8 @@ static inline void pipelined_receive(struct mqueue_inode_info *info)
837 wake_up_interruptible(&info->wait_q); 959 wake_up_interruptible(&info->wait_q);
838 return; 960 return;
839 } 961 }
840 msg_insert(sender->msg, info); 962 if (msg_insert(sender->msg, info))
963 return;
841 list_del(&sender->list); 964 list_del(&sender->list);
842 sender->state = STATE_PENDING; 965 sender->state = STATE_PENDING;
843 wake_up_process(sender->task); 966 wake_up_process(sender->task);
@@ -857,7 +980,8 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
857 struct mqueue_inode_info *info; 980 struct mqueue_inode_info *info;
858 ktime_t expires, *timeout = NULL; 981 ktime_t expires, *timeout = NULL;
859 struct timespec ts; 982 struct timespec ts;
860 int ret; 983 struct posix_msg_tree_node *new_leaf = NULL;
984 int ret = 0;
861 985
862 if (u_abs_timeout) { 986 if (u_abs_timeout) {
863 int res = prepare_timeout(u_abs_timeout, &expires, &ts); 987 int res = prepare_timeout(u_abs_timeout, &expires, &ts);
@@ -905,34 +1029,60 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
905 msg_ptr->m_ts = msg_len; 1029 msg_ptr->m_ts = msg_len;
906 msg_ptr->m_type = msg_prio; 1030 msg_ptr->m_type = msg_prio;
907 1031
1032 /*
1033 * msg_insert really wants us to have a valid, spare node struct so
1034 * it doesn't have to kmalloc a GFP_ATOMIC allocation, but it will
1035 * fall back to that if necessary.
1036 */
1037 if (!info->node_cache)
1038 new_leaf = kmalloc(sizeof(*new_leaf), GFP_KERNEL);
1039
908 spin_lock(&info->lock); 1040 spin_lock(&info->lock);
909 1041
1042 if (!info->node_cache && new_leaf) {
1043 /* Save our speculative allocation into the cache */
1044 rb_init_node(&new_leaf->rb_node);
1045 INIT_LIST_HEAD(&new_leaf->msg_list);
1046 info->node_cache = new_leaf;
1047 info->qsize += sizeof(*new_leaf);
1048 new_leaf = NULL;
1049 } else {
1050 kfree(new_leaf);
1051 }
1052
910 if (info->attr.mq_curmsgs == info->attr.mq_maxmsg) { 1053 if (info->attr.mq_curmsgs == info->attr.mq_maxmsg) {
911 if (filp->f_flags & O_NONBLOCK) { 1054 if (filp->f_flags & O_NONBLOCK) {
912 spin_unlock(&info->lock);
913 ret = -EAGAIN; 1055 ret = -EAGAIN;
914 } else { 1056 } else {
915 wait.task = current; 1057 wait.task = current;
916 wait.msg = (void *) msg_ptr; 1058 wait.msg = (void *) msg_ptr;
917 wait.state = STATE_NONE; 1059 wait.state = STATE_NONE;
918 ret = wq_sleep(info, SEND, timeout, &wait); 1060 ret = wq_sleep(info, SEND, timeout, &wait);
1061 /*
1062 * wq_sleep must be called with info->lock held, and
1063 * returns with the lock released
1064 */
1065 goto out_free;
919 } 1066 }
920 if (ret < 0)
921 free_msg(msg_ptr);
922 } else { 1067 } else {
923 receiver = wq_get_first_waiter(info, RECV); 1068 receiver = wq_get_first_waiter(info, RECV);
924 if (receiver) { 1069 if (receiver) {
925 pipelined_send(info, msg_ptr, receiver); 1070 pipelined_send(info, msg_ptr, receiver);
926 } else { 1071 } else {
927 /* adds message to the queue */ 1072 /* adds message to the queue */
928 msg_insert(msg_ptr, info); 1073 ret = msg_insert(msg_ptr, info);
1074 if (ret)
1075 goto out_unlock;
929 __do_notify(info); 1076 __do_notify(info);
930 } 1077 }
931 inode->i_atime = inode->i_mtime = inode->i_ctime = 1078 inode->i_atime = inode->i_mtime = inode->i_ctime =
932 CURRENT_TIME; 1079 CURRENT_TIME;
933 spin_unlock(&info->lock);
934 ret = 0;
935 } 1080 }
1081out_unlock:
1082 spin_unlock(&info->lock);
1083out_free:
1084 if (ret)
1085 free_msg(msg_ptr);
936out_fput: 1086out_fput:
937 fput(filp); 1087 fput(filp);
938out: 1088out:
@@ -951,6 +1101,7 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
951 struct ext_wait_queue wait; 1101 struct ext_wait_queue wait;
952 ktime_t expires, *timeout = NULL; 1102 ktime_t expires, *timeout = NULL;
953 struct timespec ts; 1103 struct timespec ts;
1104 struct posix_msg_tree_node *new_leaf = NULL;
954 1105
955 if (u_abs_timeout) { 1106 if (u_abs_timeout) {
956 int res = prepare_timeout(u_abs_timeout, &expires, &ts); 1107 int res = prepare_timeout(u_abs_timeout, &expires, &ts);
@@ -986,7 +1137,26 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
986 goto out_fput; 1137 goto out_fput;
987 } 1138 }
988 1139
1140 /*
1141 * msg_insert really wants us to have a valid, spare node struct so
1142 * it doesn't have to kmalloc a GFP_ATOMIC allocation, but it will
1143 * fall back to that if necessary.
1144 */
1145 if (!info->node_cache)
1146 new_leaf = kmalloc(sizeof(*new_leaf), GFP_KERNEL);
1147
989 spin_lock(&info->lock); 1148 spin_lock(&info->lock);
1149
1150 if (!info->node_cache && new_leaf) {
1151 /* Save our speculative allocation into the cache */
1152 rb_init_node(&new_leaf->rb_node);
1153 INIT_LIST_HEAD(&new_leaf->msg_list);
1154 info->node_cache = new_leaf;
1155 info->qsize += sizeof(*new_leaf);
1156 } else {
1157 kfree(new_leaf);
1158 }
1159
990 if (info->attr.mq_curmsgs == 0) { 1160 if (info->attr.mq_curmsgs == 0) {
991 if (filp->f_flags & O_NONBLOCK) { 1161 if (filp->f_flags & O_NONBLOCK) {
992 spin_unlock(&info->lock); 1162 spin_unlock(&info->lock);
@@ -1251,6 +1421,8 @@ int mq_init_ns(struct ipc_namespace *ns)
1251 ns->mq_queues_max = DFLT_QUEUESMAX; 1421 ns->mq_queues_max = DFLT_QUEUESMAX;
1252 ns->mq_msg_max = DFLT_MSGMAX; 1422 ns->mq_msg_max = DFLT_MSGMAX;
1253 ns->mq_msgsize_max = DFLT_MSGSIZEMAX; 1423 ns->mq_msgsize_max = DFLT_MSGSIZEMAX;
1424 ns->mq_msg_default = DFLT_MSG;
1425 ns->mq_msgsize_default = DFLT_MSGSIZE;
1254 1426
1255 ns->mq_mnt = kern_mount_data(&mqueue_fs_type, ns); 1427 ns->mq_mnt = kern_mount_data(&mqueue_fs_type, ns);
1256 if (IS_ERR(ns->mq_mnt)) { 1428 if (IS_ERR(ns->mq_mnt)) {
diff --git a/ipc/shm.c b/ipc/shm.c
index 406c5b208193..5e2cbfdab6fc 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -1036,6 +1036,10 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
1036 sfd->file = shp->shm_file; 1036 sfd->file = shp->shm_file;
1037 sfd->vm_ops = NULL; 1037 sfd->vm_ops = NULL;
1038 1038
1039 err = security_mmap_file(file, prot, flags);
1040 if (err)
1041 goto out_fput;
1042
1039 down_write(&current->mm->mmap_sem); 1043 down_write(&current->mm->mmap_sem);
1040 if (addr && !(shmflg & SHM_REMAP)) { 1044 if (addr && !(shmflg & SHM_REMAP)) {
1041 err = -EINVAL; 1045 err = -EINVAL;
@@ -1050,7 +1054,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
1050 goto invalid; 1054 goto invalid;
1051 } 1055 }
1052 1056
1053 user_addr = do_mmap (file, addr, size, prot, flags, 0); 1057 user_addr = do_mmap_pgoff(file, addr, size, prot, flags, 0);
1054 *raddr = user_addr; 1058 *raddr = user_addr;
1055 err = 0; 1059 err = 0;
1056 if (IS_ERR_VALUE(user_addr)) 1060 if (IS_ERR_VALUE(user_addr))
@@ -1058,6 +1062,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
1058invalid: 1062invalid:
1059 up_write(&current->mm->mmap_sem); 1063 up_write(&current->mm->mmap_sem);
1060 1064
1065out_fput:
1061 fput(file); 1066 fput(file);
1062 1067
1063out_nattch: 1068out_nattch:
diff --git a/kernel/Makefile b/kernel/Makefile
index 6c07f30fa9b7..c0cc67ad764c 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -5,12 +5,12 @@
5obj-y = fork.o exec_domain.o panic.o printk.o \ 5obj-y = fork.o exec_domain.o panic.o printk.o \
6 cpu.o exit.o itimer.o time.o softirq.o resource.o \ 6 cpu.o exit.o itimer.o time.o softirq.o resource.o \
7 sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \ 7 sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \
8 signal.o sys.o kmod.o workqueue.o pid.o \ 8 signal.o sys.o kmod.o workqueue.o pid.o task_work.o \
9 rcupdate.o extable.o params.o posix-timers.o \ 9 rcupdate.o extable.o params.o posix-timers.o \
10 kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ 10 kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
11 hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ 11 hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
12 notifier.o ksysfs.o cred.o \ 12 notifier.o ksysfs.o cred.o \
13 async.o range.o groups.o 13 async.o range.o groups.o lglock.o
14 14
15ifdef CONFIG_FUNCTION_TRACER 15ifdef CONFIG_FUNCTION_TRACER
16# Do not trace debug files and internal ftrace files 16# Do not trace debug files and internal ftrace files
@@ -25,6 +25,9 @@ endif
25obj-y += sched/ 25obj-y += sched/
26obj-y += power/ 26obj-y += power/
27 27
28ifeq ($(CONFIG_CHECKPOINT_RESTORE),y)
29obj-$(CONFIG_X86) += kcmp.o
30endif
28obj-$(CONFIG_FREEZER) += freezer.o 31obj-$(CONFIG_FREEZER) += freezer.o
29obj-$(CONFIG_PROFILING) += profile.o 32obj-$(CONFIG_PROFILING) += profile.o
30obj-$(CONFIG_STACKTRACE) += stacktrace.o 33obj-$(CONFIG_STACKTRACE) += stacktrace.o
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 0e6353cf147a..a4eb5227a19e 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -10,7 +10,10 @@
10#include <linux/sched.h> 10#include <linux/sched.h>
11#include <linux/unistd.h> 11#include <linux/unistd.h>
12#include <linux/cpu.h> 12#include <linux/cpu.h>
13#include <linux/oom.h>
14#include <linux/rcupdate.h>
13#include <linux/export.h> 15#include <linux/export.h>
16#include <linux/bug.h>
14#include <linux/kthread.h> 17#include <linux/kthread.h>
15#include <linux/stop_machine.h> 18#include <linux/stop_machine.h>
16#include <linux/mutex.h> 19#include <linux/mutex.h>
@@ -173,6 +176,47 @@ void __ref unregister_cpu_notifier(struct notifier_block *nb)
173} 176}
174EXPORT_SYMBOL(unregister_cpu_notifier); 177EXPORT_SYMBOL(unregister_cpu_notifier);
175 178
179/**
180 * clear_tasks_mm_cpumask - Safely clear tasks' mm_cpumask for a CPU
181 * @cpu: a CPU id
182 *
183 * This function walks all processes, finds a valid mm struct for each one and
184 * then clears a corresponding bit in mm's cpumask. While this all sounds
185 * trivial, there are various non-obvious corner cases, which this function
186 * tries to solve in a safe manner.
187 *
188 * Also note that the function uses a somewhat relaxed locking scheme, so it may
189 * be called only for an already offlined CPU.
190 */
191void clear_tasks_mm_cpumask(int cpu)
192{
193 struct task_struct *p;
194
195 /*
196 * This function is called after the cpu is taken down and marked
197 * offline, so its not like new tasks will ever get this cpu set in
198 * their mm mask. -- Peter Zijlstra
199 * Thus, we may use rcu_read_lock() here, instead of grabbing
200 * full-fledged tasklist_lock.
201 */
202 WARN_ON(cpu_online(cpu));
203 rcu_read_lock();
204 for_each_process(p) {
205 struct task_struct *t;
206
207 /*
208 * Main thread might exit, but other threads may still have
209 * a valid mm. Find one.
210 */
211 t = find_lock_task_mm(p);
212 if (!t)
213 continue;
214 cpumask_clear_cpu(cpu, mm_cpumask(t->mm));
215 task_unlock(t);
216 }
217 rcu_read_unlock();
218}
219
176static inline void check_for_tasks(int cpu) 220static inline void check_for_tasks(int cpu)
177{ 221{
178 struct task_struct *p; 222 struct task_struct *p;
diff --git a/kernel/cpu_pm.c b/kernel/cpu_pm.c
index 249152e15308..9656a3c36503 100644
--- a/kernel/cpu_pm.c
+++ b/kernel/cpu_pm.c
@@ -81,7 +81,7 @@ int cpu_pm_unregister_notifier(struct notifier_block *nb)
81EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier); 81EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier);
82 82
83/** 83/**
84 * cpm_pm_enter - CPU low power entry notifier 84 * cpu_pm_enter - CPU low power entry notifier
85 * 85 *
86 * Notifies listeners that a single CPU is entering a low power state that may 86 * Notifies listeners that a single CPU is entering a low power state that may
87 * cause some blocks in the same power domain as the cpu to reset. 87 * cause some blocks in the same power domain as the cpu to reset.
@@ -89,7 +89,7 @@ EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier);
89 * Must be called on the affected CPU with interrupts disabled. Platform is 89 * Must be called on the affected CPU with interrupts disabled. Platform is
90 * responsible for ensuring that cpu_pm_enter is not called twice on the same 90 * responsible for ensuring that cpu_pm_enter is not called twice on the same
91 * CPU before cpu_pm_exit is called. Notified drivers can include VFP 91 * CPU before cpu_pm_exit is called. Notified drivers can include VFP
92 * co-processor, interrupt controller and it's PM extensions, local CPU 92 * co-processor, interrupt controller and its PM extensions, local CPU
93 * timers context save/restore which shouldn't be interrupted. Hence it 93 * timers context save/restore which shouldn't be interrupted. Hence it
94 * must be called with interrupts disabled. 94 * must be called with interrupts disabled.
95 * 95 *
@@ -115,13 +115,13 @@ int cpu_pm_enter(void)
115EXPORT_SYMBOL_GPL(cpu_pm_enter); 115EXPORT_SYMBOL_GPL(cpu_pm_enter);
116 116
117/** 117/**
118 * cpm_pm_exit - CPU low power exit notifier 118 * cpu_pm_exit - CPU low power exit notifier
119 * 119 *
120 * Notifies listeners that a single CPU is exiting a low power state that may 120 * Notifies listeners that a single CPU is exiting a low power state that may
121 * have caused some blocks in the same power domain as the cpu to reset. 121 * have caused some blocks in the same power domain as the cpu to reset.
122 * 122 *
123 * Notified drivers can include VFP co-processor, interrupt controller 123 * Notified drivers can include VFP co-processor, interrupt controller
124 * and it's PM extensions, local CPU timers context save/restore which 124 * and its PM extensions, local CPU timers context save/restore which
125 * shouldn't be interrupted. Hence it must be called with interrupts disabled. 125 * shouldn't be interrupted. Hence it must be called with interrupts disabled.
126 * 126 *
127 * Return conditions are same as __raw_notifier_call_chain. 127 * Return conditions are same as __raw_notifier_call_chain.
@@ -139,7 +139,7 @@ int cpu_pm_exit(void)
139EXPORT_SYMBOL_GPL(cpu_pm_exit); 139EXPORT_SYMBOL_GPL(cpu_pm_exit);
140 140
141/** 141/**
142 * cpm_cluster_pm_enter - CPU cluster low power entry notifier 142 * cpu_cluster_pm_enter - CPU cluster low power entry notifier
143 * 143 *
144 * Notifies listeners that all cpus in a power domain are entering a low power 144 * Notifies listeners that all cpus in a power domain are entering a low power
145 * state that may cause some blocks in the same power domain to reset. 145 * state that may cause some blocks in the same power domain to reset.
@@ -147,7 +147,7 @@ EXPORT_SYMBOL_GPL(cpu_pm_exit);
147 * Must be called after cpu_pm_enter has been called on all cpus in the power 147 * Must be called after cpu_pm_enter has been called on all cpus in the power
148 * domain, and before cpu_pm_exit has been called on any cpu in the power 148 * domain, and before cpu_pm_exit has been called on any cpu in the power
149 * domain. Notified drivers can include VFP co-processor, interrupt controller 149 * domain. Notified drivers can include VFP co-processor, interrupt controller
150 * and it's PM extensions, local CPU timers context save/restore which 150 * and its PM extensions, local CPU timers context save/restore which
151 * shouldn't be interrupted. Hence it must be called with interrupts disabled. 151 * shouldn't be interrupted. Hence it must be called with interrupts disabled.
152 * 152 *
153 * Must be called with interrupts disabled. 153 * Must be called with interrupts disabled.
@@ -174,7 +174,7 @@ int cpu_cluster_pm_enter(void)
174EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter); 174EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);
175 175
176/** 176/**
177 * cpm_cluster_pm_exit - CPU cluster low power exit notifier 177 * cpu_cluster_pm_exit - CPU cluster low power exit notifier
178 * 178 *
179 * Notifies listeners that all cpus in a power domain are exiting form a 179 * Notifies listeners that all cpus in a power domain are exiting form a
180 * low power state that may have caused some blocks in the same power domain 180 * low power state that may have caused some blocks in the same power domain
@@ -183,7 +183,7 @@ EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);
183 * Must be called after cpu_pm_exit has been called on all cpus in the power 183 * Must be called after cpu_pm_exit has been called on all cpus in the power
184 * domain, and before cpu_pm_exit has been called on any cpu in the power 184 * domain, and before cpu_pm_exit has been called on any cpu in the power
185 * domain. Notified drivers can include VFP co-processor, interrupt controller 185 * domain. Notified drivers can include VFP co-processor, interrupt controller
186 * and it's PM extensions, local CPU timers context save/restore which 186 * and its PM extensions, local CPU timers context save/restore which
187 * shouldn't be interrupted. Hence it must be called with interrupts disabled. 187 * shouldn't be interrupted. Hence it must be called with interrupts disabled.
188 * 188 *
189 * Return conditions are same as __raw_notifier_call_chain. 189 * Return conditions are same as __raw_notifier_call_chain.
diff --git a/kernel/cred.c b/kernel/cred.c
index 430557ea488f..de728ac50d82 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -207,13 +207,6 @@ void exit_creds(struct task_struct *tsk)
207 validate_creds(cred); 207 validate_creds(cred);
208 alter_cred_subscribers(cred, -1); 208 alter_cred_subscribers(cred, -1);
209 put_cred(cred); 209 put_cred(cred);
210
211 cred = (struct cred *) tsk->replacement_session_keyring;
212 if (cred) {
213 tsk->replacement_session_keyring = NULL;
214 validate_creds(cred);
215 put_cred(cred);
216 }
217} 210}
218 211
219/** 212/**
@@ -396,8 +389,6 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
396 struct cred *new; 389 struct cred *new;
397 int ret; 390 int ret;
398 391
399 p->replacement_session_keyring = NULL;
400
401 if ( 392 if (
402#ifdef CONFIG_KEYS 393#ifdef CONFIG_KEYS
403 !p->cred->thread_keyring && 394 !p->cred->thread_keyring &&
diff --git a/kernel/exit.c b/kernel/exit.c
index 910a0716e17a..34867cc5b42a 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -884,9 +884,9 @@ static void check_stack_usage(void)
884 884
885 spin_lock(&low_water_lock); 885 spin_lock(&low_water_lock);
886 if (free < lowest_to_date) { 886 if (free < lowest_to_date) {
887 printk(KERN_WARNING "%s used greatest stack depth: %lu bytes " 887 printk(KERN_WARNING "%s (%d) used greatest stack depth: "
888 "left\n", 888 "%lu bytes left\n",
889 current->comm, free); 889 current->comm, task_pid_nr(current), free);
890 lowest_to_date = free; 890 lowest_to_date = free;
891 } 891 }
892 spin_unlock(&low_water_lock); 892 spin_unlock(&low_water_lock);
@@ -946,12 +946,13 @@ void do_exit(long code)
946 exit_signals(tsk); /* sets PF_EXITING */ 946 exit_signals(tsk); /* sets PF_EXITING */
947 /* 947 /*
948 * tsk->flags are checked in the futex code to protect against 948 * tsk->flags are checked in the futex code to protect against
949 * an exiting task cleaning up the robust pi futexes. 949 * an exiting task cleaning up the robust pi futexes, and in
950 * task_work_add() to avoid the race with exit_task_work().
950 */ 951 */
951 smp_mb(); 952 smp_mb();
952 raw_spin_unlock_wait(&tsk->pi_lock); 953 raw_spin_unlock_wait(&tsk->pi_lock);
953 954
954 exit_irq_thread(); 955 exit_task_work(tsk);
955 956
956 if (unlikely(in_atomic())) 957 if (unlikely(in_atomic()))
957 printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n", 958 printk(KERN_INFO "note: %s[%d] exited with preempt_count %d\n",
@@ -1214,7 +1215,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
1214 unsigned long state; 1215 unsigned long state;
1215 int retval, status, traced; 1216 int retval, status, traced;
1216 pid_t pid = task_pid_vnr(p); 1217 pid_t pid = task_pid_vnr(p);
1217 uid_t uid = from_kuid_munged(current_user_ns(), __task_cred(p)->uid); 1218 uid_t uid = from_kuid_munged(current_user_ns(), task_uid(p));
1218 struct siginfo __user *infop; 1219 struct siginfo __user *infop;
1219 1220
1220 if (!likely(wo->wo_flags & WEXITED)) 1221 if (!likely(wo->wo_flags & WEXITED))
diff --git a/kernel/fork.c b/kernel/fork.c
index 31a32c7dd169..ab5211b9e622 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -787,9 +787,6 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm)
787 /* Get rid of any cached register state */ 787 /* Get rid of any cached register state */
788 deactivate_mm(tsk, mm); 788 deactivate_mm(tsk, mm);
789 789
790 if (tsk->vfork_done)
791 complete_vfork_done(tsk);
792
793 /* 790 /*
794 * If we're exiting normally, clear a user-space tid field if 791 * If we're exiting normally, clear a user-space tid field if
795 * requested. We leave this alone when dying by signal, to leave 792 * requested. We leave this alone when dying by signal, to leave
@@ -810,6 +807,13 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm)
810 } 807 }
811 tsk->clear_child_tid = NULL; 808 tsk->clear_child_tid = NULL;
812 } 809 }
810
811 /*
812 * All done, finally we can wake up parent and return this mm to him.
813 * Also kthread_stop() uses this completion for synchronization.
814 */
815 if (tsk->vfork_done)
816 complete_vfork_done(tsk);
813} 817}
814 818
815/* 819/*
@@ -1411,6 +1415,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1411 */ 1415 */
1412 p->group_leader = p; 1416 p->group_leader = p;
1413 INIT_LIST_HEAD(&p->thread_group); 1417 INIT_LIST_HEAD(&p->thread_group);
1418 INIT_HLIST_HEAD(&p->task_works);
1414 1419
1415 /* Now that the task is set up, run cgroup callbacks if 1420 /* Now that the task is set up, run cgroup callbacks if
1416 * necessary. We need to run them before the task is visible 1421 * necessary. We need to run them before the task is visible
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index bb32326afe87..ea0c6c2ae6f7 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -7,6 +7,8 @@
7 * This file contains driver APIs to the irq subsystem. 7 * This file contains driver APIs to the irq subsystem.
8 */ 8 */
9 9
10#define pr_fmt(fmt) "genirq: " fmt
11
10#include <linux/irq.h> 12#include <linux/irq.h>
11#include <linux/kthread.h> 13#include <linux/kthread.h>
12#include <linux/module.h> 14#include <linux/module.h>
@@ -14,6 +16,7 @@
14#include <linux/interrupt.h> 16#include <linux/interrupt.h>
15#include <linux/slab.h> 17#include <linux/slab.h>
16#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linux/task_work.h>
17 20
18#include "internals.h" 21#include "internals.h"
19 22
@@ -565,7 +568,7 @@ int __irq_set_trigger(struct irq_desc *desc, unsigned int irq,
565 * IRQF_TRIGGER_* but the PIC does not support multiple 568 * IRQF_TRIGGER_* but the PIC does not support multiple
566 * flow-types? 569 * flow-types?
567 */ 570 */
568 pr_debug("genirq: No set_type function for IRQ %d (%s)\n", irq, 571 pr_debug("No set_type function for IRQ %d (%s)\n", irq,
569 chip ? (chip->name ? : "unknown") : "unknown"); 572 chip ? (chip->name ? : "unknown") : "unknown");
570 return 0; 573 return 0;
571 } 574 }
@@ -600,7 +603,7 @@ int __irq_set_trigger(struct irq_desc *desc, unsigned int irq,
600 ret = 0; 603 ret = 0;
601 break; 604 break;
602 default: 605 default:
603 pr_err("genirq: Setting trigger mode %lu for irq %u failed (%pF)\n", 606 pr_err("Setting trigger mode %lu for irq %u failed (%pF)\n",
604 flags, irq, chip->irq_set_type); 607 flags, irq, chip->irq_set_type);
605 } 608 }
606 if (unmask) 609 if (unmask)
@@ -773,11 +776,39 @@ static void wake_threads_waitq(struct irq_desc *desc)
773 wake_up(&desc->wait_for_threads); 776 wake_up(&desc->wait_for_threads);
774} 777}
775 778
779static void irq_thread_dtor(struct task_work *unused)
780{
781 struct task_struct *tsk = current;
782 struct irq_desc *desc;
783 struct irqaction *action;
784
785 if (WARN_ON_ONCE(!(current->flags & PF_EXITING)))
786 return;
787
788 action = kthread_data(tsk);
789
790 pr_err("exiting task \"%s\" (%d) is an active IRQ thread (irq %d)\n",
791 tsk->comm ? tsk->comm : "", tsk->pid, action->irq);
792
793
794 desc = irq_to_desc(action->irq);
795 /*
796 * If IRQTF_RUNTHREAD is set, we need to decrement
797 * desc->threads_active and wake possible waiters.
798 */
799 if (test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags))
800 wake_threads_waitq(desc);
801
802 /* Prevent a stale desc->threads_oneshot */
803 irq_finalize_oneshot(desc, action);
804}
805
776/* 806/*
777 * Interrupt handler thread 807 * Interrupt handler thread
778 */ 808 */
779static int irq_thread(void *data) 809static int irq_thread(void *data)
780{ 810{
811 struct task_work on_exit_work;
781 static const struct sched_param param = { 812 static const struct sched_param param = {
782 .sched_priority = MAX_USER_RT_PRIO/2, 813 .sched_priority = MAX_USER_RT_PRIO/2,
783 }; 814 };
@@ -793,7 +824,9 @@ static int irq_thread(void *data)
793 handler_fn = irq_thread_fn; 824 handler_fn = irq_thread_fn;
794 825
795 sched_setscheduler(current, SCHED_FIFO, &param); 826 sched_setscheduler(current, SCHED_FIFO, &param);
796 current->irq_thread = 1; 827
828 init_task_work(&on_exit_work, irq_thread_dtor, NULL);
829 task_work_add(current, &on_exit_work, false);
797 830
798 while (!irq_wait_for_interrupt(action)) { 831 while (!irq_wait_for_interrupt(action)) {
799 irqreturn_t action_ret; 832 irqreturn_t action_ret;
@@ -815,44 +848,11 @@ static int irq_thread(void *data)
815 * cannot touch the oneshot mask at this point anymore as 848 * cannot touch the oneshot mask at this point anymore as
816 * __setup_irq() might have given out currents thread_mask 849 * __setup_irq() might have given out currents thread_mask
817 * again. 850 * again.
818 *
819 * Clear irq_thread. Otherwise exit_irq_thread() would make
820 * fuzz about an active irq thread going into nirvana.
821 */ 851 */
822 current->irq_thread = 0; 852 task_work_cancel(current, irq_thread_dtor);
823 return 0; 853 return 0;
824} 854}
825 855
826/*
827 * Called from do_exit()
828 */
829void exit_irq_thread(void)
830{
831 struct task_struct *tsk = current;
832 struct irq_desc *desc;
833 struct irqaction *action;
834
835 if (!tsk->irq_thread)
836 return;
837
838 action = kthread_data(tsk);
839
840 pr_err("genirq: exiting task \"%s\" (%d) is an active IRQ thread (irq %d)\n",
841 tsk->comm ? tsk->comm : "", tsk->pid, action->irq);
842
843 desc = irq_to_desc(action->irq);
844
845 /*
846 * If IRQTF_RUNTHREAD is set, we need to decrement
847 * desc->threads_active and wake possible waiters.
848 */
849 if (test_and_clear_bit(IRQTF_RUNTHREAD, &action->thread_flags))
850 wake_threads_waitq(desc);
851
852 /* Prevent a stale desc->threads_oneshot */
853 irq_finalize_oneshot(desc, action);
854}
855
856static void irq_setup_forced_threading(struct irqaction *new) 856static void irq_setup_forced_threading(struct irqaction *new)
857{ 857{
858 if (!force_irqthreads) 858 if (!force_irqthreads)
@@ -1044,7 +1044,7 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
1044 * has. The type flags are unreliable as the 1044 * has. The type flags are unreliable as the
1045 * underlying chip implementation can override them. 1045 * underlying chip implementation can override them.
1046 */ 1046 */
1047 pr_err("genirq: Threaded irq requested with handler=NULL and !ONESHOT for irq %d\n", 1047 pr_err("Threaded irq requested with handler=NULL and !ONESHOT for irq %d\n",
1048 irq); 1048 irq);
1049 ret = -EINVAL; 1049 ret = -EINVAL;
1050 goto out_mask; 1050 goto out_mask;
@@ -1095,7 +1095,7 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
1095 1095
1096 if (nmsk != omsk) 1096 if (nmsk != omsk)
1097 /* hope the handler works with current trigger mode */ 1097 /* hope the handler works with current trigger mode */
1098 pr_warning("genirq: irq %d uses trigger mode %u; requested %u\n", 1098 pr_warning("irq %d uses trigger mode %u; requested %u\n",
1099 irq, nmsk, omsk); 1099 irq, nmsk, omsk);
1100 } 1100 }
1101 1101
@@ -1133,7 +1133,7 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
1133 1133
1134mismatch: 1134mismatch:
1135 if (!(new->flags & IRQF_PROBE_SHARED)) { 1135 if (!(new->flags & IRQF_PROBE_SHARED)) {
1136 pr_err("genirq: Flags mismatch irq %d. %08x (%s) vs. %08x (%s)\n", 1136 pr_err("Flags mismatch irq %d. %08x (%s) vs. %08x (%s)\n",
1137 irq, new->flags, new->name, old->flags, old->name); 1137 irq, new->flags, new->name, old->flags, old->name);
1138#ifdef CONFIG_DEBUG_SHIRQ 1138#ifdef CONFIG_DEBUG_SHIRQ
1139 dump_stack(); 1139 dump_stack();
diff --git a/kernel/kcmp.c b/kernel/kcmp.c
new file mode 100644
index 000000000000..30b7b225306c
--- /dev/null
+++ b/kernel/kcmp.c
@@ -0,0 +1,196 @@
1#include <linux/kernel.h>
2#include <linux/syscalls.h>
3#include <linux/fdtable.h>
4#include <linux/string.h>
5#include <linux/random.h>
6#include <linux/module.h>
7#include <linux/init.h>
8#include <linux/errno.h>
9#include <linux/cache.h>
10#include <linux/bug.h>
11#include <linux/err.h>
12#include <linux/kcmp.h>
13
14#include <asm/unistd.h>
15
16/*
17 * We don't expose the real in-memory order of objects for security reasons.
18 * But still the comparison results should be suitable for sorting. So we
19 * obfuscate kernel pointers values and compare the production instead.
20 *
21 * The obfuscation is done in two steps. First we xor the kernel pointer with
22 * a random value, which puts pointer into a new position in a reordered space.
23 * Secondly we multiply the xor production with a large odd random number to
24 * permute its bits even more (the odd multiplier guarantees that the product
25 * is unique ever after the high bits are truncated, since any odd number is
26 * relative prime to 2^n).
27 *
28 * Note also that the obfuscation itself is invisible to userspace and if needed
29 * it can be changed to an alternate scheme.
30 */
31static unsigned long cookies[KCMP_TYPES][2] __read_mostly;
32
33static long kptr_obfuscate(long v, int type)
34{
35 return (v ^ cookies[type][0]) * cookies[type][1];
36}
37
38/*
39 * 0 - equal, i.e. v1 = v2
40 * 1 - less than, i.e. v1 < v2
41 * 2 - greater than, i.e. v1 > v2
42 * 3 - not equal but ordering unavailable (reserved for future)
43 */
44static int kcmp_ptr(void *v1, void *v2, enum kcmp_type type)
45{
46 long ret;
47
48 ret = kptr_obfuscate((long)v1, type) - kptr_obfuscate((long)v2, type);
49
50 return (ret < 0) | ((ret > 0) << 1);
51}
52
53/* The caller must have pinned the task */
54static struct file *
55get_file_raw_ptr(struct task_struct *task, unsigned int idx)
56{
57 struct file *file = NULL;
58
59 task_lock(task);
60 rcu_read_lock();
61
62 if (task->files)
63 file = fcheck_files(task->files, idx);
64
65 rcu_read_unlock();
66 task_unlock(task);
67
68 return file;
69}
70
71static void kcmp_unlock(struct mutex *m1, struct mutex *m2)
72{
73 if (likely(m2 != m1))
74 mutex_unlock(m2);
75 mutex_unlock(m1);
76}
77
78static int kcmp_lock(struct mutex *m1, struct mutex *m2)
79{
80 int err;
81
82 if (m2 > m1)
83 swap(m1, m2);
84
85 err = mutex_lock_killable(m1);
86 if (!err && likely(m1 != m2)) {
87 err = mutex_lock_killable_nested(m2, SINGLE_DEPTH_NESTING);
88 if (err)
89 mutex_unlock(m1);
90 }
91
92 return err;
93}
94
95SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
96 unsigned long, idx1, unsigned long, idx2)
97{
98 struct task_struct *task1, *task2;
99 int ret;
100
101 rcu_read_lock();
102
103 /*
104 * Tasks are looked up in caller's PID namespace only.
105 */
106 task1 = find_task_by_vpid(pid1);
107 task2 = find_task_by_vpid(pid2);
108 if (!task1 || !task2)
109 goto err_no_task;
110
111 get_task_struct(task1);
112 get_task_struct(task2);
113
114 rcu_read_unlock();
115
116 /*
117 * One should have enough rights to inspect task details.
118 */
119 ret = kcmp_lock(&task1->signal->cred_guard_mutex,
120 &task2->signal->cred_guard_mutex);
121 if (ret)
122 goto err;
123 if (!ptrace_may_access(task1, PTRACE_MODE_READ) ||
124 !ptrace_may_access(task2, PTRACE_MODE_READ)) {
125 ret = -EPERM;
126 goto err_unlock;
127 }
128
129 switch (type) {
130 case KCMP_FILE: {
131 struct file *filp1, *filp2;
132
133 filp1 = get_file_raw_ptr(task1, idx1);
134 filp2 = get_file_raw_ptr(task2, idx2);
135
136 if (filp1 && filp2)
137 ret = kcmp_ptr(filp1, filp2, KCMP_FILE);
138 else
139 ret = -EBADF;
140 break;
141 }
142 case KCMP_VM:
143 ret = kcmp_ptr(task1->mm, task2->mm, KCMP_VM);
144 break;
145 case KCMP_FILES:
146 ret = kcmp_ptr(task1->files, task2->files, KCMP_FILES);
147 break;
148 case KCMP_FS:
149 ret = kcmp_ptr(task1->fs, task2->fs, KCMP_FS);
150 break;
151 case KCMP_SIGHAND:
152 ret = kcmp_ptr(task1->sighand, task2->sighand, KCMP_SIGHAND);
153 break;
154 case KCMP_IO:
155 ret = kcmp_ptr(task1->io_context, task2->io_context, KCMP_IO);
156 break;
157 case KCMP_SYSVSEM:
158#ifdef CONFIG_SYSVIPC
159 ret = kcmp_ptr(task1->sysvsem.undo_list,
160 task2->sysvsem.undo_list,
161 KCMP_SYSVSEM);
162#else
163 ret = -EOPNOTSUPP;
164#endif
165 break;
166 default:
167 ret = -EINVAL;
168 break;
169 }
170
171err_unlock:
172 kcmp_unlock(&task1->signal->cred_guard_mutex,
173 &task2->signal->cred_guard_mutex);
174err:
175 put_task_struct(task1);
176 put_task_struct(task2);
177
178 return ret;
179
180err_no_task:
181 rcu_read_unlock();
182 return -ESRCH;
183}
184
185static __init int kcmp_cookies_init(void)
186{
187 int i;
188
189 get_random_bytes(cookies, sizeof(cookies));
190
191 for (i = 0; i < KCMP_TYPES; i++)
192 cookies[i][1] |= (~(~0UL >> 1) | 1);
193
194 return 0;
195}
196arch_initcall(kcmp_cookies_init);
diff --git a/kernel/kmod.c b/kernel/kmod.c
index 05698a7415fe..ff2c7cb86d77 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -221,13 +221,12 @@ fail:
221 return 0; 221 return 0;
222} 222}
223 223
224void call_usermodehelper_freeinfo(struct subprocess_info *info) 224static void call_usermodehelper_freeinfo(struct subprocess_info *info)
225{ 225{
226 if (info->cleanup) 226 if (info->cleanup)
227 (*info->cleanup)(info); 227 (*info->cleanup)(info);
228 kfree(info); 228 kfree(info);
229} 229}
230EXPORT_SYMBOL(call_usermodehelper_freeinfo);
231 230
232static void umh_complete(struct subprocess_info *sub_info) 231static void umh_complete(struct subprocess_info *sub_info)
233{ 232{
@@ -410,7 +409,7 @@ EXPORT_SYMBOL_GPL(usermodehelper_read_unlock);
410 409
411/** 410/**
412 * __usermodehelper_set_disable_depth - Modify usermodehelper_disabled. 411 * __usermodehelper_set_disable_depth - Modify usermodehelper_disabled.
413 * depth: New value to assign to usermodehelper_disabled. 412 * @depth: New value to assign to usermodehelper_disabled.
414 * 413 *
415 * Change the value of usermodehelper_disabled (under umhelper_sem locked for 414 * Change the value of usermodehelper_disabled (under umhelper_sem locked for
416 * writing) and wakeup tasks waiting for it to change. 415 * writing) and wakeup tasks waiting for it to change.
@@ -479,6 +478,7 @@ static void helper_unlock(void)
479 * structure. This should be passed to call_usermodehelper_exec to 478 * structure. This should be passed to call_usermodehelper_exec to
480 * exec the process and free the structure. 479 * exec the process and free the structure.
481 */ 480 */
481static
482struct subprocess_info *call_usermodehelper_setup(char *path, char **argv, 482struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
483 char **envp, gfp_t gfp_mask) 483 char **envp, gfp_t gfp_mask)
484{ 484{
@@ -494,7 +494,6 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
494 out: 494 out:
495 return sub_info; 495 return sub_info;
496} 496}
497EXPORT_SYMBOL(call_usermodehelper_setup);
498 497
499/** 498/**
500 * call_usermodehelper_setfns - set a cleanup/init function 499 * call_usermodehelper_setfns - set a cleanup/init function
@@ -512,6 +511,7 @@ EXPORT_SYMBOL(call_usermodehelper_setup);
512 * Function must be runnable in either a process context or the 511 * Function must be runnable in either a process context or the
513 * context in which call_usermodehelper_exec is called. 512 * context in which call_usermodehelper_exec is called.
514 */ 513 */
514static
515void call_usermodehelper_setfns(struct subprocess_info *info, 515void call_usermodehelper_setfns(struct subprocess_info *info,
516 int (*init)(struct subprocess_info *info, struct cred *new), 516 int (*init)(struct subprocess_info *info, struct cred *new),
517 void (*cleanup)(struct subprocess_info *info), 517 void (*cleanup)(struct subprocess_info *info),
@@ -521,7 +521,6 @@ void call_usermodehelper_setfns(struct subprocess_info *info,
521 info->init = init; 521 info->init = init;
522 info->data = data; 522 info->data = data;
523} 523}
524EXPORT_SYMBOL(call_usermodehelper_setfns);
525 524
526/** 525/**
527 * call_usermodehelper_exec - start a usermode application 526 * call_usermodehelper_exec - start a usermode application
@@ -535,6 +534,7 @@ EXPORT_SYMBOL(call_usermodehelper_setfns);
535 * asynchronously if wait is not set, and runs as a child of keventd. 534 * asynchronously if wait is not set, and runs as a child of keventd.
536 * (ie. it runs with full root capabilities). 535 * (ie. it runs with full root capabilities).
537 */ 536 */
537static
538int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait) 538int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
539{ 539{
540 DECLARE_COMPLETION_ONSTACK(done); 540 DECLARE_COMPLETION_ONSTACK(done);
@@ -576,7 +576,25 @@ unlock:
576 helper_unlock(); 576 helper_unlock();
577 return retval; 577 return retval;
578} 578}
579EXPORT_SYMBOL(call_usermodehelper_exec); 579
580int call_usermodehelper_fns(
581 char *path, char **argv, char **envp, int wait,
582 int (*init)(struct subprocess_info *info, struct cred *new),
583 void (*cleanup)(struct subprocess_info *), void *data)
584{
585 struct subprocess_info *info;
586 gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
587
588 info = call_usermodehelper_setup(path, argv, envp, gfp_mask);
589
590 if (info == NULL)
591 return -ENOMEM;
592
593 call_usermodehelper_setfns(info, init, cleanup, data);
594
595 return call_usermodehelper_exec(info, wait);
596}
597EXPORT_SYMBOL(call_usermodehelper_fns);
580 598
581static int proc_cap_handler(struct ctl_table *table, int write, 599static int proc_cap_handler(struct ctl_table *table, int write,
582 void __user *buffer, size_t *lenp, loff_t *ppos) 600 void __user *buffer, size_t *lenp, loff_t *ppos)
diff --git a/kernel/lglock.c b/kernel/lglock.c
new file mode 100644
index 000000000000..6535a667a5a7
--- /dev/null
+++ b/kernel/lglock.c
@@ -0,0 +1,89 @@
1/* See include/linux/lglock.h for description */
2#include <linux/module.h>
3#include <linux/lglock.h>
4#include <linux/cpu.h>
5#include <linux/string.h>
6
7/*
8 * Note there is no uninit, so lglocks cannot be defined in
9 * modules (but it's fine to use them from there)
10 * Could be added though, just undo lg_lock_init
11 */
12
13void lg_lock_init(struct lglock *lg, char *name)
14{
15 LOCKDEP_INIT_MAP(&lg->lock_dep_map, name, &lg->lock_key, 0);
16}
17EXPORT_SYMBOL(lg_lock_init);
18
19void lg_local_lock(struct lglock *lg)
20{
21 arch_spinlock_t *lock;
22
23 preempt_disable();
24 rwlock_acquire_read(&lg->lock_dep_map, 0, 0, _RET_IP_);
25 lock = this_cpu_ptr(lg->lock);
26 arch_spin_lock(lock);
27}
28EXPORT_SYMBOL(lg_local_lock);
29
30void lg_local_unlock(struct lglock *lg)
31{
32 arch_spinlock_t *lock;
33
34 rwlock_release(&lg->lock_dep_map, 1, _RET_IP_);
35 lock = this_cpu_ptr(lg->lock);
36 arch_spin_unlock(lock);
37 preempt_enable();
38}
39EXPORT_SYMBOL(lg_local_unlock);
40
41void lg_local_lock_cpu(struct lglock *lg, int cpu)
42{
43 arch_spinlock_t *lock;
44
45 preempt_disable();
46 rwlock_acquire_read(&lg->lock_dep_map, 0, 0, _RET_IP_);
47 lock = per_cpu_ptr(lg->lock, cpu);
48 arch_spin_lock(lock);
49}
50EXPORT_SYMBOL(lg_local_lock_cpu);
51
52void lg_local_unlock_cpu(struct lglock *lg, int cpu)
53{
54 arch_spinlock_t *lock;
55
56 rwlock_release(&lg->lock_dep_map, 1, _RET_IP_);
57 lock = per_cpu_ptr(lg->lock, cpu);
58 arch_spin_unlock(lock);
59 preempt_enable();
60}
61EXPORT_SYMBOL(lg_local_unlock_cpu);
62
63void lg_global_lock(struct lglock *lg)
64{
65 int i;
66
67 preempt_disable();
68 rwlock_acquire(&lg->lock_dep_map, 0, 0, _RET_IP_);
69 for_each_possible_cpu(i) {
70 arch_spinlock_t *lock;
71 lock = per_cpu_ptr(lg->lock, i);
72 arch_spin_lock(lock);
73 }
74}
75EXPORT_SYMBOL(lg_global_lock);
76
77void lg_global_unlock(struct lglock *lg)
78{
79 int i;
80
81 rwlock_release(&lg->lock_dep_map, 1, _RET_IP_);
82 for_each_possible_cpu(i) {
83 arch_spinlock_t *lock;
84 lock = per_cpu_ptr(lg->lock, i);
85 arch_spin_unlock(lock);
86 }
87 preempt_enable();
88}
89EXPORT_SYMBOL(lg_global_unlock);
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 57bc1fd35b3c..16b20e38c4a1 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -149,7 +149,12 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
149{ 149{
150 int nr; 150 int nr;
151 int rc; 151 int rc;
152 struct task_struct *task; 152 struct task_struct *task, *me = current;
153
154 /* Ignore SIGCHLD causing any terminated children to autoreap */
155 spin_lock_irq(&me->sighand->siglock);
156 me->sighand->action[SIGCHLD - 1].sa.sa_handler = SIG_IGN;
157 spin_unlock_irq(&me->sighand->siglock);
153 158
154 /* 159 /*
155 * The last thread in the cgroup-init thread group is terminating. 160 * The last thread in the cgroup-init thread group is terminating.
@@ -191,6 +196,7 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
191 return; 196 return;
192} 197}
193 198
199#ifdef CONFIG_CHECKPOINT_RESTORE
194static int pid_ns_ctl_handler(struct ctl_table *table, int write, 200static int pid_ns_ctl_handler(struct ctl_table *table, int write,
195 void __user *buffer, size_t *lenp, loff_t *ppos) 201 void __user *buffer, size_t *lenp, loff_t *ppos)
196{ 202{
@@ -218,8 +224,8 @@ static struct ctl_table pid_ns_ctl_table[] = {
218 }, 224 },
219 { } 225 { }
220}; 226};
221
222static struct ctl_path kern_path[] = { { .procname = "kernel", }, { } }; 227static struct ctl_path kern_path[] = { { .procname = "kernel", }, { } };
228#endif /* CONFIG_CHECKPOINT_RESTORE */
223 229
224int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) 230int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
225{ 231{
@@ -253,7 +259,10 @@ int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
253static __init int pid_namespaces_init(void) 259static __init int pid_namespaces_init(void)
254{ 260{
255 pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC); 261 pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC);
262
263#ifdef CONFIG_CHECKPOINT_RESTORE
256 register_sysctl_paths(kern_path, pid_ns_ctl_table); 264 register_sysctl_paths(kern_path, pid_ns_ctl_table);
265#endif
257 return 0; 266 return 0;
258} 267}
259 268
diff --git a/kernel/resource.c b/kernel/resource.c
index 7e8ea66a8c01..e1d2b8ee76d5 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -515,8 +515,8 @@ out:
515 * @root: root resource descriptor 515 * @root: root resource descriptor
516 * @new: resource descriptor desired by caller 516 * @new: resource descriptor desired by caller
517 * @size: requested resource region size 517 * @size: requested resource region size
518 * @min: minimum size to allocate 518 * @min: minimum boundary to allocate
519 * @max: maximum size to allocate 519 * @max: maximum boundary to allocate
520 * @align: alignment requested, in bytes 520 * @align: alignment requested, in bytes
521 * @alignf: alignment function, optional, called if not NULL 521 * @alignf: alignment function, optional, called if not NULL
522 * @alignf_data: arbitrary data to pass to the @alignf function 522 * @alignf_data: arbitrary data to pass to the @alignf function
diff --git a/kernel/signal.c b/kernel/signal.c
index f7b418217633..677102789cf2 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1656,19 +1656,18 @@ bool do_notify_parent(struct task_struct *tsk, int sig)
1656 info.si_signo = sig; 1656 info.si_signo = sig;
1657 info.si_errno = 0; 1657 info.si_errno = 0;
1658 /* 1658 /*
1659 * we are under tasklist_lock here so our parent is tied to 1659 * We are under tasklist_lock here so our parent is tied to
1660 * us and cannot exit and release its namespace. 1660 * us and cannot change.
1661 * 1661 *
1662 * the only it can is to switch its nsproxy with sys_unshare, 1662 * task_active_pid_ns will always return the same pid namespace
1663 * bu uncharing pid namespaces is not allowed, so we'll always 1663 * until a task passes through release_task.
1664 * see relevant namespace
1665 * 1664 *
1666 * write_lock() currently calls preempt_disable() which is the 1665 * write_lock() currently calls preempt_disable() which is the
1667 * same as rcu_read_lock(), but according to Oleg, this is not 1666 * same as rcu_read_lock(), but according to Oleg, this is not
1668 * correct to rely on this 1667 * correct to rely on this
1669 */ 1668 */
1670 rcu_read_lock(); 1669 rcu_read_lock();
1671 info.si_pid = task_pid_nr_ns(tsk, tsk->parent->nsproxy->pid_ns); 1670 info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(tsk->parent));
1672 info.si_uid = from_kuid_munged(task_cred_xxx(tsk->parent, user_ns), 1671 info.si_uid = from_kuid_munged(task_cred_xxx(tsk->parent, user_ns),
1673 task_uid(tsk)); 1672 task_uid(tsk));
1674 rcu_read_unlock(); 1673 rcu_read_unlock();
@@ -2369,24 +2368,34 @@ relock:
2369} 2368}
2370 2369
2371/** 2370/**
2372 * block_sigmask - add @ka's signal mask to current->blocked 2371 * signal_delivered -
2373 * @ka: action for @signr 2372 * @sig: number of signal being delivered
2374 * @signr: signal that has been successfully delivered 2373 * @info: siginfo_t of signal being delivered
2374 * @ka: sigaction setting that chose the handler
2375 * @regs: user register state
2376 * @stepping: nonzero if debugger single-step or block-step in use
2375 * 2377 *
2376 * This function should be called when a signal has succesfully been 2378 * This function should be called when a signal has succesfully been
2377 * delivered. It adds the mask of signals for @ka to current->blocked 2379 * delivered. It updates the blocked signals accordingly (@ka->sa.sa_mask
2378 * so that they are blocked during the execution of the signal 2380 * is always blocked, and the signal itself is blocked unless %SA_NODEFER
2379 * handler. In addition, @signr will be blocked unless %SA_NODEFER is 2381 * is set in @ka->sa.sa_flags. Tracing is notified.
2380 * set in @ka->sa.sa_flags.
2381 */ 2382 */
2382void block_sigmask(struct k_sigaction *ka, int signr) 2383void signal_delivered(int sig, siginfo_t *info, struct k_sigaction *ka,
2384 struct pt_regs *regs, int stepping)
2383{ 2385{
2384 sigset_t blocked; 2386 sigset_t blocked;
2385 2387
2388 /* A signal was successfully delivered, and the
2389 saved sigmask was stored on the signal frame,
2390 and will be restored by sigreturn. So we can
2391 simply clear the restore sigmask flag. */
2392 clear_restore_sigmask();
2393
2386 sigorsets(&blocked, &current->blocked, &ka->sa.sa_mask); 2394 sigorsets(&blocked, &current->blocked, &ka->sa.sa_mask);
2387 if (!(ka->sa.sa_flags & SA_NODEFER)) 2395 if (!(ka->sa.sa_flags & SA_NODEFER))
2388 sigaddset(&blocked, signr); 2396 sigaddset(&blocked, sig);
2389 set_current_blocked(&blocked); 2397 set_current_blocked(&blocked);
2398 tracehook_signal_handler(sig, info, ka, regs, stepping);
2390} 2399}
2391 2400
2392/* 2401/*
@@ -2519,7 +2528,16 @@ static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset)
2519 * It is wrong to change ->blocked directly, this helper should be used 2528 * It is wrong to change ->blocked directly, this helper should be used
2520 * to ensure the process can't miss a shared signal we are going to block. 2529 * to ensure the process can't miss a shared signal we are going to block.
2521 */ 2530 */
2522void set_current_blocked(const sigset_t *newset) 2531void set_current_blocked(sigset_t *newset)
2532{
2533 struct task_struct *tsk = current;
2534 sigdelsetmask(newset, sigmask(SIGKILL) | sigmask(SIGSTOP));
2535 spin_lock_irq(&tsk->sighand->siglock);
2536 __set_task_blocked(tsk, newset);
2537 spin_unlock_irq(&tsk->sighand->siglock);
2538}
2539
2540void __set_current_blocked(const sigset_t *newset)
2523{ 2541{
2524 struct task_struct *tsk = current; 2542 struct task_struct *tsk = current;
2525 2543
@@ -2559,7 +2577,7 @@ int sigprocmask(int how, sigset_t *set, sigset_t *oldset)
2559 return -EINVAL; 2577 return -EINVAL;
2560 } 2578 }
2561 2579
2562 set_current_blocked(&newset); 2580 __set_current_blocked(&newset);
2563 return 0; 2581 return 0;
2564} 2582}
2565 2583
@@ -3133,7 +3151,7 @@ SYSCALL_DEFINE3(sigprocmask, int, how, old_sigset_t __user *, nset,
3133 return -EINVAL; 3151 return -EINVAL;
3134 } 3152 }
3135 3153
3136 set_current_blocked(&new_blocked); 3154 __set_current_blocked(&new_blocked);
3137 } 3155 }
3138 3156
3139 if (oset) { 3157 if (oset) {
@@ -3197,7 +3215,6 @@ SYSCALL_DEFINE1(ssetmask, int, newmask)
3197 int old = current->blocked.sig[0]; 3215 int old = current->blocked.sig[0];
3198 sigset_t newset; 3216 sigset_t newset;
3199 3217
3200 siginitset(&newset, newmask & ~(sigmask(SIGKILL) | sigmask(SIGSTOP)));
3201 set_current_blocked(&newset); 3218 set_current_blocked(&newset);
3202 3219
3203 return old; 3220 return old;
@@ -3236,11 +3253,8 @@ SYSCALL_DEFINE0(pause)
3236 3253
3237#endif 3254#endif
3238 3255
3239#ifdef HAVE_SET_RESTORE_SIGMASK
3240int sigsuspend(sigset_t *set) 3256int sigsuspend(sigset_t *set)
3241{ 3257{
3242 sigdelsetmask(set, sigmask(SIGKILL)|sigmask(SIGSTOP));
3243
3244 current->saved_sigmask = current->blocked; 3258 current->saved_sigmask = current->blocked;
3245 set_current_blocked(set); 3259 set_current_blocked(set);
3246 3260
@@ -3249,7 +3263,6 @@ int sigsuspend(sigset_t *set)
3249 set_restore_sigmask(); 3263 set_restore_sigmask();
3250 return -ERESTARTNOHAND; 3264 return -ERESTARTNOHAND;
3251} 3265}
3252#endif
3253 3266
3254#ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND 3267#ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND
3255/** 3268/**
diff --git a/kernel/sys.c b/kernel/sys.c
index 6df42624e454..9ff89cb9657a 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -36,6 +36,8 @@
36#include <linux/personality.h> 36#include <linux/personality.h>
37#include <linux/ptrace.h> 37#include <linux/ptrace.h>
38#include <linux/fs_struct.h> 38#include <linux/fs_struct.h>
39#include <linux/file.h>
40#include <linux/mount.h>
39#include <linux/gfp.h> 41#include <linux/gfp.h>
40#include <linux/syscore_ops.h> 42#include <linux/syscore_ops.h>
41#include <linux/version.h> 43#include <linux/version.h>
@@ -1378,8 +1380,8 @@ SYSCALL_DEFINE2(sethostname, char __user *, name, int, len)
1378 memcpy(u->nodename, tmp, len); 1380 memcpy(u->nodename, tmp, len);
1379 memset(u->nodename + len, 0, sizeof(u->nodename) - len); 1381 memset(u->nodename + len, 0, sizeof(u->nodename) - len);
1380 errno = 0; 1382 errno = 0;
1383 uts_proc_notify(UTS_PROC_HOSTNAME);
1381 } 1384 }
1382 uts_proc_notify(UTS_PROC_HOSTNAME);
1383 up_write(&uts_sem); 1385 up_write(&uts_sem);
1384 return errno; 1386 return errno;
1385} 1387}
@@ -1429,8 +1431,8 @@ SYSCALL_DEFINE2(setdomainname, char __user *, name, int, len)
1429 memcpy(u->domainname, tmp, len); 1431 memcpy(u->domainname, tmp, len);
1430 memset(u->domainname + len, 0, sizeof(u->domainname) - len); 1432 memset(u->domainname + len, 0, sizeof(u->domainname) - len);
1431 errno = 0; 1433 errno = 0;
1434 uts_proc_notify(UTS_PROC_DOMAINNAME);
1432 } 1435 }
1433 uts_proc_notify(UTS_PROC_DOMAINNAME);
1434 up_write(&uts_sem); 1436 up_write(&uts_sem);
1435 return errno; 1437 return errno;
1436} 1438}
@@ -1784,77 +1786,102 @@ SYSCALL_DEFINE1(umask, int, mask)
1784} 1786}
1785 1787
1786#ifdef CONFIG_CHECKPOINT_RESTORE 1788#ifdef CONFIG_CHECKPOINT_RESTORE
1789static bool vma_flags_mismatch(struct vm_area_struct *vma,
1790 unsigned long required,
1791 unsigned long banned)
1792{
1793 return (vma->vm_flags & required) != required ||
1794 (vma->vm_flags & banned);
1795}
1796
1797static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)
1798{
1799 struct file *exe_file;
1800 struct dentry *dentry;
1801 int err;
1802
1803 /*
1804 * Setting new mm::exe_file is only allowed when no VM_EXECUTABLE vma's
1805 * remain. So perform a quick test first.
1806 */
1807 if (mm->num_exe_file_vmas)
1808 return -EBUSY;
1809
1810 exe_file = fget(fd);
1811 if (!exe_file)
1812 return -EBADF;
1813
1814 dentry = exe_file->f_path.dentry;
1815
1816 /*
1817 * Because the original mm->exe_file points to executable file, make
1818 * sure that this one is executable as well, to avoid breaking an
1819 * overall picture.
1820 */
1821 err = -EACCES;
1822 if (!S_ISREG(dentry->d_inode->i_mode) ||
1823 exe_file->f_path.mnt->mnt_flags & MNT_NOEXEC)
1824 goto exit;
1825
1826 err = inode_permission(dentry->d_inode, MAY_EXEC);
1827 if (err)
1828 goto exit;
1829
1830 /*
1831 * The symlink can be changed only once, just to disallow arbitrary
1832 * transitions malicious software might bring in. This means one
1833 * could make a snapshot over all processes running and monitor
1834 * /proc/pid/exe changes to notice unusual activity if needed.
1835 */
1836 down_write(&mm->mmap_sem);
1837 if (likely(!mm->exe_file))
1838 set_mm_exe_file(mm, exe_file);
1839 else
1840 err = -EBUSY;
1841 up_write(&mm->mmap_sem);
1842
1843exit:
1844 fput(exe_file);
1845 return err;
1846}
1847
1787static int prctl_set_mm(int opt, unsigned long addr, 1848static int prctl_set_mm(int opt, unsigned long addr,
1788 unsigned long arg4, unsigned long arg5) 1849 unsigned long arg4, unsigned long arg5)
1789{ 1850{
1790 unsigned long rlim = rlimit(RLIMIT_DATA); 1851 unsigned long rlim = rlimit(RLIMIT_DATA);
1791 unsigned long vm_req_flags;
1792 unsigned long vm_bad_flags;
1793 struct vm_area_struct *vma;
1794 int error = 0;
1795 struct mm_struct *mm = current->mm; 1852 struct mm_struct *mm = current->mm;
1853 struct vm_area_struct *vma;
1854 int error;
1796 1855
1797 if (arg4 | arg5) 1856 if (arg5 || (arg4 && opt != PR_SET_MM_AUXV))
1798 return -EINVAL; 1857 return -EINVAL;
1799 1858
1800 if (!capable(CAP_SYS_RESOURCE)) 1859 if (!capable(CAP_SYS_RESOURCE))
1801 return -EPERM; 1860 return -EPERM;
1802 1861
1862 if (opt == PR_SET_MM_EXE_FILE)
1863 return prctl_set_mm_exe_file(mm, (unsigned int)addr);
1864
1803 if (addr >= TASK_SIZE) 1865 if (addr >= TASK_SIZE)
1804 return -EINVAL; 1866 return -EINVAL;
1805 1867
1868 error = -EINVAL;
1869
1806 down_read(&mm->mmap_sem); 1870 down_read(&mm->mmap_sem);
1807 vma = find_vma(mm, addr); 1871 vma = find_vma(mm, addr);
1808 1872
1809 if (opt != PR_SET_MM_START_BRK && opt != PR_SET_MM_BRK) {
1810 /* It must be existing VMA */
1811 if (!vma || vma->vm_start > addr)
1812 goto out;
1813 }
1814
1815 error = -EINVAL;
1816 switch (opt) { 1873 switch (opt) {
1817 case PR_SET_MM_START_CODE: 1874 case PR_SET_MM_START_CODE:
1875 mm->start_code = addr;
1876 break;
1818 case PR_SET_MM_END_CODE: 1877 case PR_SET_MM_END_CODE:
1819 vm_req_flags = VM_READ | VM_EXEC; 1878 mm->end_code = addr;
1820 vm_bad_flags = VM_WRITE | VM_MAYSHARE;
1821
1822 if ((vma->vm_flags & vm_req_flags) != vm_req_flags ||
1823 (vma->vm_flags & vm_bad_flags))
1824 goto out;
1825
1826 if (opt == PR_SET_MM_START_CODE)
1827 mm->start_code = addr;
1828 else
1829 mm->end_code = addr;
1830 break; 1879 break;
1831
1832 case PR_SET_MM_START_DATA: 1880 case PR_SET_MM_START_DATA:
1833 case PR_SET_MM_END_DATA: 1881 mm->start_data = addr;
1834 vm_req_flags = VM_READ | VM_WRITE;
1835 vm_bad_flags = VM_EXEC | VM_MAYSHARE;
1836
1837 if ((vma->vm_flags & vm_req_flags) != vm_req_flags ||
1838 (vma->vm_flags & vm_bad_flags))
1839 goto out;
1840
1841 if (opt == PR_SET_MM_START_DATA)
1842 mm->start_data = addr;
1843 else
1844 mm->end_data = addr;
1845 break; 1882 break;
1846 1883 case PR_SET_MM_END_DATA:
1847 case PR_SET_MM_START_STACK: 1884 mm->end_data = addr;
1848
1849#ifdef CONFIG_STACK_GROWSUP
1850 vm_req_flags = VM_READ | VM_WRITE | VM_GROWSUP;
1851#else
1852 vm_req_flags = VM_READ | VM_WRITE | VM_GROWSDOWN;
1853#endif
1854 if ((vma->vm_flags & vm_req_flags) != vm_req_flags)
1855 goto out;
1856
1857 mm->start_stack = addr;
1858 break; 1885 break;
1859 1886
1860 case PR_SET_MM_START_BRK: 1887 case PR_SET_MM_START_BRK:
@@ -1881,16 +1908,77 @@ static int prctl_set_mm(int opt, unsigned long addr,
1881 mm->brk = addr; 1908 mm->brk = addr;
1882 break; 1909 break;
1883 1910
1911 /*
1912 * If command line arguments and environment
1913 * are placed somewhere else on stack, we can
1914 * set them up here, ARG_START/END to setup
1915 * command line argumets and ENV_START/END
1916 * for environment.
1917 */
1918 case PR_SET_MM_START_STACK:
1919 case PR_SET_MM_ARG_START:
1920 case PR_SET_MM_ARG_END:
1921 case PR_SET_MM_ENV_START:
1922 case PR_SET_MM_ENV_END:
1923 if (!vma) {
1924 error = -EFAULT;
1925 goto out;
1926 }
1927#ifdef CONFIG_STACK_GROWSUP
1928 if (vma_flags_mismatch(vma, VM_READ | VM_WRITE | VM_GROWSUP, 0))
1929#else
1930 if (vma_flags_mismatch(vma, VM_READ | VM_WRITE | VM_GROWSDOWN, 0))
1931#endif
1932 goto out;
1933 if (opt == PR_SET_MM_START_STACK)
1934 mm->start_stack = addr;
1935 else if (opt == PR_SET_MM_ARG_START)
1936 mm->arg_start = addr;
1937 else if (opt == PR_SET_MM_ARG_END)
1938 mm->arg_end = addr;
1939 else if (opt == PR_SET_MM_ENV_START)
1940 mm->env_start = addr;
1941 else if (opt == PR_SET_MM_ENV_END)
1942 mm->env_end = addr;
1943 break;
1944
1945 /*
1946 * This doesn't move auxiliary vector itself
1947 * since it's pinned to mm_struct, but allow
1948 * to fill vector with new values. It's up
1949 * to a caller to provide sane values here
1950 * otherwise user space tools which use this
1951 * vector might be unhappy.
1952 */
1953 case PR_SET_MM_AUXV: {
1954 unsigned long user_auxv[AT_VECTOR_SIZE];
1955
1956 if (arg4 > sizeof(user_auxv))
1957 goto out;
1958 up_read(&mm->mmap_sem);
1959
1960 if (copy_from_user(user_auxv, (const void __user *)addr, arg4))
1961 return -EFAULT;
1962
1963 /* Make sure the last entry is always AT_NULL */
1964 user_auxv[AT_VECTOR_SIZE - 2] = 0;
1965 user_auxv[AT_VECTOR_SIZE - 1] = 0;
1966
1967 BUILD_BUG_ON(sizeof(user_auxv) != sizeof(mm->saved_auxv));
1968
1969 task_lock(current);
1970 memcpy(mm->saved_auxv, user_auxv, arg4);
1971 task_unlock(current);
1972
1973 return 0;
1974 }
1884 default: 1975 default:
1885 error = -EINVAL;
1886 goto out; 1976 goto out;
1887 } 1977 }
1888 1978
1889 error = 0; 1979 error = 0;
1890
1891out: 1980out:
1892 up_read(&mm->mmap_sem); 1981 up_read(&mm->mmap_sem);
1893
1894 return error; 1982 return error;
1895} 1983}
1896#else /* CONFIG_CHECKPOINT_RESTORE */ 1984#else /* CONFIG_CHECKPOINT_RESTORE */
@@ -2114,7 +2202,6 @@ int orderly_poweroff(bool force)
2114 NULL 2202 NULL
2115 }; 2203 };
2116 int ret = -ENOMEM; 2204 int ret = -ENOMEM;
2117 struct subprocess_info *info;
2118 2205
2119 if (argv == NULL) { 2206 if (argv == NULL) {
2120 printk(KERN_WARNING "%s failed to allocate memory for \"%s\"\n", 2207 printk(KERN_WARNING "%s failed to allocate memory for \"%s\"\n",
@@ -2122,18 +2209,16 @@ int orderly_poweroff(bool force)
2122 goto out; 2209 goto out;
2123 } 2210 }
2124 2211
2125 info = call_usermodehelper_setup(argv[0], argv, envp, GFP_ATOMIC); 2212 ret = call_usermodehelper_fns(argv[0], argv, envp, UMH_NO_WAIT,
2126 if (info == NULL) { 2213 NULL, argv_cleanup, NULL);
2127 argv_free(argv); 2214out:
2128 goto out; 2215 if (likely(!ret))
2129 } 2216 return 0;
2130
2131 call_usermodehelper_setfns(info, NULL, argv_cleanup, NULL);
2132 2217
2133 ret = call_usermodehelper_exec(info, UMH_NO_WAIT); 2218 if (ret == -ENOMEM)
2219 argv_free(argv);
2134 2220
2135 out: 2221 if (force) {
2136 if (ret && force) {
2137 printk(KERN_WARNING "Failed to start orderly shutdown: " 2222 printk(KERN_WARNING "Failed to start orderly shutdown: "
2138 "forcing the issue\n"); 2223 "forcing the issue\n");
2139 2224
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 47bfa16430d7..dbff751e4086 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -203,3 +203,6 @@ cond_syscall(sys_fanotify_mark);
203cond_syscall(sys_name_to_handle_at); 203cond_syscall(sys_name_to_handle_at);
204cond_syscall(sys_open_by_handle_at); 204cond_syscall(sys_open_by_handle_at);
205cond_syscall(compat_sys_open_by_handle_at); 205cond_syscall(compat_sys_open_by_handle_at);
206
207/* compare kernel pointers */
208cond_syscall(sys_kcmp);
diff --git a/kernel/task_work.c b/kernel/task_work.c
new file mode 100644
index 000000000000..82d1c794066d
--- /dev/null
+++ b/kernel/task_work.c
@@ -0,0 +1,84 @@
1#include <linux/spinlock.h>
2#include <linux/task_work.h>
3#include <linux/tracehook.h>
4
5int
6task_work_add(struct task_struct *task, struct task_work *twork, bool notify)
7{
8 unsigned long flags;
9 int err = -ESRCH;
10
11#ifndef TIF_NOTIFY_RESUME
12 if (notify)
13 return -ENOTSUPP;
14#endif
15 /*
16 * We must not insert the new work if the task has already passed
17 * exit_task_work(). We rely on do_exit()->raw_spin_unlock_wait()
18 * and check PF_EXITING under pi_lock.
19 */
20 raw_spin_lock_irqsave(&task->pi_lock, flags);
21 if (likely(!(task->flags & PF_EXITING))) {
22 hlist_add_head(&twork->hlist, &task->task_works);
23 err = 0;
24 }
25 raw_spin_unlock_irqrestore(&task->pi_lock, flags);
26
27 /* test_and_set_bit() implies mb(), see tracehook_notify_resume(). */
28 if (likely(!err) && notify)
29 set_notify_resume(task);
30 return err;
31}
32
33struct task_work *
34task_work_cancel(struct task_struct *task, task_work_func_t func)
35{
36 unsigned long flags;
37 struct task_work *twork;
38 struct hlist_node *pos;
39
40 raw_spin_lock_irqsave(&task->pi_lock, flags);
41 hlist_for_each_entry(twork, pos, &task->task_works, hlist) {
42 if (twork->func == func) {
43 hlist_del(&twork->hlist);
44 goto found;
45 }
46 }
47 twork = NULL;
48 found:
49 raw_spin_unlock_irqrestore(&task->pi_lock, flags);
50
51 return twork;
52}
53
54void task_work_run(void)
55{
56 struct task_struct *task = current;
57 struct hlist_head task_works;
58 struct hlist_node *pos;
59
60 raw_spin_lock_irq(&task->pi_lock);
61 hlist_move_list(&task->task_works, &task_works);
62 raw_spin_unlock_irq(&task->pi_lock);
63
64 if (unlikely(hlist_empty(&task_works)))
65 return;
66 /*
67 * We use hlist to save the space in task_struct, but we want fifo.
68 * Find the last entry, the list should be short, then process them
69 * in reverse order.
70 */
71 for (pos = task_works.first; pos->next; pos = pos->next)
72 ;
73
74 for (;;) {
75 struct hlist_node **pprev = pos->pprev;
76 struct task_work *twork = container_of(pos, struct task_work,
77 hlist);
78 twork->func(twork);
79
80 if (pprev == &task_works.first)
81 break;
82 pos = container_of(pprev, struct hlist_node, next);
83 }
84}
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 5391299c1e78..c3f36d415bdf 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -112,106 +112,199 @@ int skip_atoi(const char **s)
112/* Decimal conversion is by far the most typical, and is used 112/* Decimal conversion is by far the most typical, and is used
113 * for /proc and /sys data. This directly impacts e.g. top performance 113 * for /proc and /sys data. This directly impacts e.g. top performance
114 * with many processes running. We optimize it for speed 114 * with many processes running. We optimize it for speed
115 * using code from 115 * using ideas described at <http://www.cs.uiowa.edu/~jones/bcd/divide.html>
116 * http://www.cs.uiowa.edu/~jones/bcd/decimal.html 116 * (with permission from the author, Douglas W. Jones).
117 * (with permission from the author, Douglas W. Jones). */ 117 */
118 118
119/* Formats correctly any integer in [0,99999]. 119#if BITS_PER_LONG != 32 || BITS_PER_LONG_LONG != 64
120 * Outputs from one to five digits depending on input. 120/* Formats correctly any integer in [0, 999999999] */
121 * On i386 gcc 4.1.2 -O2: ~250 bytes of code. */
122static noinline_for_stack 121static noinline_for_stack
123char *put_dec_trunc(char *buf, unsigned q) 122char *put_dec_full9(char *buf, unsigned q)
124{ 123{
125 unsigned d3, d2, d1, d0; 124 unsigned r;
126 d1 = (q>>4) & 0xf;
127 d2 = (q>>8) & 0xf;
128 d3 = (q>>12);
129
130 d0 = 6*(d3 + d2 + d1) + (q & 0xf);
131 q = (d0 * 0xcd) >> 11;
132 d0 = d0 - 10*q;
133 *buf++ = d0 + '0'; /* least significant digit */
134 d1 = q + 9*d3 + 5*d2 + d1;
135 if (d1 != 0) {
136 q = (d1 * 0xcd) >> 11;
137 d1 = d1 - 10*q;
138 *buf++ = d1 + '0'; /* next digit */
139
140 d2 = q + 2*d2;
141 if ((d2 != 0) || (d3 != 0)) {
142 q = (d2 * 0xd) >> 7;
143 d2 = d2 - 10*q;
144 *buf++ = d2 + '0'; /* next digit */
145
146 d3 = q + 4*d3;
147 if (d3 != 0) {
148 q = (d3 * 0xcd) >> 11;
149 d3 = d3 - 10*q;
150 *buf++ = d3 + '0'; /* next digit */
151 if (q != 0)
152 *buf++ = q + '0'; /* most sign. digit */
153 }
154 }
155 }
156 125
126 /*
127 * Possible ways to approx. divide by 10
128 * (x * 0x1999999a) >> 32 x < 1073741829 (multiply must be 64-bit)
129 * (x * 0xcccd) >> 19 x < 81920 (x < 262149 when 64-bit mul)
130 * (x * 0x6667) >> 18 x < 43699
131 * (x * 0x3334) >> 17 x < 16389
132 * (x * 0x199a) >> 16 x < 16389
133 * (x * 0x0ccd) >> 15 x < 16389
134 * (x * 0x0667) >> 14 x < 2739
135 * (x * 0x0334) >> 13 x < 1029
136 * (x * 0x019a) >> 12 x < 1029
137 * (x * 0x00cd) >> 11 x < 1029 shorter code than * 0x67 (on i386)
138 * (x * 0x0067) >> 10 x < 179
139 * (x * 0x0034) >> 9 x < 69 same
140 * (x * 0x001a) >> 8 x < 69 same
141 * (x * 0x000d) >> 7 x < 69 same, shortest code (on i386)
142 * (x * 0x0007) >> 6 x < 19
143 * See <http://www.cs.uiowa.edu/~jones/bcd/divide.html>
144 */
145 r = (q * (uint64_t)0x1999999a) >> 32;
146 *buf++ = (q - 10 * r) + '0'; /* 1 */
147 q = (r * (uint64_t)0x1999999a) >> 32;
148 *buf++ = (r - 10 * q) + '0'; /* 2 */
149 r = (q * (uint64_t)0x1999999a) >> 32;
150 *buf++ = (q - 10 * r) + '0'; /* 3 */
151 q = (r * (uint64_t)0x1999999a) >> 32;
152 *buf++ = (r - 10 * q) + '0'; /* 4 */
153 r = (q * (uint64_t)0x1999999a) >> 32;
154 *buf++ = (q - 10 * r) + '0'; /* 5 */
155 /* Now value is under 10000, can avoid 64-bit multiply */
156 q = (r * 0x199a) >> 16;
157 *buf++ = (r - 10 * q) + '0'; /* 6 */
158 r = (q * 0xcd) >> 11;
159 *buf++ = (q - 10 * r) + '0'; /* 7 */
160 q = (r * 0xcd) >> 11;
161 *buf++ = (r - 10 * q) + '0'; /* 8 */
162 *buf++ = q + '0'; /* 9 */
157 return buf; 163 return buf;
158} 164}
159/* Same with if's removed. Always emits five digits */ 165#endif
166
167/* Similar to above but do not pad with zeros.
168 * Code can be easily arranged to print 9 digits too, but our callers
169 * always call put_dec_full9() instead when the number has 9 decimal digits.
170 */
160static noinline_for_stack 171static noinline_for_stack
161char *put_dec_full(char *buf, unsigned q) 172char *put_dec_trunc8(char *buf, unsigned r)
162{ 173{
163 /* BTW, if q is in [0,9999], 8-bit ints will be enough, */ 174 unsigned q;
164 /* but anyway, gcc produces better code with full-sized ints */ 175
165 unsigned d3, d2, d1, d0; 176 /* Copy of previous function's body with added early returns */
166 d1 = (q>>4) & 0xf; 177 q = (r * (uint64_t)0x1999999a) >> 32;
167 d2 = (q>>8) & 0xf; 178 *buf++ = (r - 10 * q) + '0'; /* 2 */
168 d3 = (q>>12); 179 if (q == 0)
180 return buf;
181 r = (q * (uint64_t)0x1999999a) >> 32;
182 *buf++ = (q - 10 * r) + '0'; /* 3 */
183 if (r == 0)
184 return buf;
185 q = (r * (uint64_t)0x1999999a) >> 32;
186 *buf++ = (r - 10 * q) + '0'; /* 4 */
187 if (q == 0)
188 return buf;
189 r = (q * (uint64_t)0x1999999a) >> 32;
190 *buf++ = (q - 10 * r) + '0'; /* 5 */
191 if (r == 0)
192 return buf;
193 q = (r * 0x199a) >> 16;
194 *buf++ = (r - 10 * q) + '0'; /* 6 */
195 if (q == 0)
196 return buf;
197 r = (q * 0xcd) >> 11;
198 *buf++ = (q - 10 * r) + '0'; /* 7 */
199 if (r == 0)
200 return buf;
201 q = (r * 0xcd) >> 11;
202 *buf++ = (r - 10 * q) + '0'; /* 8 */
203 if (q == 0)
204 return buf;
205 *buf++ = q + '0'; /* 9 */
206 return buf;
207}
169 208
170 /* 209/* There are two algorithms to print larger numbers.
171 * Possible ways to approx. divide by 10 210 * One is generic: divide by 1000000000 and repeatedly print
172 * gcc -O2 replaces multiply with shifts and adds 211 * groups of (up to) 9 digits. It's conceptually simple,
173 * (x * 0xcd) >> 11: 11001101 - shorter code than * 0x67 (on i386) 212 * but requires a (unsigned long long) / 1000000000 division.
174 * (x * 0x67) >> 10: 1100111 213 *
175 * (x * 0x34) >> 9: 110100 - same 214 * Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
176 * (x * 0x1a) >> 8: 11010 - same 215 * manipulates them cleverly and generates groups of 4 decimal digits.
177 * (x * 0x0d) >> 7: 1101 - same, shortest code (on i386) 216 * It so happens that it does NOT require long long division.
178 */ 217 *
179 d0 = 6*(d3 + d2 + d1) + (q & 0xf); 218 * If long is > 32 bits, division of 64-bit values is relatively easy,
180 q = (d0 * 0xcd) >> 11; 219 * and we will use the first algorithm.
181 d0 = d0 - 10*q; 220 * If long long is > 64 bits (strange architecture with VERY large long long),
182 *buf++ = d0 + '0'; 221 * second algorithm can't be used, and we again use the first one.
183 d1 = q + 9*d3 + 5*d2 + d1; 222 *
184 q = (d1 * 0xcd) >> 11; 223 * Else (if long is 32 bits and long long is 64 bits) we use second one.
185 d1 = d1 - 10*q; 224 */
186 *buf++ = d1 + '0';
187
188 d2 = q + 2*d2;
189 q = (d2 * 0xd) >> 7;
190 d2 = d2 - 10*q;
191 *buf++ = d2 + '0';
192
193 d3 = q + 4*d3;
194 q = (d3 * 0xcd) >> 11; /* - shorter code */
195 /* q = (d3 * 0x67) >> 10; - would also work */
196 d3 = d3 - 10*q;
197 *buf++ = d3 + '0';
198 *buf++ = q + '0';
199 225
200 return buf; 226#if BITS_PER_LONG != 32 || BITS_PER_LONG_LONG != 64
227
228/* First algorithm: generic */
229
230static
231char *put_dec(char *buf, unsigned long long n)
232{
233 if (n >= 100*1000*1000) {
234 while (n >= 1000*1000*1000)
235 buf = put_dec_full9(buf, do_div(n, 1000*1000*1000));
236 if (n >= 100*1000*1000)
237 return put_dec_full9(buf, n);
238 }
239 return put_dec_trunc8(buf, n);
201} 240}
202/* No inlining helps gcc to use registers better */ 241
242#else
243
244/* Second algorithm: valid only for 64-bit long longs */
245
203static noinline_for_stack 246static noinline_for_stack
204char *put_dec(char *buf, unsigned long long num) 247char *put_dec_full4(char *buf, unsigned q)
205{ 248{
206 while (1) { 249 unsigned r;
207 unsigned rem; 250 r = (q * 0xcccd) >> 19;
208 if (num < 100000) 251 *buf++ = (q - 10 * r) + '0';
209 return put_dec_trunc(buf, num); 252 q = (r * 0x199a) >> 16;
210 rem = do_div(num, 100000); 253 *buf++ = (r - 10 * q) + '0';
211 buf = put_dec_full(buf, rem); 254 r = (q * 0xcd) >> 11;
212 } 255 *buf++ = (q - 10 * r) + '0';
256 *buf++ = r + '0';
257 return buf;
213} 258}
214 259
260/* Based on code by Douglas W. Jones found at
261 * <http://www.cs.uiowa.edu/~jones/bcd/decimal.html#sixtyfour>
262 * (with permission from the author).
263 * Performs no 64-bit division and hence should be fast on 32-bit machines.
264 */
265static
266char *put_dec(char *buf, unsigned long long n)
267{
268 uint32_t d3, d2, d1, q, h;
269
270 if (n < 100*1000*1000)
271 return put_dec_trunc8(buf, n);
272
273 d1 = ((uint32_t)n >> 16); /* implicit "& 0xffff" */
274 h = (n >> 32);
275 d2 = (h ) & 0xffff;
276 d3 = (h >> 16); /* implicit "& 0xffff" */
277
278 q = 656 * d3 + 7296 * d2 + 5536 * d1 + ((uint32_t)n & 0xffff);
279
280 buf = put_dec_full4(buf, q % 10000);
281 q = q / 10000;
282
283 d1 = q + 7671 * d3 + 9496 * d2 + 6 * d1;
284 buf = put_dec_full4(buf, d1 % 10000);
285 q = d1 / 10000;
286
287 d2 = q + 4749 * d3 + 42 * d2;
288 buf = put_dec_full4(buf, d2 % 10000);
289 q = d2 / 10000;
290
291 d3 = q + 281 * d3;
292 if (!d3)
293 goto done;
294 buf = put_dec_full4(buf, d3 % 10000);
295 q = d3 / 10000;
296 if (!q)
297 goto done;
298 buf = put_dec_full4(buf, q);
299 done:
300 while (buf[-1] == '0')
301 --buf;
302
303 return buf;
304}
305
306#endif
307
215/* 308/*
216 * Convert passed number to decimal string. 309 * Convert passed number to decimal string.
217 * Returns the length of string. On buffer overflow, returns 0. 310 * Returns the length of string. On buffer overflow, returns 0.
@@ -220,16 +313,22 @@ char *put_dec(char *buf, unsigned long long num)
220 */ 313 */
221int num_to_str(char *buf, int size, unsigned long long num) 314int num_to_str(char *buf, int size, unsigned long long num)
222{ 315{
223 char tmp[21]; /* Enough for 2^64 in decimal */ 316 char tmp[sizeof(num) * 3];
224 int idx, len; 317 int idx, len;
225 318
226 len = put_dec(tmp, num) - tmp; 319 /* put_dec() may work incorrectly for num = 0 (generate "", not "0") */
320 if (num <= 9) {
321 tmp[0] = '0' + num;
322 len = 1;
323 } else {
324 len = put_dec(tmp, num) - tmp;
325 }
227 326
228 if (len > size) 327 if (len > size)
229 return 0; 328 return 0;
230 for (idx = 0; idx < len; ++idx) 329 for (idx = 0; idx < len; ++idx)
231 buf[idx] = tmp[len - idx - 1]; 330 buf[idx] = tmp[len - idx - 1];
232 return len; 331 return len;
233} 332}
234 333
235#define ZEROPAD 1 /* pad with zero */ 334#define ZEROPAD 1 /* pad with zero */
@@ -314,8 +413,8 @@ char *number(char *buf, char *end, unsigned long long num,
314 413
315 /* generate full string in tmp[], in reverse order */ 414 /* generate full string in tmp[], in reverse order */
316 i = 0; 415 i = 0;
317 if (num == 0) 416 if (num < spec.base)
318 tmp[i++] = '0'; 417 tmp[i++] = digits[num] | locase;
319 /* Generic code, for any base: 418 /* Generic code, for any base:
320 else do { 419 else do {
321 tmp[i++] = (digits[do_div(num,base)] | locase); 420 tmp[i++] = (digits[do_div(num,base)] | locase);
@@ -611,7 +710,7 @@ char *ip4_string(char *p, const u8 *addr, const char *fmt)
611 } 710 }
612 for (i = 0; i < 4; i++) { 711 for (i = 0; i < 4; i++) {
613 char temp[3]; /* hold each IP quad in reverse order */ 712 char temp[3]; /* hold each IP quad in reverse order */
614 int digits = put_dec_trunc(temp, addr[index]) - temp; 713 int digits = put_dec_trunc8(temp, addr[index]) - temp;
615 if (leading_zeros) { 714 if (leading_zeros) {
616 if (digits < 3) 715 if (digits < 3)
617 *p++ = '0'; 716 *p++ = '0';
@@ -870,13 +969,15 @@ static noinline_for_stack
870char *pointer(const char *fmt, char *buf, char *end, void *ptr, 969char *pointer(const char *fmt, char *buf, char *end, void *ptr,
871 struct printf_spec spec) 970 struct printf_spec spec)
872{ 971{
972 int default_width = 2 * sizeof(void *) + (spec.flags & SPECIAL ? 2 : 0);
973
873 if (!ptr && *fmt != 'K') { 974 if (!ptr && *fmt != 'K') {
874 /* 975 /*
875 * Print (null) with the same width as a pointer so it makes 976 * Print (null) with the same width as a pointer so it makes
876 * tabular output look nice. 977 * tabular output look nice.
877 */ 978 */
878 if (spec.field_width == -1) 979 if (spec.field_width == -1)
879 spec.field_width = 2 * sizeof(void *); 980 spec.field_width = default_width;
880 return string(buf, end, "(null)", spec); 981 return string(buf, end, "(null)", spec);
881 } 982 }
882 983
@@ -931,7 +1032,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
931 */ 1032 */
932 if (in_irq() || in_serving_softirq() || in_nmi()) { 1033 if (in_irq() || in_serving_softirq() || in_nmi()) {
933 if (spec.field_width == -1) 1034 if (spec.field_width == -1)
934 spec.field_width = 2 * sizeof(void *); 1035 spec.field_width = default_width;
935 return string(buf, end, "pK-error", spec); 1036 return string(buf, end, "pK-error", spec);
936 } 1037 }
937 if (!((kptr_restrict == 0) || 1038 if (!((kptr_restrict == 0) ||
@@ -948,7 +1049,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
948 } 1049 }
949 spec.flags |= SMALL; 1050 spec.flags |= SMALL;
950 if (spec.field_width == -1) { 1051 if (spec.field_width == -1) {
951 spec.field_width = 2 * sizeof(void *); 1052 spec.field_width = default_width;
952 spec.flags |= ZEROPAD; 1053 spec.flags |= ZEROPAD;
953 } 1054 }
954 spec.base = 16; 1055 spec.base = 16;
diff --git a/mm/cleancache.c b/mm/cleancache.c
index 5646c740f613..32e6f4136fa2 100644
--- a/mm/cleancache.c
+++ b/mm/cleancache.c
@@ -80,7 +80,7 @@ EXPORT_SYMBOL(__cleancache_init_shared_fs);
80static int cleancache_get_key(struct inode *inode, 80static int cleancache_get_key(struct inode *inode,
81 struct cleancache_filekey *key) 81 struct cleancache_filekey *key)
82{ 82{
83 int (*fhfn)(struct dentry *, __u32 *fh, int *, int); 83 int (*fhfn)(struct inode *, __u32 *fh, int *, struct inode *);
84 int len = 0, maxlen = CLEANCACHE_KEY_MAX; 84 int len = 0, maxlen = CLEANCACHE_KEY_MAX;
85 struct super_block *sb = inode->i_sb; 85 struct super_block *sb = inode->i_sb;
86 86
@@ -88,9 +88,7 @@ static int cleancache_get_key(struct inode *inode,
88 if (sb->s_export_op != NULL) { 88 if (sb->s_export_op != NULL) {
89 fhfn = sb->s_export_op->encode_fh; 89 fhfn = sb->s_export_op->encode_fh;
90 if (fhfn) { 90 if (fhfn) {
91 struct dentry d; 91 len = (*fhfn)(inode, &key->u.fh[0], &maxlen, NULL);
92 d.d_inode = inode;
93 len = (*fhfn)(&d, &key->u.fh[0], &maxlen, 0);
94 if (len <= 0 || len == 255) 92 if (len <= 0 || len == 255)
95 return -1; 93 return -1;
96 if (maxlen > CLEANCACHE_KEY_MAX) 94 if (maxlen > CLEANCACHE_KEY_MAX)
diff --git a/mm/filemap.c b/mm/filemap.c
index 64b48f934b89..a4a5260b0279 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1899,71 +1899,6 @@ struct page *read_cache_page(struct address_space *mapping,
1899} 1899}
1900EXPORT_SYMBOL(read_cache_page); 1900EXPORT_SYMBOL(read_cache_page);
1901 1901
1902/*
1903 * The logic we want is
1904 *
1905 * if suid or (sgid and xgrp)
1906 * remove privs
1907 */
1908int should_remove_suid(struct dentry *dentry)
1909{
1910 umode_t mode = dentry->d_inode->i_mode;
1911 int kill = 0;
1912
1913 /* suid always must be killed */
1914 if (unlikely(mode & S_ISUID))
1915 kill = ATTR_KILL_SUID;
1916
1917 /*
1918 * sgid without any exec bits is just a mandatory locking mark; leave
1919 * it alone. If some exec bits are set, it's a real sgid; kill it.
1920 */
1921 if (unlikely((mode & S_ISGID) && (mode & S_IXGRP)))
1922 kill |= ATTR_KILL_SGID;
1923
1924 if (unlikely(kill && !capable(CAP_FSETID) && S_ISREG(mode)))
1925 return kill;
1926
1927 return 0;
1928}
1929EXPORT_SYMBOL(should_remove_suid);
1930
1931static int __remove_suid(struct dentry *dentry, int kill)
1932{
1933 struct iattr newattrs;
1934
1935 newattrs.ia_valid = ATTR_FORCE | kill;
1936 return notify_change(dentry, &newattrs);
1937}
1938
1939int file_remove_suid(struct file *file)
1940{
1941 struct dentry *dentry = file->f_path.dentry;
1942 struct inode *inode = dentry->d_inode;
1943 int killsuid;
1944 int killpriv;
1945 int error = 0;
1946
1947 /* Fast path for nothing security related */
1948 if (IS_NOSEC(inode))
1949 return 0;
1950
1951 killsuid = should_remove_suid(dentry);
1952 killpriv = security_inode_need_killpriv(dentry);
1953
1954 if (killpriv < 0)
1955 return killpriv;
1956 if (killpriv)
1957 error = security_inode_killpriv(dentry);
1958 if (!error && killsuid)
1959 error = __remove_suid(dentry, killsuid);
1960 if (!error && (inode->i_sb->s_flags & MS_NOSEC))
1961 inode->i_flags |= S_NOSEC;
1962
1963 return error;
1964}
1965EXPORT_SYMBOL(file_remove_suid);
1966
1967static size_t __iovec_copy_from_user_inatomic(char *vaddr, 1902static size_t __iovec_copy_from_user_inatomic(char *vaddr,
1968 const struct iovec *iov, size_t base, size_t bytes) 1903 const struct iovec *iov, size_t base, size_t bytes)
1969{ 1904{
@@ -2489,7 +2424,9 @@ ssize_t __generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
2489 if (err) 2424 if (err)
2490 goto out; 2425 goto out;
2491 2426
2492 file_update_time(file); 2427 err = file_update_time(file);
2428 if (err)
2429 goto out;
2493 2430
2494 /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */ 2431 /* coalesce the iovecs and go direct-to-BIO for O_DIRECT */
2495 if (unlikely(file->f_flags & O_DIRECT)) { 2432 if (unlikely(file->f_flags & O_DIRECT)) {
diff --git a/mm/filemap_xip.c b/mm/filemap_xip.c
index a4eb31132229..213ca1f53409 100644
--- a/mm/filemap_xip.c
+++ b/mm/filemap_xip.c
@@ -426,7 +426,9 @@ xip_file_write(struct file *filp, const char __user *buf, size_t len,
426 if (ret) 426 if (ret)
427 goto out_backing; 427 goto out_backing;
428 428
429 file_update_time(filp); 429 ret = file_update_time(filp);
430 if (ret)
431 goto out_backing;
430 432
431 ret = __xip_file_write (filp, buf, count, pos, ppos); 433 ret = __xip_file_write (filp, buf, count, pos, ppos);
432 434
diff --git a/mm/internal.h b/mm/internal.h
index 4194ab9dc19b..5cbb78190041 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -350,3 +350,7 @@ extern u64 hwpoison_filter_flags_mask;
350extern u64 hwpoison_filter_flags_value; 350extern u64 hwpoison_filter_flags_value;
351extern u64 hwpoison_filter_memcg; 351extern u64 hwpoison_filter_memcg;
352extern u32 hwpoison_filter_enable; 352extern u32 hwpoison_filter_enable;
353
354extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
355 unsigned long, unsigned long,
356 unsigned long, unsigned long);
diff --git a/mm/mmap.c b/mm/mmap.c
index 4a9c2a391e28..3edfcdfa42d9 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -971,15 +971,13 @@ static inline unsigned long round_hint_to_min(unsigned long hint)
971 * The caller must hold down_write(&current->mm->mmap_sem). 971 * The caller must hold down_write(&current->mm->mmap_sem).
972 */ 972 */
973 973
974static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr, 974unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
975 unsigned long len, unsigned long prot, 975 unsigned long len, unsigned long prot,
976 unsigned long flags, unsigned long pgoff) 976 unsigned long flags, unsigned long pgoff)
977{ 977{
978 struct mm_struct * mm = current->mm; 978 struct mm_struct * mm = current->mm;
979 struct inode *inode; 979 struct inode *inode;
980 vm_flags_t vm_flags; 980 vm_flags_t vm_flags;
981 int error;
982 unsigned long reqprot = prot;
983 981
984 /* 982 /*
985 * Does the application expect PROT_READ to imply PROT_EXEC? 983 * Does the application expect PROT_READ to imply PROT_EXEC?
@@ -1101,39 +1099,9 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
1101 } 1099 }
1102 } 1100 }
1103 1101
1104 error = security_file_mmap(file, reqprot, prot, flags, addr, 0);
1105 if (error)
1106 return error;
1107
1108 return mmap_region(file, addr, len, flags, vm_flags, pgoff); 1102 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
1109} 1103}
1110 1104
1111unsigned long do_mmap(struct file *file, unsigned long addr,
1112 unsigned long len, unsigned long prot,
1113 unsigned long flag, unsigned long offset)
1114{
1115 if (unlikely(offset + PAGE_ALIGN(len) < offset))
1116 return -EINVAL;
1117 if (unlikely(offset & ~PAGE_MASK))
1118 return -EINVAL;
1119 return do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
1120}
1121EXPORT_SYMBOL(do_mmap);
1122
1123unsigned long vm_mmap(struct file *file, unsigned long addr,
1124 unsigned long len, unsigned long prot,
1125 unsigned long flag, unsigned long offset)
1126{
1127 unsigned long ret;
1128 struct mm_struct *mm = current->mm;
1129
1130 down_write(&mm->mmap_sem);
1131 ret = do_mmap(file, addr, len, prot, flag, offset);
1132 up_write(&mm->mmap_sem);
1133 return ret;
1134}
1135EXPORT_SYMBOL(vm_mmap);
1136
1137SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, 1105SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
1138 unsigned long, prot, unsigned long, flags, 1106 unsigned long, prot, unsigned long, flags,
1139 unsigned long, fd, unsigned long, pgoff) 1107 unsigned long, fd, unsigned long, pgoff)
@@ -1165,10 +1133,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
1165 1133
1166 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); 1134 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1167 1135
1168 down_write(&current->mm->mmap_sem); 1136 retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1169 retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1170 up_write(&current->mm->mmap_sem);
1171
1172 if (file) 1137 if (file)
1173 fput(file); 1138 fput(file);
1174out: 1139out:
@@ -1629,7 +1594,9 @@ get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
1629 if (addr & ~PAGE_MASK) 1594 if (addr & ~PAGE_MASK)
1630 return -EINVAL; 1595 return -EINVAL;
1631 1596
1632 return arch_rebalance_pgtables(addr, len); 1597 addr = arch_rebalance_pgtables(addr, len);
1598 error = security_mmap_addr(addr);
1599 return error ? error : addr;
1633} 1600}
1634 1601
1635EXPORT_SYMBOL(get_unmapped_area); 1602EXPORT_SYMBOL(get_unmapped_area);
@@ -1819,7 +1786,7 @@ int expand_downwards(struct vm_area_struct *vma,
1819 return -ENOMEM; 1786 return -ENOMEM;
1820 1787
1821 address &= PAGE_MASK; 1788 address &= PAGE_MASK;
1822 error = security_file_mmap(NULL, 0, 0, 0, address, 1); 1789 error = security_mmap_addr(address);
1823 if (error) 1790 if (error)
1824 return error; 1791 return error;
1825 1792
@@ -2159,7 +2126,6 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
2159 2126
2160 return 0; 2127 return 0;
2161} 2128}
2162EXPORT_SYMBOL(do_munmap);
2163 2129
2164int vm_munmap(unsigned long start, size_t len) 2130int vm_munmap(unsigned long start, size_t len)
2165{ 2131{
@@ -2207,10 +2173,6 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
2207 if (!len) 2173 if (!len)
2208 return addr; 2174 return addr;
2209 2175
2210 error = security_file_mmap(NULL, 0, 0, 0, addr, 1);
2211 if (error)
2212 return error;
2213
2214 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags; 2176 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
2215 2177
2216 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED); 2178 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
@@ -2563,10 +2525,6 @@ int install_special_mapping(struct mm_struct *mm,
2563 vma->vm_ops = &special_mapping_vmops; 2525 vma->vm_ops = &special_mapping_vmops;
2564 vma->vm_private_data = pages; 2526 vma->vm_private_data = pages;
2565 2527
2566 ret = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
2567 if (ret)
2568 goto out;
2569
2570 ret = insert_vm_struct(mm, vma); 2528 ret = insert_vm_struct(mm, vma);
2571 if (ret) 2529 if (ret)
2572 goto out; 2530 goto out;
diff --git a/mm/mremap.c b/mm/mremap.c
index db8d983b5a7d..21fed202ddad 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -371,10 +371,6 @@ static unsigned long mremap_to(unsigned long addr,
371 if ((addr <= new_addr) && (addr+old_len) > new_addr) 371 if ((addr <= new_addr) && (addr+old_len) > new_addr)
372 goto out; 372 goto out;
373 373
374 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
375 if (ret)
376 goto out;
377
378 ret = do_munmap(mm, new_addr, new_len); 374 ret = do_munmap(mm, new_addr, new_len);
379 if (ret) 375 if (ret)
380 goto out; 376 goto out;
@@ -432,15 +428,17 @@ static int vma_expandable(struct vm_area_struct *vma, unsigned long delta)
432 * MREMAP_FIXED option added 5-Dec-1999 by Benjamin LaHaise 428 * MREMAP_FIXED option added 5-Dec-1999 by Benjamin LaHaise
433 * This option implies MREMAP_MAYMOVE. 429 * This option implies MREMAP_MAYMOVE.
434 */ 430 */
435unsigned long do_mremap(unsigned long addr, 431SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
436 unsigned long old_len, unsigned long new_len, 432 unsigned long, new_len, unsigned long, flags,
437 unsigned long flags, unsigned long new_addr) 433 unsigned long, new_addr)
438{ 434{
439 struct mm_struct *mm = current->mm; 435 struct mm_struct *mm = current->mm;
440 struct vm_area_struct *vma; 436 struct vm_area_struct *vma;
441 unsigned long ret = -EINVAL; 437 unsigned long ret = -EINVAL;
442 unsigned long charged = 0; 438 unsigned long charged = 0;
443 439
440 down_write(&current->mm->mmap_sem);
441
444 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE)) 442 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
445 goto out; 443 goto out;
446 444
@@ -530,25 +528,11 @@ unsigned long do_mremap(unsigned long addr,
530 goto out; 528 goto out;
531 } 529 }
532 530
533 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
534 if (ret)
535 goto out;
536 ret = move_vma(vma, addr, old_len, new_len, new_addr); 531 ret = move_vma(vma, addr, old_len, new_len, new_addr);
537 } 532 }
538out: 533out:
539 if (ret & ~PAGE_MASK) 534 if (ret & ~PAGE_MASK)
540 vm_unacct_memory(charged); 535 vm_unacct_memory(charged);
541 return ret;
542}
543
544SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
545 unsigned long, new_len, unsigned long, flags,
546 unsigned long, new_addr)
547{
548 unsigned long ret;
549
550 down_write(&current->mm->mmap_sem);
551 ret = do_mremap(addr, old_len, new_len, flags, new_addr);
552 up_write(&current->mm->mmap_sem); 536 up_write(&current->mm->mmap_sem);
553 return ret; 537 return ret;
554} 538}
diff --git a/mm/nommu.c b/mm/nommu.c
index bb8f4f004a82..c4acfbc09972 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -889,7 +889,6 @@ static int validate_mmap_request(struct file *file,
889 unsigned long *_capabilities) 889 unsigned long *_capabilities)
890{ 890{
891 unsigned long capabilities, rlen; 891 unsigned long capabilities, rlen;
892 unsigned long reqprot = prot;
893 int ret; 892 int ret;
894 893
895 /* do the simple checks first */ 894 /* do the simple checks first */
@@ -1047,7 +1046,7 @@ static int validate_mmap_request(struct file *file,
1047 } 1046 }
1048 1047
1049 /* allow the security API to have its say */ 1048 /* allow the security API to have its say */
1050 ret = security_file_mmap(file, reqprot, prot, flags, addr, 0); 1049 ret = security_mmap_addr(addr);
1051 if (ret < 0) 1050 if (ret < 0)
1052 return ret; 1051 return ret;
1053 1052
@@ -1233,7 +1232,7 @@ enomem:
1233/* 1232/*
1234 * handle mapping creation for uClinux 1233 * handle mapping creation for uClinux
1235 */ 1234 */
1236static unsigned long do_mmap_pgoff(struct file *file, 1235unsigned long do_mmap_pgoff(struct file *file,
1237 unsigned long addr, 1236 unsigned long addr,
1238 unsigned long len, 1237 unsigned long len,
1239 unsigned long prot, 1238 unsigned long prot,
@@ -1471,32 +1470,6 @@ error_getting_region:
1471 return -ENOMEM; 1470 return -ENOMEM;
1472} 1471}
1473 1472
1474unsigned long do_mmap(struct file *file, unsigned long addr,
1475 unsigned long len, unsigned long prot,
1476 unsigned long flag, unsigned long offset)
1477{
1478 if (unlikely(offset + PAGE_ALIGN(len) < offset))
1479 return -EINVAL;
1480 if (unlikely(offset & ~PAGE_MASK))
1481 return -EINVAL;
1482 return do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
1483}
1484EXPORT_SYMBOL(do_mmap);
1485
1486unsigned long vm_mmap(struct file *file, unsigned long addr,
1487 unsigned long len, unsigned long prot,
1488 unsigned long flag, unsigned long offset)
1489{
1490 unsigned long ret;
1491 struct mm_struct *mm = current->mm;
1492
1493 down_write(&mm->mmap_sem);
1494 ret = do_mmap(file, addr, len, prot, flag, offset);
1495 up_write(&mm->mmap_sem);
1496 return ret;
1497}
1498EXPORT_SYMBOL(vm_mmap);
1499
1500SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len, 1473SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
1501 unsigned long, prot, unsigned long, flags, 1474 unsigned long, prot, unsigned long, flags,
1502 unsigned long, fd, unsigned long, pgoff) 1475 unsigned long, fd, unsigned long, pgoff)
@@ -1513,9 +1486,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
1513 1486
1514 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); 1487 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1515 1488
1516 down_write(&current->mm->mmap_sem); 1489 ret = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1517 retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1518 up_write(&current->mm->mmap_sem);
1519 1490
1520 if (file) 1491 if (file)
1521 fput(file); 1492 fput(file);
diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
index c20ff48994c2..926b46649749 100644
--- a/mm/process_vm_access.c
+++ b/mm/process_vm_access.c
@@ -371,15 +371,15 @@ static ssize_t process_vm_rw(pid_t pid,
371 /* Check iovecs */ 371 /* Check iovecs */
372 if (vm_write) 372 if (vm_write)
373 rc = rw_copy_check_uvector(WRITE, lvec, liovcnt, UIO_FASTIOV, 373 rc = rw_copy_check_uvector(WRITE, lvec, liovcnt, UIO_FASTIOV,
374 iovstack_l, &iov_l, 1); 374 iovstack_l, &iov_l);
375 else 375 else
376 rc = rw_copy_check_uvector(READ, lvec, liovcnt, UIO_FASTIOV, 376 rc = rw_copy_check_uvector(READ, lvec, liovcnt, UIO_FASTIOV,
377 iovstack_l, &iov_l, 1); 377 iovstack_l, &iov_l);
378 if (rc <= 0) 378 if (rc <= 0)
379 goto free_iovecs; 379 goto free_iovecs;
380 380
381 rc = rw_copy_check_uvector(READ, rvec, riovcnt, UIO_FASTIOV, 381 rc = rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, UIO_FASTIOV,
382 iovstack_r, &iov_r, 0); 382 iovstack_r, &iov_r);
383 if (rc <= 0) 383 if (rc <= 0)
384 goto free_iovecs; 384 goto free_iovecs;
385 385
@@ -438,16 +438,16 @@ compat_process_vm_rw(compat_pid_t pid,
438 if (vm_write) 438 if (vm_write)
439 rc = compat_rw_copy_check_uvector(WRITE, lvec, liovcnt, 439 rc = compat_rw_copy_check_uvector(WRITE, lvec, liovcnt,
440 UIO_FASTIOV, iovstack_l, 440 UIO_FASTIOV, iovstack_l,
441 &iov_l, 1); 441 &iov_l);
442 else 442 else
443 rc = compat_rw_copy_check_uvector(READ, lvec, liovcnt, 443 rc = compat_rw_copy_check_uvector(READ, lvec, liovcnt,
444 UIO_FASTIOV, iovstack_l, 444 UIO_FASTIOV, iovstack_l,
445 &iov_l, 1); 445 &iov_l);
446 if (rc <= 0) 446 if (rc <= 0)
447 goto free_iovecs; 447 goto free_iovecs;
448 rc = compat_rw_copy_check_uvector(READ, rvec, riovcnt, 448 rc = compat_rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt,
449 UIO_FASTIOV, iovstack_r, 449 UIO_FASTIOV, iovstack_r,
450 &iov_r, 0); 450 &iov_r);
451 if (rc <= 0) 451 if (rc <= 0)
452 goto free_iovecs; 452 goto free_iovecs;
453 453
diff --git a/mm/shmem.c b/mm/shmem.c
index d576b84d913c..585bd220a21e 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2439,11 +2439,9 @@ static struct dentry *shmem_fh_to_dentry(struct super_block *sb,
2439 return dentry; 2439 return dentry;
2440} 2440}
2441 2441
2442static int shmem_encode_fh(struct dentry *dentry, __u32 *fh, int *len, 2442static int shmem_encode_fh(struct inode *inode, __u32 *fh, int *len,
2443 int connectable) 2443 struct inode *parent)
2444{ 2444{
2445 struct inode *inode = dentry->d_inode;
2446
2447 if (*len < 3) { 2445 if (*len < 3) {
2448 *len = 3; 2446 *len = 3;
2449 return 255; 2447 return 255;
diff --git a/mm/slub.c b/mm/slub.c
index 80848cd3901c..8c691fa1cf3c 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1369,7 +1369,7 @@ static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
1369 1369
1370 inc_slabs_node(s, page_to_nid(page), page->objects); 1370 inc_slabs_node(s, page_to_nid(page), page->objects);
1371 page->slab = s; 1371 page->slab = s;
1372 page->flags |= 1 << PG_slab; 1372 __SetPageSlab(page);
1373 1373
1374 start = page_address(page); 1374 start = page_address(page);
1375 1375
@@ -1514,15 +1514,19 @@ static inline void *acquire_slab(struct kmem_cache *s,
1514 freelist = page->freelist; 1514 freelist = page->freelist;
1515 counters = page->counters; 1515 counters = page->counters;
1516 new.counters = counters; 1516 new.counters = counters;
1517 if (mode) 1517 if (mode) {
1518 new.inuse = page->objects; 1518 new.inuse = page->objects;
1519 new.freelist = NULL;
1520 } else {
1521 new.freelist = freelist;
1522 }
1519 1523
1520 VM_BUG_ON(new.frozen); 1524 VM_BUG_ON(new.frozen);
1521 new.frozen = 1; 1525 new.frozen = 1;
1522 1526
1523 } while (!__cmpxchg_double_slab(s, page, 1527 } while (!__cmpxchg_double_slab(s, page,
1524 freelist, counters, 1528 freelist, counters,
1525 NULL, new.counters, 1529 new.freelist, new.counters,
1526 "lock and freeze")); 1530 "lock and freeze"));
1527 1531
1528 remove_partial(n, page); 1532 remove_partial(n, page);
@@ -1564,7 +1568,6 @@ static void *get_partial_node(struct kmem_cache *s,
1564 object = t; 1568 object = t;
1565 available = page->objects - page->inuse; 1569 available = page->objects - page->inuse;
1566 } else { 1570 } else {
1567 page->freelist = t;
1568 available = put_cpu_partial(s, page, 0); 1571 available = put_cpu_partial(s, page, 0);
1569 stat(s, CPU_PARTIAL_NODE); 1572 stat(s, CPU_PARTIAL_NODE);
1570 } 1573 }
@@ -1579,7 +1582,7 @@ static void *get_partial_node(struct kmem_cache *s,
1579/* 1582/*
1580 * Get a page from somewhere. Search in increasing NUMA distances. 1583 * Get a page from somewhere. Search in increasing NUMA distances.
1581 */ 1584 */
1582static struct page *get_any_partial(struct kmem_cache *s, gfp_t flags, 1585static void *get_any_partial(struct kmem_cache *s, gfp_t flags,
1583 struct kmem_cache_cpu *c) 1586 struct kmem_cache_cpu *c)
1584{ 1587{
1585#ifdef CONFIG_NUMA 1588#ifdef CONFIG_NUMA
@@ -2766,7 +2769,7 @@ static unsigned long calculate_alignment(unsigned long flags,
2766} 2769}
2767 2770
2768static void 2771static void
2769init_kmem_cache_node(struct kmem_cache_node *n, struct kmem_cache *s) 2772init_kmem_cache_node(struct kmem_cache_node *n)
2770{ 2773{
2771 n->nr_partial = 0; 2774 n->nr_partial = 0;
2772 spin_lock_init(&n->list_lock); 2775 spin_lock_init(&n->list_lock);
@@ -2836,7 +2839,7 @@ static void early_kmem_cache_node_alloc(int node)
2836 init_object(kmem_cache_node, n, SLUB_RED_ACTIVE); 2839 init_object(kmem_cache_node, n, SLUB_RED_ACTIVE);
2837 init_tracking(kmem_cache_node, n); 2840 init_tracking(kmem_cache_node, n);
2838#endif 2841#endif
2839 init_kmem_cache_node(n, kmem_cache_node); 2842 init_kmem_cache_node(n);
2840 inc_slabs_node(kmem_cache_node, node, page->objects); 2843 inc_slabs_node(kmem_cache_node, node, page->objects);
2841 2844
2842 add_partial(n, page, DEACTIVATE_TO_HEAD); 2845 add_partial(n, page, DEACTIVATE_TO_HEAD);
@@ -2876,7 +2879,7 @@ static int init_kmem_cache_nodes(struct kmem_cache *s)
2876 } 2879 }
2877 2880
2878 s->node[node] = n; 2881 s->node[node] = n;
2879 init_kmem_cache_node(n, s); 2882 init_kmem_cache_node(n);
2880 } 2883 }
2881 return 1; 2884 return 1;
2882} 2885}
@@ -3625,7 +3628,7 @@ static int slab_mem_going_online_callback(void *arg)
3625 ret = -ENOMEM; 3628 ret = -ENOMEM;
3626 goto out; 3629 goto out;
3627 } 3630 }
3628 init_kmem_cache_node(n, s); 3631 init_kmem_cache_node(n);
3629 s->node[nid] = n; 3632 s->node[nid] = n;
3630 } 3633 }
3631out: 3634out:
@@ -3968,9 +3971,9 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
3968 } 3971 }
3969 return s; 3972 return s;
3970 } 3973 }
3971 kfree(n);
3972 kfree(s); 3974 kfree(s);
3973 } 3975 }
3976 kfree(n);
3974err: 3977err:
3975 up_write(&slub_lock); 3978 up_write(&slub_lock);
3976 3979
diff --git a/mm/util.c b/mm/util.c
index ae962b31de88..8c7265afa29f 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -4,6 +4,7 @@
4#include <linux/export.h> 4#include <linux/export.h>
5#include <linux/err.h> 5#include <linux/err.h>
6#include <linux/sched.h> 6#include <linux/sched.h>
7#include <linux/security.h>
7#include <asm/uaccess.h> 8#include <asm/uaccess.h>
8 9
9#include "internal.h" 10#include "internal.h"
@@ -341,6 +342,35 @@ int __attribute__((weak)) get_user_pages_fast(unsigned long start,
341} 342}
342EXPORT_SYMBOL_GPL(get_user_pages_fast); 343EXPORT_SYMBOL_GPL(get_user_pages_fast);
343 344
345unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,
346 unsigned long len, unsigned long prot,
347 unsigned long flag, unsigned long pgoff)
348{
349 unsigned long ret;
350 struct mm_struct *mm = current->mm;
351
352 ret = security_mmap_file(file, prot, flag);
353 if (!ret) {
354 down_write(&mm->mmap_sem);
355 ret = do_mmap_pgoff(file, addr, len, prot, flag, pgoff);
356 up_write(&mm->mmap_sem);
357 }
358 return ret;
359}
360
361unsigned long vm_mmap(struct file *file, unsigned long addr,
362 unsigned long len, unsigned long prot,
363 unsigned long flag, unsigned long offset)
364{
365 if (unlikely(offset + PAGE_ALIGN(len) < offset))
366 return -EINVAL;
367 if (unlikely(offset & ~PAGE_MASK))
368 return -EINVAL;
369
370 return vm_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT);
371}
372EXPORT_SYMBOL(vm_mmap);
373
344/* Tracepoints definitions. */ 374/* Tracepoints definitions. */
345EXPORT_TRACEPOINT_SYMBOL(kmalloc); 375EXPORT_TRACEPOINT_SYMBOL(kmalloc);
346EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc); 376EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index aa5d73b786ac..d1820ff14aee 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -710,9 +710,9 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
710 break; 710 break;
711 } 711 }
712 712
713 tty_unlock(tty); 713 tty_unlock();
714 schedule(); 714 schedule();
715 tty_lock(tty); 715 tty_lock();
716 } 716 }
717 set_current_state(TASK_RUNNING); 717 set_current_state(TASK_RUNNING);
718 remove_wait_queue(&dev->wait, &wait); 718 remove_wait_queue(&dev->wait, &wait);
diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c
index 8522a4793374..ca8e0a57d945 100644
--- a/net/sched/sch_atm.c
+++ b/net/sched/sch_atm.c
@@ -16,8 +16,6 @@
16#include <net/netlink.h> 16#include <net/netlink.h>
17#include <net/pkt_sched.h> 17#include <net/pkt_sched.h>
18 18
19extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */
20
21/* 19/*
22 * The ATM queuing discipline provides a framework for invoking classifiers 20 * The ATM queuing discipline provides a framework for invoking classifiers
23 * (aka "filters"), which in turn select classes of this queuing discipline. 21 * (aka "filters"), which in turn select classes of this queuing discipline.
diff --git a/net/sunrpc/auth_gss/gss_krb5_wrap.c b/net/sunrpc/auth_gss/gss_krb5_wrap.c
index 38f388c39dce..107c4528654f 100644
--- a/net/sunrpc/auth_gss/gss_krb5_wrap.c
+++ b/net/sunrpc/auth_gss/gss_krb5_wrap.c
@@ -381,21 +381,53 @@ gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
381} 381}
382 382
383/* 383/*
384 * We cannot currently handle tokens with rotated data. We need a 384 * We can shift data by up to LOCAL_BUF_LEN bytes in a pass. If we need
385 * generalized routine to rotate the data in place. It is anticipated 385 * to do more than that, we shift repeatedly. Kevin Coffman reports
386 * that we won't encounter rotated data in the general case. 386 * seeing 28 bytes as the value used by Microsoft clients and servers
387 * with AES, so this constant is chosen to allow handling 28 in one pass
388 * without using too much stack space.
389 *
390 * If that proves to a problem perhaps we could use a more clever
391 * algorithm.
387 */ 392 */
388static u32 393#define LOCAL_BUF_LEN 32u
389rotate_left(struct krb5_ctx *kctx, u32 offset, struct xdr_buf *buf, u16 rrc) 394
395static void rotate_buf_a_little(struct xdr_buf *buf, unsigned int shift)
390{ 396{
391 unsigned int realrrc = rrc % (buf->len - offset - GSS_KRB5_TOK_HDR_LEN); 397 char head[LOCAL_BUF_LEN];
398 char tmp[LOCAL_BUF_LEN];
399 unsigned int this_len, i;
400
401 BUG_ON(shift > LOCAL_BUF_LEN);
392 402
393 if (realrrc == 0) 403 read_bytes_from_xdr_buf(buf, 0, head, shift);
394 return 0; 404 for (i = 0; i + shift < buf->len; i += LOCAL_BUF_LEN) {
405 this_len = min(LOCAL_BUF_LEN, buf->len - (i + shift));
406 read_bytes_from_xdr_buf(buf, i+shift, tmp, this_len);
407 write_bytes_to_xdr_buf(buf, i, tmp, this_len);
408 }
409 write_bytes_to_xdr_buf(buf, buf->len - shift, head, shift);
410}
395 411
396 dprintk("%s: cannot process token with rotated data: " 412static void _rotate_left(struct xdr_buf *buf, unsigned int shift)
397 "rrc %u, realrrc %u\n", __func__, rrc, realrrc); 413{
398 return 1; 414 int shifted = 0;
415 int this_shift;
416
417 shift %= buf->len;
418 while (shifted < shift) {
419 this_shift = min(shift - shifted, LOCAL_BUF_LEN);
420 rotate_buf_a_little(buf, this_shift);
421 shifted += this_shift;
422 }
423}
424
425static void rotate_left(u32 base, struct xdr_buf *buf, unsigned int shift)
426{
427 struct xdr_buf subbuf;
428
429 xdr_buf_subsegment(buf, &subbuf, base, buf->len - base);
430 _rotate_left(&subbuf, shift);
399} 431}
400 432
401static u32 433static u32
@@ -495,11 +527,8 @@ gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
495 527
496 seqnum = be64_to_cpup((__be64 *)(ptr + 8)); 528 seqnum = be64_to_cpup((__be64 *)(ptr + 8));
497 529
498 if (rrc != 0) { 530 if (rrc != 0)
499 err = rotate_left(kctx, offset, buf, rrc); 531 rotate_left(offset + 16, buf, rrc);
500 if (err)
501 return GSS_S_FAILURE;
502 }
503 532
504 err = (*kctx->gk5e->decrypt_v2)(kctx, offset, buf, 533 err = (*kctx->gk5e->decrypt_v2)(kctx, offset, buf,
505 &headskip, &tailskip); 534 &headskip, &tailskip);
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index 28b62dbb6d1e..73e957386600 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -336,7 +336,6 @@ struct rsc {
336 struct svc_cred cred; 336 struct svc_cred cred;
337 struct gss_svc_seq_data seqdata; 337 struct gss_svc_seq_data seqdata;
338 struct gss_ctx *mechctx; 338 struct gss_ctx *mechctx;
339 char *client_name;
340}; 339};
341 340
342static struct rsc *rsc_update(struct cache_detail *cd, struct rsc *new, struct rsc *old); 341static struct rsc *rsc_update(struct cache_detail *cd, struct rsc *new, struct rsc *old);
@@ -347,9 +346,7 @@ static void rsc_free(struct rsc *rsci)
347 kfree(rsci->handle.data); 346 kfree(rsci->handle.data);
348 if (rsci->mechctx) 347 if (rsci->mechctx)
349 gss_delete_sec_context(&rsci->mechctx); 348 gss_delete_sec_context(&rsci->mechctx);
350 if (rsci->cred.cr_group_info) 349 free_svc_cred(&rsci->cred);
351 put_group_info(rsci->cred.cr_group_info);
352 kfree(rsci->client_name);
353} 350}
354 351
355static void rsc_put(struct kref *ref) 352static void rsc_put(struct kref *ref)
@@ -387,7 +384,7 @@ rsc_init(struct cache_head *cnew, struct cache_head *ctmp)
387 tmp->handle.data = NULL; 384 tmp->handle.data = NULL;
388 new->mechctx = NULL; 385 new->mechctx = NULL;
389 new->cred.cr_group_info = NULL; 386 new->cred.cr_group_info = NULL;
390 new->client_name = NULL; 387 new->cred.cr_principal = NULL;
391} 388}
392 389
393static void 390static void
@@ -402,8 +399,8 @@ update_rsc(struct cache_head *cnew, struct cache_head *ctmp)
402 spin_lock_init(&new->seqdata.sd_lock); 399 spin_lock_init(&new->seqdata.sd_lock);
403 new->cred = tmp->cred; 400 new->cred = tmp->cred;
404 tmp->cred.cr_group_info = NULL; 401 tmp->cred.cr_group_info = NULL;
405 new->client_name = tmp->client_name; 402 new->cred.cr_principal = tmp->cred.cr_principal;
406 tmp->client_name = NULL; 403 tmp->cred.cr_principal = NULL;
407} 404}
408 405
409static struct cache_head * 406static struct cache_head *
@@ -501,8 +498,8 @@ static int rsc_parse(struct cache_detail *cd,
501 /* get client name */ 498 /* get client name */
502 len = qword_get(&mesg, buf, mlen); 499 len = qword_get(&mesg, buf, mlen);
503 if (len > 0) { 500 if (len > 0) {
504 rsci.client_name = kstrdup(buf, GFP_KERNEL); 501 rsci.cred.cr_principal = kstrdup(buf, GFP_KERNEL);
505 if (!rsci.client_name) 502 if (!rsci.cred.cr_principal)
506 goto out; 503 goto out;
507 } 504 }
508 505
@@ -932,16 +929,6 @@ struct gss_svc_data {
932 struct rsc *rsci; 929 struct rsc *rsci;
933}; 930};
934 931
935char *svc_gss_principal(struct svc_rqst *rqstp)
936{
937 struct gss_svc_data *gd = (struct gss_svc_data *)rqstp->rq_auth_data;
938
939 if (gd && gd->rsci)
940 return gd->rsci->client_name;
941 return NULL;
942}
943EXPORT_SYMBOL_GPL(svc_gss_principal);
944
945static int 932static int
946svcauth_gss_set_client(struct svc_rqst *rqstp) 933svcauth_gss_set_client(struct svc_rqst *rqstp)
947{ 934{
@@ -969,16 +956,17 @@ svcauth_gss_set_client(struct svc_rqst *rqstp)
969} 956}
970 957
971static inline int 958static inline int
972gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp, struct rsi *rsip) 959gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp,
960 struct xdr_netobj *out_handle, int *major_status)
973{ 961{
974 struct rsc *rsci; 962 struct rsc *rsci;
975 int rc; 963 int rc;
976 964
977 if (rsip->major_status != GSS_S_COMPLETE) 965 if (*major_status != GSS_S_COMPLETE)
978 return gss_write_null_verf(rqstp); 966 return gss_write_null_verf(rqstp);
979 rsci = gss_svc_searchbyctx(cd, &rsip->out_handle); 967 rsci = gss_svc_searchbyctx(cd, out_handle);
980 if (rsci == NULL) { 968 if (rsci == NULL) {
981 rsip->major_status = GSS_S_NO_CONTEXT; 969 *major_status = GSS_S_NO_CONTEXT;
982 return gss_write_null_verf(rqstp); 970 return gss_write_null_verf(rqstp);
983 } 971 }
984 rc = gss_write_verf(rqstp, rsci->mechctx, GSS_SEQ_WIN); 972 rc = gss_write_verf(rqstp, rsci->mechctx, GSS_SEQ_WIN);
@@ -986,22 +974,13 @@ gss_write_init_verf(struct cache_detail *cd, struct svc_rqst *rqstp, struct rsi
986 return rc; 974 return rc;
987} 975}
988 976
989/* 977static inline int
990 * Having read the cred already and found we're in the context 978gss_read_verf(struct rpc_gss_wire_cred *gc,
991 * initiation case, read the verifier and initiate (or check the results 979 struct kvec *argv, __be32 *authp,
992 * of) upcalls to userspace for help with context initiation. If 980 struct xdr_netobj *in_handle,
993 * the upcall results are available, write the verifier and result. 981 struct xdr_netobj *in_token)
994 * Otherwise, drop the request pending an answer to the upcall.
995 */
996static int svcauth_gss_handle_init(struct svc_rqst *rqstp,
997 struct rpc_gss_wire_cred *gc, __be32 *authp)
998{ 982{
999 struct kvec *argv = &rqstp->rq_arg.head[0];
1000 struct kvec *resv = &rqstp->rq_res.head[0];
1001 struct xdr_netobj tmpobj; 983 struct xdr_netobj tmpobj;
1002 struct rsi *rsip, rsikey;
1003 int ret;
1004 struct sunrpc_net *sn = net_generic(rqstp->rq_xprt->xpt_net, sunrpc_net_id);
1005 984
1006 /* Read the verifier; should be NULL: */ 985 /* Read the verifier; should be NULL: */
1007 *authp = rpc_autherr_badverf; 986 *authp = rpc_autherr_badverf;
@@ -1011,24 +990,67 @@ static int svcauth_gss_handle_init(struct svc_rqst *rqstp,
1011 return SVC_DENIED; 990 return SVC_DENIED;
1012 if (svc_getnl(argv) != 0) 991 if (svc_getnl(argv) != 0)
1013 return SVC_DENIED; 992 return SVC_DENIED;
1014
1015 /* Martial context handle and token for upcall: */ 993 /* Martial context handle and token for upcall: */
1016 *authp = rpc_autherr_badcred; 994 *authp = rpc_autherr_badcred;
1017 if (gc->gc_proc == RPC_GSS_PROC_INIT && gc->gc_ctx.len != 0) 995 if (gc->gc_proc == RPC_GSS_PROC_INIT && gc->gc_ctx.len != 0)
1018 return SVC_DENIED; 996 return SVC_DENIED;
1019 memset(&rsikey, 0, sizeof(rsikey)); 997 if (dup_netobj(in_handle, &gc->gc_ctx))
1020 if (dup_netobj(&rsikey.in_handle, &gc->gc_ctx))
1021 return SVC_CLOSE; 998 return SVC_CLOSE;
1022 *authp = rpc_autherr_badverf; 999 *authp = rpc_autherr_badverf;
1023 if (svc_safe_getnetobj(argv, &tmpobj)) { 1000 if (svc_safe_getnetobj(argv, &tmpobj)) {
1024 kfree(rsikey.in_handle.data); 1001 kfree(in_handle->data);
1025 return SVC_DENIED; 1002 return SVC_DENIED;
1026 } 1003 }
1027 if (dup_netobj(&rsikey.in_token, &tmpobj)) { 1004 if (dup_netobj(in_token, &tmpobj)) {
1028 kfree(rsikey.in_handle.data); 1005 kfree(in_handle->data);
1029 return SVC_CLOSE; 1006 return SVC_CLOSE;
1030 } 1007 }
1031 1008
1009 return 0;
1010}
1011
1012static inline int
1013gss_write_resv(struct kvec *resv, size_t size_limit,
1014 struct xdr_netobj *out_handle, struct xdr_netobj *out_token,
1015 int major_status, int minor_status)
1016{
1017 if (resv->iov_len + 4 > size_limit)
1018 return -1;
1019 svc_putnl(resv, RPC_SUCCESS);
1020 if (svc_safe_putnetobj(resv, out_handle))
1021 return -1;
1022 if (resv->iov_len + 3 * 4 > size_limit)
1023 return -1;
1024 svc_putnl(resv, major_status);
1025 svc_putnl(resv, minor_status);
1026 svc_putnl(resv, GSS_SEQ_WIN);
1027 if (svc_safe_putnetobj(resv, out_token))
1028 return -1;
1029 return 0;
1030}
1031
1032/*
1033 * Having read the cred already and found we're in the context
1034 * initiation case, read the verifier and initiate (or check the results
1035 * of) upcalls to userspace for help with context initiation. If
1036 * the upcall results are available, write the verifier and result.
1037 * Otherwise, drop the request pending an answer to the upcall.
1038 */
1039static int svcauth_gss_handle_init(struct svc_rqst *rqstp,
1040 struct rpc_gss_wire_cred *gc, __be32 *authp)
1041{
1042 struct kvec *argv = &rqstp->rq_arg.head[0];
1043 struct kvec *resv = &rqstp->rq_res.head[0];
1044 struct rsi *rsip, rsikey;
1045 int ret;
1046 struct sunrpc_net *sn = net_generic(rqstp->rq_xprt->xpt_net, sunrpc_net_id);
1047
1048 memset(&rsikey, 0, sizeof(rsikey));
1049 ret = gss_read_verf(gc, argv, authp,
1050 &rsikey.in_handle, &rsikey.in_token);
1051 if (ret)
1052 return ret;
1053
1032 /* Perform upcall, or find upcall result: */ 1054 /* Perform upcall, or find upcall result: */
1033 rsip = rsi_lookup(sn->rsi_cache, &rsikey); 1055 rsip = rsi_lookup(sn->rsi_cache, &rsikey);
1034 rsi_free(&rsikey); 1056 rsi_free(&rsikey);
@@ -1040,19 +1062,12 @@ static int svcauth_gss_handle_init(struct svc_rqst *rqstp,
1040 1062
1041 ret = SVC_CLOSE; 1063 ret = SVC_CLOSE;
1042 /* Got an answer to the upcall; use it: */ 1064 /* Got an answer to the upcall; use it: */
1043 if (gss_write_init_verf(sn->rsc_cache, rqstp, rsip)) 1065 if (gss_write_init_verf(sn->rsc_cache, rqstp,
1044 goto out; 1066 &rsip->out_handle, &rsip->major_status))
1045 if (resv->iov_len + 4 > PAGE_SIZE)
1046 goto out; 1067 goto out;
1047 svc_putnl(resv, RPC_SUCCESS); 1068 if (gss_write_resv(resv, PAGE_SIZE,
1048 if (svc_safe_putnetobj(resv, &rsip->out_handle)) 1069 &rsip->out_handle, &rsip->out_token,
1049 goto out; 1070 rsip->major_status, rsip->minor_status))
1050 if (resv->iov_len + 3 * 4 > PAGE_SIZE)
1051 goto out;
1052 svc_putnl(resv, rsip->major_status);
1053 svc_putnl(resv, rsip->minor_status);
1054 svc_putnl(resv, GSS_SEQ_WIN);
1055 if (svc_safe_putnetobj(resv, &rsip->out_token))
1056 goto out; 1071 goto out;
1057 1072
1058 ret = SVC_COMPLETE; 1073 ret = SVC_COMPLETE;
@@ -1192,7 +1207,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp, __be32 *authp)
1192 } 1207 }
1193 svcdata->rsci = rsci; 1208 svcdata->rsci = rsci;
1194 cache_get(&rsci->h); 1209 cache_get(&rsci->h);
1195 rqstp->rq_flavor = gss_svc_to_pseudoflavor( 1210 rqstp->rq_cred.cr_flavor = gss_svc_to_pseudoflavor(
1196 rsci->mechctx->mech_type, gc->gc_svc); 1211 rsci->mechctx->mech_type, gc->gc_svc);
1197 ret = SVC_OK; 1212 ret = SVC_OK;
1198 goto out; 1213 goto out;
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c
index 3c0653439f3d..92509ffe15fc 100644
--- a/net/sunrpc/rpcb_clnt.c
+++ b/net/sunrpc/rpcb_clnt.c
@@ -180,14 +180,16 @@ void rpcb_put_local(struct net *net)
180 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); 180 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
181 struct rpc_clnt *clnt = sn->rpcb_local_clnt; 181 struct rpc_clnt *clnt = sn->rpcb_local_clnt;
182 struct rpc_clnt *clnt4 = sn->rpcb_local_clnt4; 182 struct rpc_clnt *clnt4 = sn->rpcb_local_clnt4;
183 int shutdown; 183 int shutdown = 0;
184 184
185 spin_lock(&sn->rpcb_clnt_lock); 185 spin_lock(&sn->rpcb_clnt_lock);
186 if (--sn->rpcb_users == 0) { 186 if (sn->rpcb_users) {
187 sn->rpcb_local_clnt = NULL; 187 if (--sn->rpcb_users == 0) {
188 sn->rpcb_local_clnt4 = NULL; 188 sn->rpcb_local_clnt = NULL;
189 sn->rpcb_local_clnt4 = NULL;
190 }
191 shutdown = !sn->rpcb_users;
189 } 192 }
190 shutdown = !sn->rpcb_users;
191 spin_unlock(&sn->rpcb_clnt_lock); 193 spin_unlock(&sn->rpcb_clnt_lock);
192 194
193 if (shutdown) { 195 if (shutdown) {
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index 017c0117d154..7e9baaa1e543 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -407,6 +407,14 @@ static int svc_uses_rpcbind(struct svc_serv *serv)
407 return 0; 407 return 0;
408} 408}
409 409
410int svc_bind(struct svc_serv *serv, struct net *net)
411{
412 if (!svc_uses_rpcbind(serv))
413 return 0;
414 return svc_rpcb_setup(serv, net);
415}
416EXPORT_SYMBOL_GPL(svc_bind);
417
410/* 418/*
411 * Create an RPC service 419 * Create an RPC service
412 */ 420 */
@@ -471,15 +479,8 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
471 spin_lock_init(&pool->sp_lock); 479 spin_lock_init(&pool->sp_lock);
472 } 480 }
473 481
474 if (svc_uses_rpcbind(serv)) { 482 if (svc_uses_rpcbind(serv) && (!serv->sv_shutdown))
475 if (svc_rpcb_setup(serv, current->nsproxy->net_ns) < 0) { 483 serv->sv_shutdown = svc_rpcb_cleanup;
476 kfree(serv->sv_pools);
477 kfree(serv);
478 return NULL;
479 }
480 if (!serv->sv_shutdown)
481 serv->sv_shutdown = svc_rpcb_cleanup;
482 }
483 484
484 return serv; 485 return serv;
485} 486}
@@ -536,8 +537,6 @@ EXPORT_SYMBOL_GPL(svc_shutdown_net);
536void 537void
537svc_destroy(struct svc_serv *serv) 538svc_destroy(struct svc_serv *serv)
538{ 539{
539 struct net *net = current->nsproxy->net_ns;
540
541 dprintk("svc: svc_destroy(%s, %d)\n", 540 dprintk("svc: svc_destroy(%s, %d)\n",
542 serv->sv_program->pg_name, 541 serv->sv_program->pg_name,
543 serv->sv_nrthreads); 542 serv->sv_nrthreads);
@@ -552,8 +551,6 @@ svc_destroy(struct svc_serv *serv)
552 551
553 del_timer_sync(&serv->sv_temptimer); 552 del_timer_sync(&serv->sv_temptimer);
554 553
555 svc_shutdown_net(serv, net);
556
557 /* 554 /*
558 * The last user is gone and thus all sockets have to be destroyed to 555 * The last user is gone and thus all sockets have to be destroyed to
559 * the point. Check this. 556 * the point. Check this.
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index b98ee3514912..88f2bf671960 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -598,6 +598,7 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
598 598
599 /* now allocate needed pages. If we get a failure, sleep briefly */ 599 /* now allocate needed pages. If we get a failure, sleep briefly */
600 pages = (serv->sv_max_mesg + PAGE_SIZE) / PAGE_SIZE; 600 pages = (serv->sv_max_mesg + PAGE_SIZE) / PAGE_SIZE;
601 BUG_ON(pages >= RPCSVC_MAXPAGES);
601 for (i = 0; i < pages ; i++) 602 for (i = 0; i < pages ; i++)
602 while (rqstp->rq_pages[i] == NULL) { 603 while (rqstp->rq_pages[i] == NULL) {
603 struct page *p = alloc_page(GFP_KERNEL); 604 struct page *p = alloc_page(GFP_KERNEL);
@@ -612,7 +613,6 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
612 rqstp->rq_pages[i] = p; 613 rqstp->rq_pages[i] = p;
613 } 614 }
614 rqstp->rq_pages[i++] = NULL; /* this might be seen in nfs_read_actor */ 615 rqstp->rq_pages[i++] = NULL; /* this might be seen in nfs_read_actor */
615 BUG_ON(pages >= RPCSVC_MAXPAGES);
616 616
617 /* Make arg->head point to first page and arg->pages point to rest */ 617 /* Make arg->head point to first page and arg->pages point to rest */
618 arg = &rqstp->rq_arg; 618 arg = &rqstp->rq_arg;
@@ -973,7 +973,7 @@ void svc_close_net(struct svc_serv *serv, struct net *net)
973 svc_clear_pools(serv, net); 973 svc_clear_pools(serv, net);
974 /* 974 /*
975 * At this point the sp_sockets lists will stay empty, since 975 * At this point the sp_sockets lists will stay empty, since
976 * svc_enqueue will not add new entries without taking the 976 * svc_xprt_enqueue will not add new entries without taking the
977 * sp_lock and checking XPT_BUSY. 977 * sp_lock and checking XPT_BUSY.
978 */ 978 */
979 svc_clear_list(&serv->sv_tempsocks, net); 979 svc_clear_list(&serv->sv_tempsocks, net);
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 71ec8530ec8c..2777fa896645 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -347,17 +347,12 @@ static inline int ip_map_update(struct net *net, struct ip_map *ipm,
347 return __ip_map_update(sn->ip_map_cache, ipm, udom, expiry); 347 return __ip_map_update(sn->ip_map_cache, ipm, udom, expiry);
348} 348}
349 349
350 350void svcauth_unix_purge(struct net *net)
351void svcauth_unix_purge(void)
352{ 351{
353 struct net *net; 352 struct sunrpc_net *sn;
354
355 for_each_net(net) {
356 struct sunrpc_net *sn;
357 353
358 sn = net_generic(net, sunrpc_net_id); 354 sn = net_generic(net, sunrpc_net_id);
359 cache_purge(sn->ip_map_cache); 355 cache_purge(sn->ip_map_cache);
360 }
361} 356}
362EXPORT_SYMBOL_GPL(svcauth_unix_purge); 357EXPORT_SYMBOL_GPL(svcauth_unix_purge);
363 358
@@ -751,6 +746,7 @@ svcauth_null_accept(struct svc_rqst *rqstp, __be32 *authp)
751 struct svc_cred *cred = &rqstp->rq_cred; 746 struct svc_cred *cred = &rqstp->rq_cred;
752 747
753 cred->cr_group_info = NULL; 748 cred->cr_group_info = NULL;
749 cred->cr_principal = NULL;
754 rqstp->rq_client = NULL; 750 rqstp->rq_client = NULL;
755 751
756 if (argv->iov_len < 3*4) 752 if (argv->iov_len < 3*4)
@@ -778,7 +774,7 @@ svcauth_null_accept(struct svc_rqst *rqstp, __be32 *authp)
778 svc_putnl(resv, RPC_AUTH_NULL); 774 svc_putnl(resv, RPC_AUTH_NULL);
779 svc_putnl(resv, 0); 775 svc_putnl(resv, 0);
780 776
781 rqstp->rq_flavor = RPC_AUTH_NULL; 777 rqstp->rq_cred.cr_flavor = RPC_AUTH_NULL;
782 return SVC_OK; 778 return SVC_OK;
783} 779}
784 780
@@ -816,6 +812,7 @@ svcauth_unix_accept(struct svc_rqst *rqstp, __be32 *authp)
816 int len = argv->iov_len; 812 int len = argv->iov_len;
817 813
818 cred->cr_group_info = NULL; 814 cred->cr_group_info = NULL;
815 cred->cr_principal = NULL;
819 rqstp->rq_client = NULL; 816 rqstp->rq_client = NULL;
820 817
821 if ((len -= 3*4) < 0) 818 if ((len -= 3*4) < 0)
@@ -852,7 +849,7 @@ svcauth_unix_accept(struct svc_rqst *rqstp, __be32 *authp)
852 svc_putnl(resv, RPC_AUTH_NULL); 849 svc_putnl(resv, RPC_AUTH_NULL);
853 svc_putnl(resv, 0); 850 svc_putnl(resv, 0);
854 851
855 rqstp->rq_flavor = RPC_AUTH_UNIX; 852 rqstp->rq_cred.cr_flavor = RPC_AUTH_UNIX;
856 return SVC_OK; 853 return SVC_OK;
857 854
858badcred: 855badcred:
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index faea0ec612bf..e5bd60ff48e3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2382,6 +2382,19 @@ sub process {
2382 } 2382 }
2383 } 2383 }
2384 2384
2385 if ($line =~ /\bprintk\s*\(\s*KERN_([A-Z]+)/) {
2386 my $orig = $1;
2387 my $level = lc($orig);
2388 $level = "warn" if ($level eq "warning");
2389 WARN("PREFER_PR_LEVEL",
2390 "Prefer pr_$level(... to printk(KERN_$1, ...\n" . $herecurr);
2391 }
2392
2393 if ($line =~ /\bpr_warning\s*\(/) {
2394 WARN("PREFER_PR_LEVEL",
2395 "Prefer pr_warn(... to pr_warning(...\n" . $herecurr);
2396 }
2397
2385# function brace can't be on same line, except for #defines of do while, 2398# function brace can't be on same line, except for #defines of do while,
2386# or if closed on same line 2399# or if closed on same line
2387 if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and 2400 if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and
@@ -2448,6 +2461,13 @@ sub process {
2448 "space prohibited between function name and open parenthesis '('\n" . $herecurr); 2461 "space prohibited between function name and open parenthesis '('\n" . $herecurr);
2449 } 2462 }
2450 } 2463 }
2464
2465# check for whitespace before a non-naked semicolon
2466 if ($line =~ /^\+.*\S\s+;/) {
2467 CHK("SPACING",
2468 "space prohibited before semicolon\n" . $herecurr);
2469 }
2470
2451# Check operator spacing. 2471# Check operator spacing.
2452 if (!($line=~/\#\s*include/)) { 2472 if (!($line=~/\#\s*include/)) {
2453 my $ops = qr{ 2473 my $ops = qr{
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index 032daab449b0..8ea39aabe948 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -490,17 +490,9 @@ static int common_mmap(int op, struct file *file, unsigned long prot,
490 return common_file_perm(op, file, mask); 490 return common_file_perm(op, file, mask);
491} 491}
492 492
493static int apparmor_file_mmap(struct file *file, unsigned long reqprot, 493static int apparmor_mmap_file(struct file *file, unsigned long reqprot,
494 unsigned long prot, unsigned long flags, 494 unsigned long prot, unsigned long flags)
495 unsigned long addr, unsigned long addr_only)
496{ 495{
497 int rc = 0;
498
499 /* do DAC check */
500 rc = cap_file_mmap(file, reqprot, prot, flags, addr, addr_only);
501 if (rc || addr_only)
502 return rc;
503
504 return common_mmap(OP_FMMAP, file, prot, flags); 496 return common_mmap(OP_FMMAP, file, prot, flags);
505} 497}
506 498
@@ -646,7 +638,8 @@ static struct security_operations apparmor_ops = {
646 .file_permission = apparmor_file_permission, 638 .file_permission = apparmor_file_permission,
647 .file_alloc_security = apparmor_file_alloc_security, 639 .file_alloc_security = apparmor_file_alloc_security,
648 .file_free_security = apparmor_file_free_security, 640 .file_free_security = apparmor_file_free_security,
649 .file_mmap = apparmor_file_mmap, 641 .mmap_file = apparmor_mmap_file,
642 .mmap_addr = cap_mmap_addr,
650 .file_mprotect = apparmor_file_mprotect, 643 .file_mprotect = apparmor_file_mprotect,
651 .file_lock = apparmor_file_lock, 644 .file_lock = apparmor_file_lock,
652 645
diff --git a/security/capability.c b/security/capability.c
index fca889676c5e..61095df8b89a 100644
--- a/security/capability.c
+++ b/security/capability.c
@@ -949,7 +949,8 @@ void __init security_fixup_ops(struct security_operations *ops)
949 set_to_cap_if_null(ops, file_alloc_security); 949 set_to_cap_if_null(ops, file_alloc_security);
950 set_to_cap_if_null(ops, file_free_security); 950 set_to_cap_if_null(ops, file_free_security);
951 set_to_cap_if_null(ops, file_ioctl); 951 set_to_cap_if_null(ops, file_ioctl);
952 set_to_cap_if_null(ops, file_mmap); 952 set_to_cap_if_null(ops, mmap_addr);
953 set_to_cap_if_null(ops, mmap_file);
953 set_to_cap_if_null(ops, file_mprotect); 954 set_to_cap_if_null(ops, file_mprotect);
954 set_to_cap_if_null(ops, file_lock); 955 set_to_cap_if_null(ops, file_lock);
955 set_to_cap_if_null(ops, file_fcntl); 956 set_to_cap_if_null(ops, file_fcntl);
diff --git a/security/commoncap.c b/security/commoncap.c
index e771cb1b2d79..6dbae4650abe 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -958,22 +958,15 @@ int cap_vm_enough_memory(struct mm_struct *mm, long pages)
958} 958}
959 959
960/* 960/*
961 * cap_file_mmap - check if able to map given addr 961 * cap_mmap_addr - check if able to map given addr
962 * @file: unused
963 * @reqprot: unused
964 * @prot: unused
965 * @flags: unused
966 * @addr: address attempting to be mapped 962 * @addr: address attempting to be mapped
967 * @addr_only: unused
968 * 963 *
969 * If the process is attempting to map memory below dac_mmap_min_addr they need 964 * If the process is attempting to map memory below dac_mmap_min_addr they need
970 * CAP_SYS_RAWIO. The other parameters to this function are unused by the 965 * CAP_SYS_RAWIO. The other parameters to this function are unused by the
971 * capability security module. Returns 0 if this mapping should be allowed 966 * capability security module. Returns 0 if this mapping should be allowed
972 * -EPERM if not. 967 * -EPERM if not.
973 */ 968 */
974int cap_file_mmap(struct file *file, unsigned long reqprot, 969int cap_mmap_addr(unsigned long addr)
975 unsigned long prot, unsigned long flags,
976 unsigned long addr, unsigned long addr_only)
977{ 970{
978 int ret = 0; 971 int ret = 0;
979 972
@@ -986,3 +979,9 @@ int cap_file_mmap(struct file *file, unsigned long reqprot,
986 } 979 }
987 return ret; 980 return ret;
988} 981}
982
983int cap_mmap_file(struct file *file, unsigned long reqprot,
984 unsigned long prot, unsigned long flags)
985{
986 return 0;
987}
diff --git a/security/keys/compat.c b/security/keys/compat.c
index fab4f8dda6c6..c92d42b021aa 100644
--- a/security/keys/compat.c
+++ b/security/keys/compat.c
@@ -38,7 +38,7 @@ long compat_keyctl_instantiate_key_iov(
38 38
39 ret = compat_rw_copy_check_uvector(WRITE, _payload_iov, ioc, 39 ret = compat_rw_copy_check_uvector(WRITE, _payload_iov, ioc,
40 ARRAY_SIZE(iovstack), 40 ARRAY_SIZE(iovstack),
41 iovstack, &iov, 1); 41 iovstack, &iov);
42 if (ret < 0) 42 if (ret < 0)
43 return ret; 43 return ret;
44 if (ret == 0) 44 if (ret == 0)
diff --git a/security/keys/internal.h b/security/keys/internal.h
index f711b094ed41..3dcbf86b0d31 100644
--- a/security/keys/internal.h
+++ b/security/keys/internal.h
@@ -14,6 +14,7 @@
14 14
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/key-type.h> 16#include <linux/key-type.h>
17#include <linux/task_work.h>
17 18
18#ifdef __KDEBUG 19#ifdef __KDEBUG
19#define kenter(FMT, ...) \ 20#define kenter(FMT, ...) \
@@ -148,6 +149,7 @@ extern key_ref_t lookup_user_key(key_serial_t id, unsigned long flags,
148#define KEY_LOOKUP_FOR_UNLINK 0x04 149#define KEY_LOOKUP_FOR_UNLINK 0x04
149 150
150extern long join_session_keyring(const char *name); 151extern long join_session_keyring(const char *name);
152extern void key_change_session_keyring(struct task_work *twork);
151 153
152extern struct work_struct key_gc_work; 154extern struct work_struct key_gc_work;
153extern unsigned key_gc_delay; 155extern unsigned key_gc_delay;
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index ddb3e05bc5fc..0f5b3f027299 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -84,7 +84,7 @@ SYSCALL_DEFINE5(add_key, const char __user *, _type,
84 vm = false; 84 vm = false;
85 if (_payload) { 85 if (_payload) {
86 ret = -ENOMEM; 86 ret = -ENOMEM;
87 payload = kmalloc(plen, GFP_KERNEL); 87 payload = kmalloc(plen, GFP_KERNEL | __GFP_NOWARN);
88 if (!payload) { 88 if (!payload) {
89 if (plen <= PAGE_SIZE) 89 if (plen <= PAGE_SIZE)
90 goto error2; 90 goto error2;
@@ -1110,7 +1110,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
1110 goto no_payload; 1110 goto no_payload;
1111 1111
1112 ret = rw_copy_check_uvector(WRITE, _payload_iov, ioc, 1112 ret = rw_copy_check_uvector(WRITE, _payload_iov, ioc,
1113 ARRAY_SIZE(iovstack), iovstack, &iov, 1); 1113 ARRAY_SIZE(iovstack), iovstack, &iov);
1114 if (ret < 0) 1114 if (ret < 0)
1115 return ret; 1115 return ret;
1116 if (ret == 0) 1116 if (ret == 0)
@@ -1454,50 +1454,57 @@ long keyctl_get_security(key_serial_t keyid,
1454 */ 1454 */
1455long keyctl_session_to_parent(void) 1455long keyctl_session_to_parent(void)
1456{ 1456{
1457#ifdef TIF_NOTIFY_RESUME
1458 struct task_struct *me, *parent; 1457 struct task_struct *me, *parent;
1459 const struct cred *mycred, *pcred; 1458 const struct cred *mycred, *pcred;
1460 struct cred *cred, *oldcred; 1459 struct task_work *newwork, *oldwork;
1461 key_ref_t keyring_r; 1460 key_ref_t keyring_r;
1461 struct cred *cred;
1462 int ret; 1462 int ret;
1463 1463
1464 keyring_r = lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_LINK); 1464 keyring_r = lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_LINK);
1465 if (IS_ERR(keyring_r)) 1465 if (IS_ERR(keyring_r))
1466 return PTR_ERR(keyring_r); 1466 return PTR_ERR(keyring_r);
1467 1467
1468 ret = -ENOMEM;
1469 newwork = kmalloc(sizeof(struct task_work), GFP_KERNEL);
1470 if (!newwork)
1471 goto error_keyring;
1472
1468 /* our parent is going to need a new cred struct, a new tgcred struct 1473 /* our parent is going to need a new cred struct, a new tgcred struct
1469 * and new security data, so we allocate them here to prevent ENOMEM in 1474 * and new security data, so we allocate them here to prevent ENOMEM in
1470 * our parent */ 1475 * our parent */
1471 ret = -ENOMEM;
1472 cred = cred_alloc_blank(); 1476 cred = cred_alloc_blank();
1473 if (!cred) 1477 if (!cred)
1474 goto error_keyring; 1478 goto error_newwork;
1475 1479
1476 cred->tgcred->session_keyring = key_ref_to_ptr(keyring_r); 1480 cred->tgcred->session_keyring = key_ref_to_ptr(keyring_r);
1477 keyring_r = NULL; 1481 init_task_work(newwork, key_change_session_keyring, cred);
1478 1482
1479 me = current; 1483 me = current;
1480 rcu_read_lock(); 1484 rcu_read_lock();
1481 write_lock_irq(&tasklist_lock); 1485 write_lock_irq(&tasklist_lock);
1482 1486
1483 parent = me->real_parent;
1484 ret = -EPERM; 1487 ret = -EPERM;
1488 oldwork = NULL;
1489 parent = me->real_parent;
1485 1490
1486 /* the parent mustn't be init and mustn't be a kernel thread */ 1491 /* the parent mustn't be init and mustn't be a kernel thread */
1487 if (parent->pid <= 1 || !parent->mm) 1492 if (parent->pid <= 1 || !parent->mm)
1488 goto not_permitted; 1493 goto unlock;
1489 1494
1490 /* the parent must be single threaded */ 1495 /* the parent must be single threaded */
1491 if (!thread_group_empty(parent)) 1496 if (!thread_group_empty(parent))
1492 goto not_permitted; 1497 goto unlock;
1493 1498
1494 /* the parent and the child must have different session keyrings or 1499 /* the parent and the child must have different session keyrings or
1495 * there's no point */ 1500 * there's no point */
1496 mycred = current_cred(); 1501 mycred = current_cred();
1497 pcred = __task_cred(parent); 1502 pcred = __task_cred(parent);
1498 if (mycred == pcred || 1503 if (mycred == pcred ||
1499 mycred->tgcred->session_keyring == pcred->tgcred->session_keyring) 1504 mycred->tgcred->session_keyring == pcred->tgcred->session_keyring) {
1500 goto already_same; 1505 ret = 0;
1506 goto unlock;
1507 }
1501 1508
1502 /* the parent must have the same effective ownership and mustn't be 1509 /* the parent must have the same effective ownership and mustn't be
1503 * SUID/SGID */ 1510 * SUID/SGID */
@@ -1507,50 +1514,40 @@ long keyctl_session_to_parent(void)
1507 pcred->gid != mycred->egid || 1514 pcred->gid != mycred->egid ||
1508 pcred->egid != mycred->egid || 1515 pcred->egid != mycred->egid ||
1509 pcred->sgid != mycred->egid) 1516 pcred->sgid != mycred->egid)
1510 goto not_permitted; 1517 goto unlock;
1511 1518
1512 /* the keyrings must have the same UID */ 1519 /* the keyrings must have the same UID */
1513 if ((pcred->tgcred->session_keyring && 1520 if ((pcred->tgcred->session_keyring &&
1514 pcred->tgcred->session_keyring->uid != mycred->euid) || 1521 pcred->tgcred->session_keyring->uid != mycred->euid) ||
1515 mycred->tgcred->session_keyring->uid != mycred->euid) 1522 mycred->tgcred->session_keyring->uid != mycred->euid)
1516 goto not_permitted; 1523 goto unlock;
1517 1524
1518 /* if there's an already pending keyring replacement, then we replace 1525 /* cancel an already pending keyring replacement */
1519 * that */ 1526 oldwork = task_work_cancel(parent, key_change_session_keyring);
1520 oldcred = parent->replacement_session_keyring;
1521 1527
1522 /* the replacement session keyring is applied just prior to userspace 1528 /* the replacement session keyring is applied just prior to userspace
1523 * restarting */ 1529 * restarting */
1524 parent->replacement_session_keyring = cred; 1530 ret = task_work_add(parent, newwork, true);
1525 cred = NULL; 1531 if (!ret)
1526 set_ti_thread_flag(task_thread_info(parent), TIF_NOTIFY_RESUME); 1532 newwork = NULL;
1527 1533unlock:
1528 write_unlock_irq(&tasklist_lock);
1529 rcu_read_unlock();
1530 if (oldcred)
1531 put_cred(oldcred);
1532 return 0;
1533
1534already_same:
1535 ret = 0;
1536not_permitted:
1537 write_unlock_irq(&tasklist_lock); 1534 write_unlock_irq(&tasklist_lock);
1538 rcu_read_unlock(); 1535 rcu_read_unlock();
1539 put_cred(cred); 1536 if (oldwork) {
1537 put_cred(oldwork->data);
1538 kfree(oldwork);
1539 }
1540 if (newwork) {
1541 put_cred(newwork->data);
1542 kfree(newwork);
1543 }
1540 return ret; 1544 return ret;
1541 1545
1546error_newwork:
1547 kfree(newwork);
1542error_keyring: 1548error_keyring:
1543 key_ref_put(keyring_r); 1549 key_ref_put(keyring_r);
1544 return ret; 1550 return ret;
1545
1546#else /* !TIF_NOTIFY_RESUME */
1547 /*
1548 * To be removed when TIF_NOTIFY_RESUME has been implemented on
1549 * m68k/xtensa
1550 */
1551#warning TIF_NOTIFY_RESUME not implemented
1552 return -EOPNOTSUPP;
1553#endif /* !TIF_NOTIFY_RESUME */
1554} 1551}
1555 1552
1556/* 1553/*
diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
index d71056db7b67..4ad54eea1ea4 100644
--- a/security/keys/process_keys.c
+++ b/security/keys/process_keys.c
@@ -834,23 +834,17 @@ error:
834 * Replace a process's session keyring on behalf of one of its children when 834 * Replace a process's session keyring on behalf of one of its children when
835 * the target process is about to resume userspace execution. 835 * the target process is about to resume userspace execution.
836 */ 836 */
837void key_replace_session_keyring(void) 837void key_change_session_keyring(struct task_work *twork)
838{ 838{
839 const struct cred *old; 839 const struct cred *old = current_cred();
840 struct cred *new; 840 struct cred *new = twork->data;
841
842 if (!current->replacement_session_keyring)
843 return;
844 841
845 write_lock_irq(&tasklist_lock); 842 kfree(twork);
846 new = current->replacement_session_keyring; 843 if (unlikely(current->flags & PF_EXITING)) {
847 current->replacement_session_keyring = NULL; 844 put_cred(new);
848 write_unlock_irq(&tasklist_lock);
849
850 if (!new)
851 return; 845 return;
846 }
852 847
853 old = current_cred();
854 new-> uid = old-> uid; 848 new-> uid = old-> uid;
855 new-> euid = old-> euid; 849 new-> euid = old-> euid;
856 new-> suid = old-> suid; 850 new-> suid = old-> suid;
diff --git a/security/keys/request_key.c b/security/keys/request_key.c
index cc3790315d2f..000e75017520 100644
--- a/security/keys/request_key.c
+++ b/security/keys/request_key.c
@@ -93,16 +93,9 @@ static void umh_keys_cleanup(struct subprocess_info *info)
93static int call_usermodehelper_keys(char *path, char **argv, char **envp, 93static int call_usermodehelper_keys(char *path, char **argv, char **envp,
94 struct key *session_keyring, int wait) 94 struct key *session_keyring, int wait)
95{ 95{
96 gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL; 96 return call_usermodehelper_fns(path, argv, envp, wait,
97 struct subprocess_info *info = 97 umh_keys_init, umh_keys_cleanup,
98 call_usermodehelper_setup(path, argv, envp, gfp_mask); 98 key_get(session_keyring));
99
100 if (!info)
101 return -ENOMEM;
102
103 call_usermodehelper_setfns(info, umh_keys_init, umh_keys_cleanup,
104 key_get(session_keyring));
105 return call_usermodehelper_exec(info, wait);
106} 99}
107 100
108/* 101/*
diff --git a/security/security.c b/security/security.c
index 5497a57fba01..3efc9b12aef4 100644
--- a/security/security.c
+++ b/security/security.c
@@ -20,6 +20,9 @@
20#include <linux/ima.h> 20#include <linux/ima.h>
21#include <linux/evm.h> 21#include <linux/evm.h>
22#include <linux/fsnotify.h> 22#include <linux/fsnotify.h>
23#include <linux/mman.h>
24#include <linux/mount.h>
25#include <linux/personality.h>
23#include <net/flow.h> 26#include <net/flow.h>
24 27
25#define MAX_LSM_EVM_XATTR 2 28#define MAX_LSM_EVM_XATTR 2
@@ -657,18 +660,56 @@ int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
657 return security_ops->file_ioctl(file, cmd, arg); 660 return security_ops->file_ioctl(file, cmd, arg);
658} 661}
659 662
660int security_file_mmap(struct file *file, unsigned long reqprot, 663static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
661 unsigned long prot, unsigned long flags,
662 unsigned long addr, unsigned long addr_only)
663{ 664{
664 int ret; 665 /*
666 * Does we have PROT_READ and does the application expect
667 * it to imply PROT_EXEC? If not, nothing to talk about...
668 */
669 if ((prot & (PROT_READ | PROT_EXEC)) != PROT_READ)
670 return prot;
671 if (!(current->personality & READ_IMPLIES_EXEC))
672 return prot;
673 /*
674 * if that's an anonymous mapping, let it.
675 */
676 if (!file)
677 return prot | PROT_EXEC;
678 /*
679 * ditto if it's not on noexec mount, except that on !MMU we need
680 * BDI_CAP_EXEC_MMAP (== VM_MAYEXEC) in this case
681 */
682 if (!(file->f_path.mnt->mnt_flags & MNT_NOEXEC)) {
683#ifndef CONFIG_MMU
684 unsigned long caps = 0;
685 struct address_space *mapping = file->f_mapping;
686 if (mapping && mapping->backing_dev_info)
687 caps = mapping->backing_dev_info->capabilities;
688 if (!(caps & BDI_CAP_EXEC_MAP))
689 return prot;
690#endif
691 return prot | PROT_EXEC;
692 }
693 /* anything on noexec mount won't get PROT_EXEC */
694 return prot;
695}
665 696
666 ret = security_ops->file_mmap(file, reqprot, prot, flags, addr, addr_only); 697int security_mmap_file(struct file *file, unsigned long prot,
698 unsigned long flags)
699{
700 int ret;
701 ret = security_ops->mmap_file(file, prot,
702 mmap_prot(file, prot), flags);
667 if (ret) 703 if (ret)
668 return ret; 704 return ret;
669 return ima_file_mmap(file, prot); 705 return ima_file_mmap(file, prot);
670} 706}
671 707
708int security_mmap_addr(unsigned long addr)
709{
710 return security_ops->mmap_addr(addr);
711}
712
672int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot, 713int security_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
673 unsigned long prot) 714 unsigned long prot)
674{ 715{
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index fa2341b68331..372ec6502aa8 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3083,9 +3083,7 @@ error:
3083 return rc; 3083 return rc;
3084} 3084}
3085 3085
3086static int selinux_file_mmap(struct file *file, unsigned long reqprot, 3086static int selinux_mmap_addr(unsigned long addr)
3087 unsigned long prot, unsigned long flags,
3088 unsigned long addr, unsigned long addr_only)
3089{ 3087{
3090 int rc = 0; 3088 int rc = 0;
3091 u32 sid = current_sid(); 3089 u32 sid = current_sid();
@@ -3104,10 +3102,12 @@ static int selinux_file_mmap(struct file *file, unsigned long reqprot,
3104 } 3102 }
3105 3103
3106 /* do DAC check on address space usage */ 3104 /* do DAC check on address space usage */
3107 rc = cap_file_mmap(file, reqprot, prot, flags, addr, addr_only); 3105 return cap_mmap_addr(addr);
3108 if (rc || addr_only) 3106}
3109 return rc;
3110 3107
3108static int selinux_mmap_file(struct file *file, unsigned long reqprot,
3109 unsigned long prot, unsigned long flags)
3110{
3111 if (selinux_checkreqprot) 3111 if (selinux_checkreqprot)
3112 prot = reqprot; 3112 prot = reqprot;
3113 3113
@@ -5570,7 +5570,8 @@ static struct security_operations selinux_ops = {
5570 .file_alloc_security = selinux_file_alloc_security, 5570 .file_alloc_security = selinux_file_alloc_security,
5571 .file_free_security = selinux_file_free_security, 5571 .file_free_security = selinux_file_free_security,
5572 .file_ioctl = selinux_file_ioctl, 5572 .file_ioctl = selinux_file_ioctl,
5573 .file_mmap = selinux_file_mmap, 5573 .mmap_file = selinux_mmap_file,
5574 .mmap_addr = selinux_mmap_addr,
5574 .file_mprotect = selinux_file_mprotect, 5575 .file_mprotect = selinux_file_mprotect,
5575 .file_lock = selinux_file_lock, 5576 .file_lock = selinux_file_lock,
5576 .file_fcntl = selinux_file_fcntl, 5577 .file_fcntl = selinux_file_fcntl,
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 4e93f9ef970b..3ad290251288 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -1259,12 +1259,8 @@ static int sel_make_bools(void)
1259 if (!inode) 1259 if (!inode)
1260 goto out; 1260 goto out;
1261 1261
1262 ret = -EINVAL;
1263 len = snprintf(page, PAGE_SIZE, "/%s/%s", BOOL_DIR_NAME, names[i]);
1264 if (len < 0)
1265 goto out;
1266
1267 ret = -ENAMETOOLONG; 1262 ret = -ENAMETOOLONG;
1263 len = snprintf(page, PAGE_SIZE, "/%s/%s", BOOL_DIR_NAME, names[i]);
1268 if (len >= PAGE_SIZE) 1264 if (len >= PAGE_SIZE)
1269 goto out; 1265 goto out;
1270 1266
@@ -1557,19 +1553,10 @@ static inline u32 sel_ino_to_perm(unsigned long ino)
1557static ssize_t sel_read_class(struct file *file, char __user *buf, 1553static ssize_t sel_read_class(struct file *file, char __user *buf,
1558 size_t count, loff_t *ppos) 1554 size_t count, loff_t *ppos)
1559{ 1555{
1560 ssize_t rc, len;
1561 char *page;
1562 unsigned long ino = file->f_path.dentry->d_inode->i_ino; 1556 unsigned long ino = file->f_path.dentry->d_inode->i_ino;
1563 1557 char res[TMPBUFLEN];
1564 page = (char *)__get_free_page(GFP_KERNEL); 1558 ssize_t len = snprintf(res, sizeof(res), "%d", sel_ino_to_class(ino));
1565 if (!page) 1559 return simple_read_from_buffer(buf, count, ppos, res, len);
1566 return -ENOMEM;
1567
1568 len = snprintf(page, PAGE_SIZE, "%d", sel_ino_to_class(ino));
1569 rc = simple_read_from_buffer(buf, count, ppos, page, len);
1570 free_page((unsigned long)page);
1571
1572 return rc;
1573} 1560}
1574 1561
1575static const struct file_operations sel_class_ops = { 1562static const struct file_operations sel_class_ops = {
@@ -1580,19 +1567,10 @@ static const struct file_operations sel_class_ops = {
1580static ssize_t sel_read_perm(struct file *file, char __user *buf, 1567static ssize_t sel_read_perm(struct file *file, char __user *buf,
1581 size_t count, loff_t *ppos) 1568 size_t count, loff_t *ppos)
1582{ 1569{
1583 ssize_t rc, len;
1584 char *page;
1585 unsigned long ino = file->f_path.dentry->d_inode->i_ino; 1570 unsigned long ino = file->f_path.dentry->d_inode->i_ino;
1586 1571 char res[TMPBUFLEN];
1587 page = (char *)__get_free_page(GFP_KERNEL); 1572 ssize_t len = snprintf(res, sizeof(res), "%d", sel_ino_to_perm(ino));
1588 if (!page) 1573 return simple_read_from_buffer(buf, count, ppos, res, len);
1589 return -ENOMEM;
1590
1591 len = snprintf(page, PAGE_SIZE, "%d", sel_ino_to_perm(ino));
1592 rc = simple_read_from_buffer(buf, count, ppos, page, len);
1593 free_page((unsigned long)page);
1594
1595 return rc;
1596} 1574}
1597 1575
1598static const struct file_operations sel_perm_ops = { 1576static const struct file_operations sel_perm_ops = {
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index d583c0545808..ee0bb5735f35 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1171,7 +1171,7 @@ static int smack_file_fcntl(struct file *file, unsigned int cmd,
1171} 1171}
1172 1172
1173/** 1173/**
1174 * smack_file_mmap : 1174 * smack_mmap_file :
1175 * Check permissions for a mmap operation. The @file may be NULL, e.g. 1175 * Check permissions for a mmap operation. The @file may be NULL, e.g.
1176 * if mapping anonymous memory. 1176 * if mapping anonymous memory.
1177 * @file contains the file structure for file to map (may be NULL). 1177 * @file contains the file structure for file to map (may be NULL).
@@ -1180,10 +1180,9 @@ static int smack_file_fcntl(struct file *file, unsigned int cmd,
1180 * @flags contains the operational flags. 1180 * @flags contains the operational flags.
1181 * Return 0 if permission is granted. 1181 * Return 0 if permission is granted.
1182 */ 1182 */
1183static int smack_file_mmap(struct file *file, 1183static int smack_mmap_file(struct file *file,
1184 unsigned long reqprot, unsigned long prot, 1184 unsigned long reqprot, unsigned long prot,
1185 unsigned long flags, unsigned long addr, 1185 unsigned long flags)
1186 unsigned long addr_only)
1187{ 1186{
1188 struct smack_known *skp; 1187 struct smack_known *skp;
1189 struct smack_rule *srp; 1188 struct smack_rule *srp;
@@ -1198,11 +1197,6 @@ static int smack_file_mmap(struct file *file,
1198 int tmay; 1197 int tmay;
1199 int rc; 1198 int rc;
1200 1199
1201 /* do DAC check on address space usage */
1202 rc = cap_file_mmap(file, reqprot, prot, flags, addr, addr_only);
1203 if (rc || addr_only)
1204 return rc;
1205
1206 if (file == NULL || file->f_dentry == NULL) 1200 if (file == NULL || file->f_dentry == NULL)
1207 return 0; 1201 return 0;
1208 1202
@@ -3482,7 +3476,8 @@ struct security_operations smack_ops = {
3482 .file_ioctl = smack_file_ioctl, 3476 .file_ioctl = smack_file_ioctl,
3483 .file_lock = smack_file_lock, 3477 .file_lock = smack_file_lock,
3484 .file_fcntl = smack_file_fcntl, 3478 .file_fcntl = smack_file_fcntl,
3485 .file_mmap = smack_file_mmap, 3479 .mmap_file = smack_mmap_file,
3480 .mmap_addr = cap_mmap_addr,
3486 .file_set_fowner = smack_file_set_fowner, 3481 .file_set_fowner = smack_file_set_fowner,
3487 .file_send_sigiotask = smack_file_send_sigiotask, 3482 .file_send_sigiotask = smack_file_send_sigiotask,
3488 .file_receive = smack_file_receive, 3483 .file_receive = smack_file_receive,
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 0a5027b94714..b8ac8710f47f 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -1988,6 +1988,13 @@ static int hdspm_get_system_sample_rate(struct hdspm *hdspm)
1988 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); 1988 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
1989 rate = hdspm_calc_dds_value(hdspm, period); 1989 rate = hdspm_calc_dds_value(hdspm, period);
1990 1990
1991 if (rate > 207000) {
1992 /* Unreasonable high sample rate as seen on PCI MADI cards.
1993 * Use the cached value instead.
1994 */
1995 rate = hdspm->system_sample_rate;
1996 }
1997
1991 return rate; 1998 return rate;
1992} 1999}
1993 2000
diff --git a/sound/soc/fsl/imx-ssi.c b/sound/soc/fsl/imx-ssi.c
index cf3ed0362c9c..28dd76c7cb1c 100644
--- a/sound/soc/fsl/imx-ssi.c
+++ b/sound/soc/fsl/imx-ssi.c
@@ -543,7 +543,7 @@ static int imx_ssi_probe(struct platform_device *pdev)
543 ret); 543 ret);
544 goto failed_clk; 544 goto failed_clk;
545 } 545 }
546 clk_enable(ssi->clk); 546 clk_prepare_enable(ssi->clk);
547 547
548 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 548 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
549 if (!res) { 549 if (!res) {
@@ -641,7 +641,7 @@ failed_ac97:
641failed_ioremap: 641failed_ioremap:
642 release_mem_region(res->start, resource_size(res)); 642 release_mem_region(res->start, resource_size(res));
643failed_get_resource: 643failed_get_resource:
644 clk_disable(ssi->clk); 644 clk_disable_unprepare(ssi->clk);
645 clk_put(ssi->clk); 645 clk_put(ssi->clk);
646failed_clk: 646failed_clk:
647 kfree(ssi); 647 kfree(ssi);
@@ -664,7 +664,7 @@ static int __devexit imx_ssi_remove(struct platform_device *pdev)
664 664
665 iounmap(ssi->base); 665 iounmap(ssi->base);
666 release_mem_region(res->start, resource_size(res)); 666 release_mem_region(res->start, resource_size(res));
667 clk_disable(ssi->clk); 667 clk_disable_unprepare(ssi->clk);
668 clk_put(ssi->clk); 668 clk_put(ssi->clk);
669 kfree(ssi); 669 kfree(ssi);
670 670
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 7cee22515d9d..2ef98536f1da 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -1052,6 +1052,13 @@ static int fsi_dma_quit(struct fsi_priv *fsi, struct fsi_stream *io)
1052 return 0; 1052 return 0;
1053} 1053}
1054 1054
1055static dma_addr_t fsi_dma_get_area(struct fsi_stream *io)
1056{
1057 struct snd_pcm_runtime *runtime = io->substream->runtime;
1058
1059 return io->dma + samples_to_bytes(runtime, io->buff_sample_pos);
1060}
1061
1055static void fsi_dma_complete(void *data) 1062static void fsi_dma_complete(void *data)
1056{ 1063{
1057 struct fsi_stream *io = (struct fsi_stream *)data; 1064 struct fsi_stream *io = (struct fsi_stream *)data;
@@ -1061,7 +1068,7 @@ static void fsi_dma_complete(void *data)
1061 enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ? 1068 enum dma_data_direction dir = fsi_stream_is_play(fsi, io) ?
1062 DMA_TO_DEVICE : DMA_FROM_DEVICE; 1069 DMA_TO_DEVICE : DMA_FROM_DEVICE;
1063 1070
1064 dma_sync_single_for_cpu(dai->dev, io->dma, 1071 dma_sync_single_for_cpu(dai->dev, fsi_dma_get_area(io),
1065 samples_to_bytes(runtime, io->period_samples), dir); 1072 samples_to_bytes(runtime, io->period_samples), dir);
1066 1073
1067 io->buff_sample_pos += io->period_samples; 1074 io->buff_sample_pos += io->period_samples;
@@ -1078,13 +1085,6 @@ static void fsi_dma_complete(void *data)
1078 snd_pcm_period_elapsed(io->substream); 1085 snd_pcm_period_elapsed(io->substream);
1079} 1086}
1080 1087
1081static dma_addr_t fsi_dma_get_area(struct fsi_stream *io)
1082{
1083 struct snd_pcm_runtime *runtime = io->substream->runtime;
1084
1085 return io->dma + samples_to_bytes(runtime, io->buff_sample_pos);
1086}
1087
1088static void fsi_dma_do_tasklet(unsigned long data) 1088static void fsi_dma_do_tasklet(unsigned long data)
1089{ 1089{
1090 struct fsi_stream *io = (struct fsi_stream *)data; 1090 struct fsi_stream *io = (struct fsi_stream *)data;
@@ -1110,7 +1110,7 @@ static void fsi_dma_do_tasklet(unsigned long data)
1110 len = samples_to_bytes(runtime, io->period_samples); 1110 len = samples_to_bytes(runtime, io->period_samples);
1111 buf = fsi_dma_get_area(io); 1111 buf = fsi_dma_get_area(io);
1112 1112
1113 dma_sync_single_for_device(dai->dev, io->dma, len, dir); 1113 dma_sync_single_for_device(dai->dev, buf, len, dir);
1114 1114
1115 sg_init_table(&sg, 1); 1115 sg_init_table(&sg, 1);
1116 sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf)), 1116 sg_set_page(&sg, pfn_to_page(PFN_DOWN(buf)),
@@ -1172,9 +1172,16 @@ static int fsi_dma_transfer(struct fsi_priv *fsi, struct fsi_stream *io)
1172static void fsi_dma_push_start_stop(struct fsi_priv *fsi, struct fsi_stream *io, 1172static void fsi_dma_push_start_stop(struct fsi_priv *fsi, struct fsi_stream *io,
1173 int start) 1173 int start)
1174{ 1174{
1175 struct fsi_master *master = fsi_get_master(fsi);
1176 u32 clk = fsi_is_port_a(fsi) ? CRA : CRB;
1175 u32 enable = start ? DMA_ON : 0; 1177 u32 enable = start ? DMA_ON : 0;
1176 1178
1177 fsi_reg_mask_set(fsi, OUT_DMAC, DMA_ON, enable); 1179 fsi_reg_mask_set(fsi, OUT_DMAC, DMA_ON, enable);
1180
1181 dmaengine_terminate_all(io->chan);
1182
1183 if (fsi_is_clk_master(fsi))
1184 fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0);
1178} 1185}
1179 1186
1180static int fsi_dma_probe(struct fsi_priv *fsi, struct fsi_stream *io) 1187static int fsi_dma_probe(struct fsi_priv *fsi, struct fsi_stream *io)
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 24839d932648..cdf8b7601973 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -788,6 +788,9 @@ static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
788 int count = 0, needs_knot = 0; 788 int count = 0, needs_knot = 0;
789 int err; 789 int err;
790 790
791 kfree(subs->rate_list.list);
792 subs->rate_list.list = NULL;
793
791 list_for_each_entry(fp, &subs->fmt_list, list) { 794 list_for_each_entry(fp, &subs->fmt_list, list) {
792 if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) 795 if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS)
793 return 0; 796 return 0;
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 28bc57ee757c..a4162e15c25f 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -1,4 +1,4 @@
1TARGETS = breakpoints vm 1TARGETS = breakpoints kcmp mqueue vm
2 2
3all: 3all:
4 for TARGET in $(TARGETS); do \ 4 for TARGET in $(TARGETS); do \
diff --git a/tools/testing/selftests/kcmp/Makefile b/tools/testing/selftests/kcmp/Makefile
new file mode 100644
index 000000000000..dc79b86ea65c
--- /dev/null
+++ b/tools/testing/selftests/kcmp/Makefile
@@ -0,0 +1,29 @@
1uname_M := $(shell uname -m 2>/dev/null || echo not)
2ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/)
3ifeq ($(ARCH),i386)
4 ARCH := X86
5 CFLAGS := -DCONFIG_X86_32 -D__i386__
6endif
7ifeq ($(ARCH),x86_64)
8 ARCH := X86
9 CFLAGS := -DCONFIG_X86_64 -D__x86_64__
10endif
11
12CFLAGS += -I../../../../arch/x86/include/generated/
13CFLAGS += -I../../../../include/
14CFLAGS += -I../../../../usr/include/
15CFLAGS += -I../../../../arch/x86/include/
16
17all:
18ifeq ($(ARCH),X86)
19 gcc $(CFLAGS) kcmp_test.c -o run_test
20else
21 echo "Not an x86 target, can't build kcmp selftest"
22endif
23
24run-tests: all
25 ./kcmp_test
26
27clean:
28 rm -fr ./run_test
29 rm -fr ./test-file
diff --git a/tools/testing/selftests/kcmp/kcmp_test.c b/tools/testing/selftests/kcmp/kcmp_test.c
new file mode 100644
index 000000000000..358cc6bfa35d
--- /dev/null
+++ b/tools/testing/selftests/kcmp/kcmp_test.c
@@ -0,0 +1,94 @@
1#define _GNU_SOURCE
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <signal.h>
6#include <limits.h>
7#include <unistd.h>
8#include <errno.h>
9#include <string.h>
10#include <fcntl.h>
11
12#include <linux/unistd.h>
13#include <linux/kcmp.h>
14
15#include <sys/syscall.h>
16#include <sys/types.h>
17#include <sys/stat.h>
18#include <sys/wait.h>
19
20static long sys_kcmp(int pid1, int pid2, int type, int fd1, int fd2)
21{
22 return syscall(__NR_kcmp, pid1, pid2, type, fd1, fd2);
23}
24
25int main(int argc, char **argv)
26{
27 const char kpath[] = "kcmp-test-file";
28 int pid1, pid2;
29 int fd1, fd2;
30 int status;
31
32 fd1 = open(kpath, O_RDWR | O_CREAT | O_TRUNC, 0644);
33 pid1 = getpid();
34
35 if (fd1 < 0) {
36 perror("Can't create file");
37 exit(1);
38 }
39
40 pid2 = fork();
41 if (pid2 < 0) {
42 perror("fork failed");
43 exit(1);
44 }
45
46 if (!pid2) {
47 int pid2 = getpid();
48 int ret;
49
50 fd2 = open(kpath, O_RDWR, 0644);
51 if (fd2 < 0) {
52 perror("Can't open file");
53 exit(1);
54 }
55
56 /* An example of output and arguments */
57 printf("pid1: %6d pid2: %6d FD: %2ld FILES: %2ld VM: %2ld "
58 "FS: %2ld SIGHAND: %2ld IO: %2ld SYSVSEM: %2ld "
59 "INV: %2ld\n",
60 pid1, pid2,
61 sys_kcmp(pid1, pid2, KCMP_FILE, fd1, fd2),
62 sys_kcmp(pid1, pid2, KCMP_FILES, 0, 0),
63 sys_kcmp(pid1, pid2, KCMP_VM, 0, 0),
64 sys_kcmp(pid1, pid2, KCMP_FS, 0, 0),
65 sys_kcmp(pid1, pid2, KCMP_SIGHAND, 0, 0),
66 sys_kcmp(pid1, pid2, KCMP_IO, 0, 0),
67 sys_kcmp(pid1, pid2, KCMP_SYSVSEM, 0, 0),
68
69 /* This one should fail */
70 sys_kcmp(pid1, pid2, KCMP_TYPES + 1, 0, 0));
71
72 /* This one should return same fd */
73 ret = sys_kcmp(pid1, pid2, KCMP_FILE, fd1, fd1);
74 if (ret) {
75 printf("FAIL: 0 expected but %d returned\n", ret);
76 ret = -1;
77 } else
78 printf("PASS: 0 returned as expected\n");
79
80 /* Compare with self */
81 ret = sys_kcmp(pid1, pid1, KCMP_VM, 0, 0);
82 if (ret) {
83 printf("FAIL: 0 expected but %li returned\n", ret);
84 ret = -1;
85 } else
86 printf("PASS: 0 returned as expected\n");
87
88 exit(ret);
89 }
90
91 waitpid(pid2, &status, P_ALL);
92
93 return 0;
94}
diff --git a/tools/testing/selftests/mqueue/.gitignore b/tools/testing/selftests/mqueue/.gitignore
new file mode 100644
index 000000000000..d8d42377205a
--- /dev/null
+++ b/tools/testing/selftests/mqueue/.gitignore
@@ -0,0 +1,2 @@
1mq_open_tests
2mq_perf_tests
diff --git a/tools/testing/selftests/mqueue/Makefile b/tools/testing/selftests/mqueue/Makefile
new file mode 100644
index 000000000000..54c0aad2b47c
--- /dev/null
+++ b/tools/testing/selftests/mqueue/Makefile
@@ -0,0 +1,10 @@
1all:
2 gcc -O2 -lrt mq_open_tests.c -o mq_open_tests
3 gcc -O2 -lrt -lpthread -lpopt -o mq_perf_tests mq_perf_tests.c
4
5run_tests:
6 ./mq_open_tests /test1
7 ./mq_perf_tests
8
9clean:
10 rm -f mq_open_tests mq_perf_tests
diff --git a/tools/testing/selftests/mqueue/mq_open_tests.c b/tools/testing/selftests/mqueue/mq_open_tests.c
new file mode 100644
index 000000000000..711cc2923047
--- /dev/null
+++ b/tools/testing/selftests/mqueue/mq_open_tests.c
@@ -0,0 +1,492 @@
1/*
2 * This application is Copyright 2012 Red Hat, Inc.
3 * Doug Ledford <dledford@redhat.com>
4 *
5 * mq_open_tests is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * mq_open_tests 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
12 * GNU General Public License for more details.
13 *
14 * For the full text of the license, see <http://www.gnu.org/licenses/>.
15 *
16 * mq_open_tests.c
17 * Tests the various situations that should either succeed or fail to
18 * open a posix message queue and then reports whether or not they
19 * did as they were supposed to.
20 *
21 */
22#include <stdio.h>
23#include <stdlib.h>
24#include <unistd.h>
25#include <fcntl.h>
26#include <string.h>
27#include <limits.h>
28#include <errno.h>
29#include <sys/types.h>
30#include <sys/time.h>
31#include <sys/resource.h>
32#include <sys/stat.h>
33#include <mqueue.h>
34
35static char *usage =
36"Usage:\n"
37" %s path\n"
38"\n"
39" path Path name of the message queue to create\n"
40"\n"
41" Note: this program must be run as root in order to enable all tests\n"
42"\n";
43
44char *DEF_MSGS = "/proc/sys/fs/mqueue/msg_default";
45char *DEF_MSGSIZE = "/proc/sys/fs/mqueue/msgsize_default";
46char *MAX_MSGS = "/proc/sys/fs/mqueue/msg_max";
47char *MAX_MSGSIZE = "/proc/sys/fs/mqueue/msgsize_max";
48
49int default_settings;
50struct rlimit saved_limits, cur_limits;
51int saved_def_msgs, saved_def_msgsize, saved_max_msgs, saved_max_msgsize;
52int cur_def_msgs, cur_def_msgsize, cur_max_msgs, cur_max_msgsize;
53FILE *def_msgs, *def_msgsize, *max_msgs, *max_msgsize;
54char *queue_path;
55mqd_t queue = -1;
56
57static inline void __set(FILE *stream, int value, char *err_msg);
58void shutdown(int exit_val, char *err_cause, int line_no);
59static inline int get(FILE *stream);
60static inline void set(FILE *stream, int value);
61static inline void getr(int type, struct rlimit *rlim);
62static inline void setr(int type, struct rlimit *rlim);
63void validate_current_settings();
64static inline void test_queue(struct mq_attr *attr, struct mq_attr *result);
65static inline int test_queue_fail(struct mq_attr *attr, struct mq_attr *result);
66
67static inline void __set(FILE *stream, int value, char *err_msg)
68{
69 rewind(stream);
70 if (fprintf(stream, "%d", value) < 0)
71 perror(err_msg);
72}
73
74
75void shutdown(int exit_val, char *err_cause, int line_no)
76{
77 static int in_shutdown = 0;
78
79 /* In case we get called recursively by a set() call below */
80 if (in_shutdown++)
81 return;
82
83 seteuid(0);
84
85 if (queue != -1)
86 if (mq_close(queue))
87 perror("mq_close() during shutdown");
88 if (queue_path)
89 /*
90 * Be silent if this fails, if we cleaned up already it's
91 * expected to fail
92 */
93 mq_unlink(queue_path);
94 if (default_settings) {
95 if (saved_def_msgs)
96 __set(def_msgs, saved_def_msgs,
97 "failed to restore saved_def_msgs");
98 if (saved_def_msgsize)
99 __set(def_msgsize, saved_def_msgsize,
100 "failed to restore saved_def_msgsize");
101 }
102 if (saved_max_msgs)
103 __set(max_msgs, saved_max_msgs,
104 "failed to restore saved_max_msgs");
105 if (saved_max_msgsize)
106 __set(max_msgsize, saved_max_msgsize,
107 "failed to restore saved_max_msgsize");
108 if (exit_val)
109 error(exit_val, errno, "%s at %d", err_cause, line_no);
110 exit(0);
111}
112
113static inline int get(FILE *stream)
114{
115 int value;
116 rewind(stream);
117 if (fscanf(stream, "%d", &value) != 1)
118 shutdown(4, "Error reading /proc entry", __LINE__ - 1);
119 return value;
120}
121
122static inline void set(FILE *stream, int value)
123{
124 int new_value;
125
126 rewind(stream);
127 if (fprintf(stream, "%d", value) < 0)
128 return shutdown(5, "Failed writing to /proc file",
129 __LINE__ - 1);
130 new_value = get(stream);
131 if (new_value != value)
132 return shutdown(5, "We didn't get what we wrote to /proc back",
133 __LINE__ - 1);
134}
135
136static inline void getr(int type, struct rlimit *rlim)
137{
138 if (getrlimit(type, rlim))
139 shutdown(6, "getrlimit()", __LINE__ - 1);
140}
141
142static inline void setr(int type, struct rlimit *rlim)
143{
144 if (setrlimit(type, rlim))
145 shutdown(7, "setrlimit()", __LINE__ - 1);
146}
147
148void validate_current_settings()
149{
150 int rlim_needed;
151
152 if (cur_limits.rlim_cur < 4096) {
153 printf("Current rlimit value for POSIX message queue bytes is "
154 "unreasonably low,\nincreasing.\n\n");
155 cur_limits.rlim_cur = 8192;
156 cur_limits.rlim_max = 16384;
157 setr(RLIMIT_MSGQUEUE, &cur_limits);
158 }
159
160 if (default_settings) {
161 rlim_needed = (cur_def_msgs + 1) * (cur_def_msgsize + 1 +
162 2 * sizeof(void *));
163 if (rlim_needed > cur_limits.rlim_cur) {
164 printf("Temporarily lowering default queue parameters "
165 "to something that will work\n"
166 "with the current rlimit values.\n\n");
167 set(def_msgs, 10);
168 cur_def_msgs = 10;
169 set(def_msgsize, 128);
170 cur_def_msgsize = 128;
171 }
172 } else {
173 rlim_needed = (cur_max_msgs + 1) * (cur_max_msgsize + 1 +
174 2 * sizeof(void *));
175 if (rlim_needed > cur_limits.rlim_cur) {
176 printf("Temporarily lowering maximum queue parameters "
177 "to something that will work\n"
178 "with the current rlimit values in case this is "
179 "a kernel that ties the default\n"
180 "queue parameters to the maximum queue "
181 "parameters.\n\n");
182 set(max_msgs, 10);
183 cur_max_msgs = 10;
184 set(max_msgsize, 128);
185 cur_max_msgsize = 128;
186 }
187 }
188}
189
190/*
191 * test_queue - Test opening a queue, shutdown if we fail. This should
192 * only be called in situations that should never fail. We clean up
193 * after ourselves and return the queue attributes in *result.
194 */
195static inline void test_queue(struct mq_attr *attr, struct mq_attr *result)
196{
197 int flags = O_RDWR | O_EXCL | O_CREAT;
198 int perms = DEFFILEMODE;
199
200 if ((queue = mq_open(queue_path, flags, perms, attr)) == -1)
201 shutdown(1, "mq_open()", __LINE__);
202 if (mq_getattr(queue, result))
203 shutdown(1, "mq_getattr()", __LINE__);
204 if (mq_close(queue))
205 shutdown(1, "mq_close()", __LINE__);
206 queue = -1;
207 if (mq_unlink(queue_path))
208 shutdown(1, "mq_unlink()", __LINE__);
209}
210
211/*
212 * Same as test_queue above, but failure is not fatal.
213 * Returns:
214 * 0 - Failed to create a queue
215 * 1 - Created a queue, attributes in *result
216 */
217static inline int test_queue_fail(struct mq_attr *attr, struct mq_attr *result)
218{
219 int flags = O_RDWR | O_EXCL | O_CREAT;
220 int perms = DEFFILEMODE;
221
222 if ((queue = mq_open(queue_path, flags, perms, attr)) == -1)
223 return 0;
224 if (mq_getattr(queue, result))
225 shutdown(1, "mq_getattr()", __LINE__);
226 if (mq_close(queue))
227 shutdown(1, "mq_close()", __LINE__);
228 queue = -1;
229 if (mq_unlink(queue_path))
230 shutdown(1, "mq_unlink()", __LINE__);
231 return 1;
232}
233
234int main(int argc, char *argv[])
235{
236 struct mq_attr attr, result;
237
238 if (argc != 2) {
239 fprintf(stderr, "Must pass a valid queue name\n\n");
240 fprintf(stderr, usage, argv[0]);
241 exit(1);
242 }
243
244 /*
245 * Although we can create a msg queue with a non-absolute path name,
246 * unlink will fail. So, if the name doesn't start with a /, add one
247 * when we save it.
248 */
249 if (*argv[1] == '/')
250 queue_path = strdup(argv[1]);
251 else {
252 queue_path = malloc(strlen(argv[1]) + 2);
253 if (!queue_path) {
254 perror("malloc()");
255 exit(1);
256 }
257 queue_path[0] = '/';
258 queue_path[1] = 0;
259 strcat(queue_path, argv[1]);
260 }
261
262 if (getuid() != 0) {
263 fprintf(stderr, "Not running as root, but almost all tests "
264 "require root in order to modify\nsystem settings. "
265 "Exiting.\n");
266 exit(1);
267 }
268
269 /* Find out what files there are for us to make tweaks in */
270 def_msgs = fopen(DEF_MSGS, "r+");
271 def_msgsize = fopen(DEF_MSGSIZE, "r+");
272 max_msgs = fopen(MAX_MSGS, "r+");
273 max_msgsize = fopen(MAX_MSGSIZE, "r+");
274
275 if (!max_msgs)
276 shutdown(2, "Failed to open msg_max", __LINE__);
277 if (!max_msgsize)
278 shutdown(2, "Failed to open msgsize_max", __LINE__);
279 if (def_msgs || def_msgsize)
280 default_settings = 1;
281
282 /* Load up the current system values for everything we can */
283 getr(RLIMIT_MSGQUEUE, &saved_limits);
284 cur_limits = saved_limits;
285 if (default_settings) {
286 saved_def_msgs = cur_def_msgs = get(def_msgs);
287 saved_def_msgsize = cur_def_msgsize = get(def_msgsize);
288 }
289 saved_max_msgs = cur_max_msgs = get(max_msgs);
290 saved_max_msgsize = cur_max_msgsize = get(max_msgsize);
291
292 /* Tell the user our initial state */
293 printf("\nInitial system state:\n");
294 printf("\tUsing queue path:\t\t%s\n", queue_path);
295 printf("\tRLIMIT_MSGQUEUE(soft):\t\t%d\n", saved_limits.rlim_cur);
296 printf("\tRLIMIT_MSGQUEUE(hard):\t\t%d\n", saved_limits.rlim_max);
297 printf("\tMaximum Message Size:\t\t%d\n", saved_max_msgsize);
298 printf("\tMaximum Queue Size:\t\t%d\n", saved_max_msgs);
299 if (default_settings) {
300 printf("\tDefault Message Size:\t\t%d\n", saved_def_msgsize);
301 printf("\tDefault Queue Size:\t\t%d\n", saved_def_msgs);
302 } else {
303 printf("\tDefault Message Size:\t\tNot Supported\n");
304 printf("\tDefault Queue Size:\t\tNot Supported\n");
305 }
306 printf("\n");
307
308 validate_current_settings();
309
310 printf("Adjusted system state for testing:\n");
311 printf("\tRLIMIT_MSGQUEUE(soft):\t\t%d\n", cur_limits.rlim_cur);
312 printf("\tRLIMIT_MSGQUEUE(hard):\t\t%d\n", cur_limits.rlim_max);
313 printf("\tMaximum Message Size:\t\t%d\n", cur_max_msgsize);
314 printf("\tMaximum Queue Size:\t\t%d\n", cur_max_msgs);
315 if (default_settings) {
316 printf("\tDefault Message Size:\t\t%d\n", cur_def_msgsize);
317 printf("\tDefault Queue Size:\t\t%d\n", cur_def_msgs);
318 }
319
320 printf("\n\nTest series 1, behavior when no attr struct "
321 "passed to mq_open:\n");
322 if (!default_settings) {
323 test_queue(NULL, &result);
324 printf("Given sane system settings, mq_open without an attr "
325 "struct succeeds:\tPASS\n");
326 if (result.mq_maxmsg != cur_max_msgs ||
327 result.mq_msgsize != cur_max_msgsize) {
328 printf("Kernel does not support setting the default "
329 "mq attributes,\nbut also doesn't tie the "
330 "defaults to the maximums:\t\t\tPASS\n");
331 } else {
332 set(max_msgs, ++cur_max_msgs);
333 set(max_msgsize, ++cur_max_msgsize);
334 test_queue(NULL, &result);
335 if (result.mq_maxmsg == cur_max_msgs &&
336 result.mq_msgsize == cur_max_msgsize)
337 printf("Kernel does not support setting the "
338 "default mq attributes and\n"
339 "also ties system wide defaults to "
340 "the system wide maximums:\t\t"
341 "FAIL\n");
342 else
343 printf("Kernel does not support setting the "
344 "default mq attributes,\n"
345 "but also doesn't tie the defaults to "
346 "the maximums:\t\t\tPASS\n");
347 }
348 } else {
349 printf("Kernel supports setting defaults separately from "
350 "maximums:\t\tPASS\n");
351 /*
352 * While we are here, go ahead and test that the kernel
353 * properly follows the default settings
354 */
355 test_queue(NULL, &result);
356 printf("Given sane values, mq_open without an attr struct "
357 "succeeds:\t\tPASS\n");
358 if (result.mq_maxmsg != cur_def_msgs ||
359 result.mq_msgsize != cur_def_msgsize)
360 printf("Kernel supports setting defaults, but does "
361 "not actually honor them:\tFAIL\n\n");
362 else {
363 set(def_msgs, ++cur_def_msgs);
364 set(def_msgsize, ++cur_def_msgsize);
365 /* In case max was the same as the default */
366 set(max_msgs, ++cur_max_msgs);
367 set(max_msgsize, ++cur_max_msgsize);
368 test_queue(NULL, &result);
369 if (result.mq_maxmsg != cur_def_msgs ||
370 result.mq_msgsize != cur_def_msgsize)
371 printf("Kernel supports setting defaults, but "
372 "does not actually honor them:\t"
373 "FAIL\n");
374 else
375 printf("Kernel properly honors default setting "
376 "knobs:\t\t\t\tPASS\n");
377 }
378 set(def_msgs, cur_max_msgs + 1);
379 cur_def_msgs = cur_max_msgs + 1;
380 set(def_msgsize, cur_max_msgsize + 1);
381 cur_def_msgsize = cur_max_msgsize + 1;
382 if (cur_def_msgs * (cur_def_msgsize + 2 * sizeof(void *)) >=
383 cur_limits.rlim_cur) {
384 cur_limits.rlim_cur = (cur_def_msgs + 2) *
385 (cur_def_msgsize + 2 * sizeof(void *));
386 cur_limits.rlim_max = 2 * cur_limits.rlim_cur;
387 setr(RLIMIT_MSGQUEUE, &cur_limits);
388 }
389 if (test_queue_fail(NULL, &result)) {
390 if (result.mq_maxmsg == cur_max_msgs &&
391 result.mq_msgsize == cur_max_msgsize)
392 printf("Kernel properly limits default values "
393 "to lesser of default/max:\t\tPASS\n");
394 else
395 printf("Kernel does not properly set default "
396 "queue parameters when\ndefaults > "
397 "max:\t\t\t\t\t\t\t\tFAIL\n");
398 } else
399 printf("Kernel fails to open mq because defaults are "
400 "greater than maximums:\tFAIL\n");
401 set(def_msgs, --cur_def_msgs);
402 set(def_msgsize, --cur_def_msgsize);
403 cur_limits.rlim_cur = cur_limits.rlim_max = cur_def_msgs *
404 cur_def_msgsize;
405 setr(RLIMIT_MSGQUEUE, &cur_limits);
406 if (test_queue_fail(NULL, &result))
407 printf("Kernel creates queue even though defaults "
408 "would exceed\nrlimit setting:"
409 "\t\t\t\t\t\t\t\tFAIL\n");
410 else
411 printf("Kernel properly fails to create queue when "
412 "defaults would\nexceed rlimit:"
413 "\t\t\t\t\t\t\t\tPASS\n");
414 }
415
416 /*
417 * Test #2 - open with an attr struct that exceeds rlimit
418 */
419 printf("\n\nTest series 2, behavior when attr struct is "
420 "passed to mq_open:\n");
421 cur_max_msgs = 32;
422 cur_max_msgsize = cur_limits.rlim_max >> 4;
423 set(max_msgs, cur_max_msgs);
424 set(max_msgsize, cur_max_msgsize);
425 attr.mq_maxmsg = cur_max_msgs;
426 attr.mq_msgsize = cur_max_msgsize;
427 if (test_queue_fail(&attr, &result))
428 printf("Queue open in excess of rlimit max when euid = 0 "
429 "succeeded:\t\tFAIL\n");
430 else
431 printf("Queue open in excess of rlimit max when euid = 0 "
432 "failed:\t\tPASS\n");
433 attr.mq_maxmsg = cur_max_msgs + 1;
434 attr.mq_msgsize = 10;
435 if (test_queue_fail(&attr, &result))
436 printf("Queue open with mq_maxmsg > limit when euid = 0 "
437 "succeeded:\t\tPASS\n");
438 else
439 printf("Queue open with mq_maxmsg > limit when euid = 0 "
440 "failed:\t\tFAIL\n");
441 attr.mq_maxmsg = 1;
442 attr.mq_msgsize = cur_max_msgsize + 1;
443 if (test_queue_fail(&attr, &result))
444 printf("Queue open with mq_msgsize > limit when euid = 0 "
445 "succeeded:\t\tPASS\n");
446 else
447 printf("Queue open with mq_msgsize > limit when euid = 0 "
448 "failed:\t\tFAIL\n");
449 attr.mq_maxmsg = 65536;
450 attr.mq_msgsize = 65536;
451 if (test_queue_fail(&attr, &result))
452 printf("Queue open with total size > 2GB when euid = 0 "
453 "succeeded:\t\tFAIL\n");
454 else
455 printf("Queue open with total size > 2GB when euid = 0 "
456 "failed:\t\t\tPASS\n");
457 seteuid(99);
458 attr.mq_maxmsg = cur_max_msgs;
459 attr.mq_msgsize = cur_max_msgsize;
460 if (test_queue_fail(&attr, &result))
461 printf("Queue open in excess of rlimit max when euid = 99 "
462 "succeeded:\t\tFAIL\n");
463 else
464 printf("Queue open in excess of rlimit max when euid = 99 "
465 "failed:\t\tPASS\n");
466 attr.mq_maxmsg = cur_max_msgs + 1;
467 attr.mq_msgsize = 10;
468 if (test_queue_fail(&attr, &result))
469 printf("Queue open with mq_maxmsg > limit when euid = 99 "
470 "succeeded:\t\tFAIL\n");
471 else
472 printf("Queue open with mq_maxmsg > limit when euid = 99 "
473 "failed:\t\tPASS\n");
474 attr.mq_maxmsg = 1;
475 attr.mq_msgsize = cur_max_msgsize + 1;
476 if (test_queue_fail(&attr, &result))
477 printf("Queue open with mq_msgsize > limit when euid = 99 "
478 "succeeded:\t\tFAIL\n");
479 else
480 printf("Queue open with mq_msgsize > limit when euid = 99 "
481 "failed:\t\tPASS\n");
482 attr.mq_maxmsg = 65536;
483 attr.mq_msgsize = 65536;
484 if (test_queue_fail(&attr, &result))
485 printf("Queue open with total size > 2GB when euid = 99 "
486 "succeeded:\t\tFAIL\n");
487 else
488 printf("Queue open with total size > 2GB when euid = 99 "
489 "failed:\t\t\tPASS\n");
490
491 shutdown(0,"",0);
492}
diff --git a/tools/testing/selftests/mqueue/mq_perf_tests.c b/tools/testing/selftests/mqueue/mq_perf_tests.c
new file mode 100644
index 000000000000..2fadd4b97045
--- /dev/null
+++ b/tools/testing/selftests/mqueue/mq_perf_tests.c
@@ -0,0 +1,741 @@
1/*
2 * This application is Copyright 2012 Red Hat, Inc.
3 * Doug Ledford <dledford@redhat.com>
4 *
5 * mq_perf_tests is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * mq_perf_tests 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
12 * GNU General Public License for more details.
13 *
14 * For the full text of the license, see <http://www.gnu.org/licenses/>.
15 *
16 * mq_perf_tests.c
17 * Tests various types of message queue workloads, concentrating on those
18 * situations that invole large message sizes, large message queue depths,
19 * or both, and reports back useful metrics about kernel message queue
20 * performance.
21 *
22 */
23#define _GNU_SOURCE
24#include <stdio.h>
25#include <stdlib.h>
26#include <unistd.h>
27#include <fcntl.h>
28#include <string.h>
29#include <limits.h>
30#include <errno.h>
31#include <signal.h>
32#include <pthread.h>
33#include <sched.h>
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/resource.h>
37#include <sys/stat.h>
38#include <mqueue.h>
39#include <popt.h>
40
41static char *usage =
42"Usage:\n"
43" %s [-c #[,#..] -f] path\n"
44"\n"
45" -c # Skip most tests and go straight to a high queue depth test\n"
46" and then run that test continuously (useful for running at\n"
47" the same time as some other workload to see how much the\n"
48" cache thrashing caused by adding messages to a very deep\n"
49" queue impacts the performance of other programs). The number\n"
50" indicates which CPU core we should bind the process to during\n"
51" the run. If you have more than one physical CPU, then you\n"
52" will need one copy per physical CPU package, and you should\n"
53" specify the CPU cores to pin ourself to via a comma separated\n"
54" list of CPU values.\n"
55" -f Only usable with continuous mode. Pin ourself to the CPUs\n"
56" as requested, then instead of looping doing a high mq\n"
57" workload, just busy loop. This will allow us to lock up a\n"
58" single CPU just like we normally would, but without actually\n"
59" thrashing the CPU cache. This is to make it easier to get\n"
60" comparable numbers from some other workload running on the\n"
61" other CPUs. One set of numbers with # CPUs locked up running\n"
62" an mq workload, and another set of numbers with those same\n"
63" CPUs locked away from the test workload, but not doing\n"
64" anything to trash the cache like the mq workload might.\n"
65" path Path name of the message queue to create\n"
66"\n"
67" Note: this program must be run as root in order to enable all tests\n"
68"\n";
69
70char *MAX_MSGS = "/proc/sys/fs/mqueue/msg_max";
71char *MAX_MSGSIZE = "/proc/sys/fs/mqueue/msgsize_max";
72
73#define min(a, b) ((a) < (b) ? (a) : (b))
74#define MAX_CPUS 64
75char *cpu_option_string;
76int cpus_to_pin[MAX_CPUS];
77int num_cpus_to_pin;
78pthread_t cpu_threads[MAX_CPUS];
79pthread_t main_thread;
80cpu_set_t *cpu_set;
81int cpu_set_size;
82int cpus_online;
83
84#define MSG_SIZE 16
85#define TEST1_LOOPS 10000000
86#define TEST2_LOOPS 100000
87int continuous_mode;
88int continuous_mode_fake;
89
90struct rlimit saved_limits, cur_limits;
91int saved_max_msgs, saved_max_msgsize;
92int cur_max_msgs, cur_max_msgsize;
93FILE *max_msgs, *max_msgsize;
94int cur_nice;
95char *queue_path = "/mq_perf_tests";
96mqd_t queue = -1;
97struct mq_attr result;
98int mq_prio_max;
99
100const struct poptOption options[] = {
101 {
102 .longName = "continuous",
103 .shortName = 'c',
104 .argInfo = POPT_ARG_STRING,
105 .arg = &cpu_option_string,
106 .val = 'c',
107 .descrip = "Run continuous tests at a high queue depth in "
108 "order to test the effects of cache thrashing on "
109 "other tasks on the system. This test is intended "
110 "to be run on one core of each physical CPU while "
111 "some other CPU intensive task is run on all the other "
112 "cores of that same physical CPU and the other task "
113 "is timed. It is assumed that the process of adding "
114 "messages to the message queue in a tight loop will "
115 "impact that other task to some degree. Once the "
116 "tests are performed in this way, you should then "
117 "re-run the tests using fake mode in order to check "
118 "the difference in time required to perform the CPU "
119 "intensive task",
120 .argDescrip = "cpu[,cpu]",
121 },
122 {
123 .longName = "fake",
124 .shortName = 'f',
125 .argInfo = POPT_ARG_NONE,
126 .arg = &continuous_mode_fake,
127 .val = 0,
128 .descrip = "Tie up the CPUs that we would normally tie up in"
129 "continuous mode, but don't actually do any mq stuff, "
130 "just keep the CPU busy so it can't be used to process "
131 "system level tasks as this would free up resources on "
132 "the other CPU cores and skew the comparison between "
133 "the no-mqueue work and mqueue work tests",
134 .argDescrip = NULL,
135 },
136 {
137 .longName = "path",
138 .shortName = 'p',
139 .argInfo = POPT_ARG_STRING | POPT_ARGFLAG_SHOW_DEFAULT,
140 .arg = &queue_path,
141 .val = 'p',
142 .descrip = "The name of the path to use in the mqueue "
143 "filesystem for our tests",
144 .argDescrip = "pathname",
145 },
146 POPT_AUTOHELP
147 POPT_TABLEEND
148};
149
150static inline void __set(FILE *stream, int value, char *err_msg);
151void shutdown(int exit_val, char *err_cause, int line_no);
152void sig_action_SIGUSR1(int signum, siginfo_t *info, void *context);
153void sig_action(int signum, siginfo_t *info, void *context);
154static inline int get(FILE *stream);
155static inline void set(FILE *stream, int value);
156static inline int try_set(FILE *stream, int value);
157static inline void getr(int type, struct rlimit *rlim);
158static inline void setr(int type, struct rlimit *rlim);
159static inline void open_queue(struct mq_attr *attr);
160void increase_limits(void);
161
162static inline void __set(FILE *stream, int value, char *err_msg)
163{
164 rewind(stream);
165 if (fprintf(stream, "%d", value) < 0)
166 perror(err_msg);
167}
168
169
170void shutdown(int exit_val, char *err_cause, int line_no)
171{
172 static int in_shutdown = 0;
173 int errno_at_shutdown = errno;
174 int i;
175
176 /* In case we get called by multiple threads or from an sighandler */
177 if (in_shutdown++)
178 return;
179
180 for (i = 0; i < num_cpus_to_pin; i++)
181 if (cpu_threads[i]) {
182 pthread_kill(cpu_threads[i], SIGUSR1);
183 pthread_join(cpu_threads[i], NULL);
184 }
185
186 if (queue != -1)
187 if (mq_close(queue))
188 perror("mq_close() during shutdown");
189 if (queue_path)
190 /*
191 * Be silent if this fails, if we cleaned up already it's
192 * expected to fail
193 */
194 mq_unlink(queue_path);
195 if (saved_max_msgs)
196 __set(max_msgs, saved_max_msgs,
197 "failed to restore saved_max_msgs");
198 if (saved_max_msgsize)
199 __set(max_msgsize, saved_max_msgsize,
200 "failed to restore saved_max_msgsize");
201 if (exit_val)
202 error(exit_val, errno_at_shutdown, "%s at %d",
203 err_cause, line_no);
204 exit(0);
205}
206
207void sig_action_SIGUSR1(int signum, siginfo_t *info, void *context)
208{
209 if (pthread_self() != main_thread)
210 pthread_exit(0);
211 else {
212 fprintf(stderr, "Caught signal %d in SIGUSR1 handler, "
213 "exiting\n", signum);
214 shutdown(0, "", 0);
215 fprintf(stderr, "\n\nReturned from shutdown?!?!\n\n");
216 exit(0);
217 }
218}
219
220void sig_action(int signum, siginfo_t *info, void *context)
221{
222 if (pthread_self() != main_thread)
223 pthread_kill(main_thread, signum);
224 else {
225 fprintf(stderr, "Caught signal %d, exiting\n", signum);
226 shutdown(0, "", 0);
227 fprintf(stderr, "\n\nReturned from shutdown?!?!\n\n");
228 exit(0);
229 }
230}
231
232static inline int get(FILE *stream)
233{
234 int value;
235 rewind(stream);
236 if (fscanf(stream, "%d", &value) != 1)
237 shutdown(4, "Error reading /proc entry", __LINE__);
238 return value;
239}
240
241static inline void set(FILE *stream, int value)
242{
243 int new_value;
244
245 rewind(stream);
246 if (fprintf(stream, "%d", value) < 0)
247 return shutdown(5, "Failed writing to /proc file", __LINE__);
248 new_value = get(stream);
249 if (new_value != value)
250 return shutdown(5, "We didn't get what we wrote to /proc back",
251 __LINE__);
252}
253
254static inline int try_set(FILE *stream, int value)
255{
256 int new_value;
257
258 rewind(stream);
259 fprintf(stream, "%d", value);
260 new_value = get(stream);
261 return new_value == value;
262}
263
264static inline void getr(int type, struct rlimit *rlim)
265{
266 if (getrlimit(type, rlim))
267 shutdown(6, "getrlimit()", __LINE__);
268}
269
270static inline void setr(int type, struct rlimit *rlim)
271{
272 if (setrlimit(type, rlim))
273 shutdown(7, "setrlimit()", __LINE__);
274}
275
276/**
277 * open_queue - open the global queue for testing
278 * @attr - An attr struct specifying the desired queue traits
279 * @result - An attr struct that lists the actual traits the queue has
280 *
281 * This open is not allowed to fail, failure will result in an orderly
282 * shutdown of the program. The global queue_path is used to set what
283 * queue to open, the queue descriptor is saved in the global queue
284 * variable.
285 */
286static inline void open_queue(struct mq_attr *attr)
287{
288 int flags = O_RDWR | O_EXCL | O_CREAT | O_NONBLOCK;
289 int perms = DEFFILEMODE;
290
291 queue = mq_open(queue_path, flags, perms, attr);
292 if (queue == -1)
293 shutdown(1, "mq_open()", __LINE__);
294 if (mq_getattr(queue, &result))
295 shutdown(1, "mq_getattr()", __LINE__);
296 printf("\n\tQueue %s created:\n", queue_path);
297 printf("\t\tmq_flags:\t\t\t%s\n", result.mq_flags & O_NONBLOCK ?
298 "O_NONBLOCK" : "(null)");
299 printf("\t\tmq_maxmsg:\t\t\t%d\n", result.mq_maxmsg);
300 printf("\t\tmq_msgsize:\t\t\t%d\n", result.mq_msgsize);
301 printf("\t\tmq_curmsgs:\t\t\t%d\n", result.mq_curmsgs);
302}
303
304void *fake_cont_thread(void *arg)
305{
306 int i;
307
308 for (i = 0; i < num_cpus_to_pin; i++)
309 if (cpu_threads[i] == pthread_self())
310 break;
311 printf("\tStarted fake continuous mode thread %d on CPU %d\n", i,
312 cpus_to_pin[i]);
313 while (1)
314 ;
315}
316
317void *cont_thread(void *arg)
318{
319 char buff[MSG_SIZE];
320 int i, priority;
321
322 for (i = 0; i < num_cpus_to_pin; i++)
323 if (cpu_threads[i] == pthread_self())
324 break;
325 printf("\tStarted continuous mode thread %d on CPU %d\n", i,
326 cpus_to_pin[i]);
327 while (1) {
328 while (mq_send(queue, buff, sizeof(buff), 0) == 0)
329 ;
330 mq_receive(queue, buff, sizeof(buff), &priority);
331 }
332}
333
334#define drain_queue() \
335 while (mq_receive(queue, buff, MSG_SIZE, &prio_in) == MSG_SIZE)
336
337#define do_untimed_send() \
338 do { \
339 if (mq_send(queue, buff, MSG_SIZE, prio_out)) \
340 shutdown(3, "Test send failure", __LINE__); \
341 } while (0)
342
343#define do_send_recv() \
344 do { \
345 clock_gettime(clock, &start); \
346 if (mq_send(queue, buff, MSG_SIZE, prio_out)) \
347 shutdown(3, "Test send failure", __LINE__); \
348 clock_gettime(clock, &middle); \
349 if (mq_receive(queue, buff, MSG_SIZE, &prio_in) != MSG_SIZE) \
350 shutdown(3, "Test receive failure", __LINE__); \
351 clock_gettime(clock, &end); \
352 nsec = ((middle.tv_sec - start.tv_sec) * 1000000000) + \
353 (middle.tv_nsec - start.tv_nsec); \
354 send_total.tv_nsec += nsec; \
355 if (send_total.tv_nsec >= 1000000000) { \
356 send_total.tv_sec++; \
357 send_total.tv_nsec -= 1000000000; \
358 } \
359 nsec = ((end.tv_sec - middle.tv_sec) * 1000000000) + \
360 (end.tv_nsec - middle.tv_nsec); \
361 recv_total.tv_nsec += nsec; \
362 if (recv_total.tv_nsec >= 1000000000) { \
363 recv_total.tv_sec++; \
364 recv_total.tv_nsec -= 1000000000; \
365 } \
366 } while (0)
367
368struct test {
369 char *desc;
370 void (*func)(int *);
371};
372
373void const_prio(int *prio)
374{
375 return;
376}
377
378void inc_prio(int *prio)
379{
380 if (++*prio == mq_prio_max)
381 *prio = 0;
382}
383
384void dec_prio(int *prio)
385{
386 if (--*prio < 0)
387 *prio = mq_prio_max - 1;
388}
389
390void random_prio(int *prio)
391{
392 *prio = random() % mq_prio_max;
393}
394
395struct test test2[] = {
396 {"\n\tTest #2a: Time send/recv message, queue full, constant prio\n",
397 const_prio},
398 {"\n\tTest #2b: Time send/recv message, queue full, increasing prio\n",
399 inc_prio},
400 {"\n\tTest #2c: Time send/recv message, queue full, decreasing prio\n",
401 dec_prio},
402 {"\n\tTest #2d: Time send/recv message, queue full, random prio\n",
403 random_prio},
404 {NULL, NULL}
405};
406
407/**
408 * Tests to perform (all done with MSG_SIZE messages):
409 *
410 * 1) Time to add/remove message with 0 messages on queue
411 * 1a) with constant prio
412 * 2) Time to add/remove message when queue close to capacity:
413 * 2a) with constant prio
414 * 2b) with increasing prio
415 * 2c) with decreasing prio
416 * 2d) with random prio
417 * 3) Test limits of priorities honored (double check _SC_MQ_PRIO_MAX)
418 */
419void *perf_test_thread(void *arg)
420{
421 char buff[MSG_SIZE];
422 int prio_out, prio_in;
423 int i;
424 clockid_t clock;
425 pthread_t *t;
426 struct timespec res, start, middle, end, send_total, recv_total;
427 unsigned long long nsec;
428 struct test *cur_test;
429
430 t = &cpu_threads[0];
431 printf("\n\tStarted mqueue performance test thread on CPU %d\n",
432 cpus_to_pin[0]);
433 mq_prio_max = sysconf(_SC_MQ_PRIO_MAX);
434 if (mq_prio_max == -1)
435 shutdown(2, "sysconf(_SC_MQ_PRIO_MAX)", __LINE__);
436 if (pthread_getcpuclockid(cpu_threads[0], &clock) != 0)
437 shutdown(2, "pthread_getcpuclockid", __LINE__);
438
439 if (clock_getres(clock, &res))
440 shutdown(2, "clock_getres()", __LINE__);
441
442 printf("\t\tMax priorities:\t\t\t%d\n", mq_prio_max);
443 printf("\t\tClock resolution:\t\t%d nsec%s\n", res.tv_nsec,
444 res.tv_nsec > 1 ? "s" : "");
445
446
447
448 printf("\n\tTest #1: Time send/recv message, queue empty\n");
449 printf("\t\t(%d iterations)\n", TEST1_LOOPS);
450 prio_out = 0;
451 send_total.tv_sec = 0;
452 send_total.tv_nsec = 0;
453 recv_total.tv_sec = 0;
454 recv_total.tv_nsec = 0;
455 for (i = 0; i < TEST1_LOOPS; i++)
456 do_send_recv();
457 printf("\t\tSend msg:\t\t\t%d.%ds total time\n",
458 send_total.tv_sec, send_total.tv_nsec);
459 nsec = ((unsigned long long)send_total.tv_sec * 1000000000 +
460 send_total.tv_nsec) / TEST1_LOOPS;
461 printf("\t\t\t\t\t\t%d nsec/msg\n", nsec);
462 printf("\t\tRecv msg:\t\t\t%d.%ds total time\n",
463 recv_total.tv_sec, recv_total.tv_nsec);
464 nsec = ((unsigned long long)recv_total.tv_sec * 1000000000 +
465 recv_total.tv_nsec) / TEST1_LOOPS;
466 printf("\t\t\t\t\t\t%d nsec/msg\n", nsec);
467
468
469 for (cur_test = test2; cur_test->desc != NULL; cur_test++) {
470 printf(cur_test->desc);
471 printf("\t\t(%d iterations)\n", TEST2_LOOPS);
472 prio_out = 0;
473 send_total.tv_sec = 0;
474 send_total.tv_nsec = 0;
475 recv_total.tv_sec = 0;
476 recv_total.tv_nsec = 0;
477 printf("\t\tFilling queue...");
478 fflush(stdout);
479 clock_gettime(clock, &start);
480 for (i = 0; i < result.mq_maxmsg - 1; i++) {
481 do_untimed_send();
482 cur_test->func(&prio_out);
483 }
484 clock_gettime(clock, &end);
485 nsec = ((unsigned long long)(end.tv_sec - start.tv_sec) *
486 1000000000) + (end.tv_nsec - start.tv_nsec);
487 printf("done.\t\t%lld.%llds\n", nsec / 1000000000,
488 nsec % 1000000000);
489 printf("\t\tTesting...");
490 fflush(stdout);
491 for (i = 0; i < TEST2_LOOPS; i++) {
492 do_send_recv();
493 cur_test->func(&prio_out);
494 }
495 printf("done.\n");
496 printf("\t\tSend msg:\t\t\t%d.%ds total time\n",
497 send_total.tv_sec, send_total.tv_nsec);
498 nsec = ((unsigned long long)send_total.tv_sec * 1000000000 +
499 send_total.tv_nsec) / TEST2_LOOPS;
500 printf("\t\t\t\t\t\t%d nsec/msg\n", nsec);
501 printf("\t\tRecv msg:\t\t\t%d.%ds total time\n",
502 recv_total.tv_sec, recv_total.tv_nsec);
503 nsec = ((unsigned long long)recv_total.tv_sec * 1000000000 +
504 recv_total.tv_nsec) / TEST2_LOOPS;
505 printf("\t\t\t\t\t\t%d nsec/msg\n", nsec);
506 printf("\t\tDraining queue...");
507 fflush(stdout);
508 clock_gettime(clock, &start);
509 drain_queue();
510 clock_gettime(clock, &end);
511 nsec = ((unsigned long long)(end.tv_sec - start.tv_sec) *
512 1000000000) + (end.tv_nsec - start.tv_nsec);
513 printf("done.\t\t%lld.%llds\n", nsec / 1000000000,
514 nsec % 1000000000);
515 }
516 return 0;
517}
518
519void increase_limits(void)
520{
521 cur_limits.rlim_cur = RLIM_INFINITY;
522 cur_limits.rlim_max = RLIM_INFINITY;
523 setr(RLIMIT_MSGQUEUE, &cur_limits);
524 while (try_set(max_msgs, cur_max_msgs += 10))
525 ;
526 cur_max_msgs = get(max_msgs);
527 while (try_set(max_msgsize, cur_max_msgsize += 1024))
528 ;
529 cur_max_msgsize = get(max_msgsize);
530 if (setpriority(PRIO_PROCESS, 0, -20) != 0)
531 shutdown(2, "setpriority()", __LINE__);
532 cur_nice = -20;
533}
534
535int main(int argc, char *argv[])
536{
537 struct mq_attr attr;
538 char *option, *next_option;
539 int i, cpu;
540 struct sigaction sa;
541 poptContext popt_context;
542 char rc;
543 void *retval;
544
545 main_thread = pthread_self();
546 num_cpus_to_pin = 0;
547
548 if (sysconf(_SC_NPROCESSORS_ONLN) == -1) {
549 perror("sysconf(_SC_NPROCESSORS_ONLN)");
550 exit(1);
551 }
552 cpus_online = min(MAX_CPUS, sysconf(_SC_NPROCESSORS_ONLN));
553 cpu_set = CPU_ALLOC(cpus_online);
554 if (cpu_set == NULL) {
555 perror("CPU_ALLOC()");
556 exit(1);
557 }
558 cpu_set_size = CPU_ALLOC_SIZE(cpus_online);
559 CPU_ZERO_S(cpu_set_size, cpu_set);
560
561 popt_context = poptGetContext(NULL, argc, (const char **)argv,
562 options, 0);
563
564 while ((rc = poptGetNextOpt(popt_context)) > 0) {
565 switch (rc) {
566 case 'c':
567 continuous_mode = 1;
568 option = cpu_option_string;
569 do {
570 next_option = strchr(option, ',');
571 if (next_option)
572 *next_option = '\0';
573 cpu = atoi(option);
574 if (cpu >= cpus_online)
575 fprintf(stderr, "CPU %d exceeds "
576 "cpus online, ignoring.\n",
577 cpu);
578 else
579 cpus_to_pin[num_cpus_to_pin++] = cpu;
580 if (next_option)
581 option = ++next_option;
582 } while (next_option && num_cpus_to_pin < MAX_CPUS);
583 /* Double check that they didn't give us the same CPU
584 * more than once */
585 for (cpu = 0; cpu < num_cpus_to_pin; cpu++) {
586 if (CPU_ISSET_S(cpus_to_pin[cpu], cpu_set_size,
587 cpu_set)) {
588 fprintf(stderr, "Any given CPU may "
589 "only be given once.\n");
590 exit(1);
591 } else
592 CPU_SET_S(cpus_to_pin[cpu],
593 cpu_set_size, cpu_set);
594 }
595 break;
596 case 'p':
597 /*
598 * Although we can create a msg queue with a
599 * non-absolute path name, unlink will fail. So,
600 * if the name doesn't start with a /, add one
601 * when we save it.
602 */
603 option = queue_path;
604 if (*option != '/') {
605 queue_path = malloc(strlen(option) + 2);
606 if (!queue_path) {
607 perror("malloc()");
608 exit(1);
609 }
610 queue_path[0] = '/';
611 queue_path[1] = 0;
612 strcat(queue_path, option);
613 free(option);
614 }
615 break;
616 }
617 }
618
619 if (continuous_mode && num_cpus_to_pin == 0) {
620 fprintf(stderr, "Must pass at least one CPU to continuous "
621 "mode.\n");
622 poptPrintUsage(popt_context, stderr, 0);
623 exit(1);
624 } else if (!continuous_mode) {
625 num_cpus_to_pin = 1;
626 cpus_to_pin[0] = cpus_online - 1;
627 }
628
629 if (getuid() != 0) {
630 fprintf(stderr, "Not running as root, but almost all tests "
631 "require root in order to modify\nsystem settings. "
632 "Exiting.\n");
633 exit(1);
634 }
635
636 max_msgs = fopen(MAX_MSGS, "r+");
637 max_msgsize = fopen(MAX_MSGSIZE, "r+");
638 if (!max_msgs)
639 shutdown(2, "Failed to open msg_max", __LINE__);
640 if (!max_msgsize)
641 shutdown(2, "Failed to open msgsize_max", __LINE__);
642
643 /* Load up the current system values for everything we can */
644 getr(RLIMIT_MSGQUEUE, &saved_limits);
645 cur_limits = saved_limits;
646 saved_max_msgs = cur_max_msgs = get(max_msgs);
647 saved_max_msgsize = cur_max_msgsize = get(max_msgsize);
648 errno = 0;
649 cur_nice = getpriority(PRIO_PROCESS, 0);
650 if (errno)
651 shutdown(2, "getpriority()", __LINE__);
652
653 /* Tell the user our initial state */
654 printf("\nInitial system state:\n");
655 printf("\tUsing queue path:\t\t\t%s\n", queue_path);
656 printf("\tRLIMIT_MSGQUEUE(soft):\t\t\t%d\n", saved_limits.rlim_cur);
657 printf("\tRLIMIT_MSGQUEUE(hard):\t\t\t%d\n", saved_limits.rlim_max);
658 printf("\tMaximum Message Size:\t\t\t%d\n", saved_max_msgsize);
659 printf("\tMaximum Queue Size:\t\t\t%d\n", saved_max_msgs);
660 printf("\tNice value:\t\t\t\t%d\n", cur_nice);
661 printf("\n");
662
663 increase_limits();
664
665 printf("Adjusted system state for testing:\n");
666 if (cur_limits.rlim_cur == RLIM_INFINITY) {
667 printf("\tRLIMIT_MSGQUEUE(soft):\t\t\t(unlimited)\n");
668 printf("\tRLIMIT_MSGQUEUE(hard):\t\t\t(unlimited)\n");
669 } else {
670 printf("\tRLIMIT_MSGQUEUE(soft):\t\t\t%d\n",
671 cur_limits.rlim_cur);
672 printf("\tRLIMIT_MSGQUEUE(hard):\t\t\t%d\n",
673 cur_limits.rlim_max);
674 }
675 printf("\tMaximum Message Size:\t\t\t%d\n", cur_max_msgsize);
676 printf("\tMaximum Queue Size:\t\t\t%d\n", cur_max_msgs);
677 printf("\tNice value:\t\t\t\t%d\n", cur_nice);
678 printf("\tContinuous mode:\t\t\t(%s)\n", continuous_mode ?
679 (continuous_mode_fake ? "fake mode" : "enabled") :
680 "disabled");
681 printf("\tCPUs to pin:\t\t\t\t%d", cpus_to_pin[0]);
682 for (cpu = 1; cpu < num_cpus_to_pin; cpu++)
683 printf(",%d", cpus_to_pin[cpu]);
684 printf("\n");
685
686 sa.sa_sigaction = sig_action_SIGUSR1;
687 sigemptyset(&sa.sa_mask);
688 sigaddset(&sa.sa_mask, SIGHUP);
689 sigaddset(&sa.sa_mask, SIGINT);
690 sigaddset(&sa.sa_mask, SIGQUIT);
691 sigaddset(&sa.sa_mask, SIGTERM);
692 sa.sa_flags = SA_SIGINFO;
693 if (sigaction(SIGUSR1, &sa, NULL) == -1)
694 shutdown(1, "sigaction(SIGUSR1)", __LINE__);
695 sa.sa_sigaction = sig_action;
696 if (sigaction(SIGHUP, &sa, NULL) == -1)
697 shutdown(1, "sigaction(SIGHUP)", __LINE__);
698 if (sigaction(SIGINT, &sa, NULL) == -1)
699 shutdown(1, "sigaction(SIGINT)", __LINE__);
700 if (sigaction(SIGQUIT, &sa, NULL) == -1)
701 shutdown(1, "sigaction(SIGQUIT)", __LINE__);
702 if (sigaction(SIGTERM, &sa, NULL) == -1)
703 shutdown(1, "sigaction(SIGTERM)", __LINE__);
704
705 if (!continuous_mode_fake) {
706 attr.mq_flags = O_NONBLOCK;
707 attr.mq_maxmsg = cur_max_msgs;
708 attr.mq_msgsize = MSG_SIZE;
709 open_queue(&attr);
710 }
711 for (i = 0; i < num_cpus_to_pin; i++) {
712 pthread_attr_t thread_attr;
713 void *thread_func;
714
715 if (continuous_mode_fake)
716 thread_func = &fake_cont_thread;
717 else if (continuous_mode)
718 thread_func = &cont_thread;
719 else
720 thread_func = &perf_test_thread;
721
722 CPU_ZERO_S(cpu_set_size, cpu_set);
723 CPU_SET_S(cpus_to_pin[i], cpu_set_size, cpu_set);
724 pthread_attr_init(&thread_attr);
725 pthread_attr_setaffinity_np(&thread_attr, cpu_set_size,
726 cpu_set);
727 if (pthread_create(&cpu_threads[i], &thread_attr, thread_func,
728 NULL))
729 shutdown(1, "pthread_create()", __LINE__);
730 pthread_attr_destroy(&thread_attr);
731 }
732
733 if (!continuous_mode) {
734 pthread_join(cpu_threads[0], &retval);
735 shutdown((long)retval, "perf_test_thread()", __LINE__);
736 } else {
737 while (1)
738 sleep(1);
739 }
740 shutdown(0, "", 0);
741}
diff --git a/usr/Kconfig b/usr/Kconfig
index 65b845bd4e3e..085872bb2bb5 100644
--- a/usr/Kconfig
+++ b/usr/Kconfig
@@ -134,7 +134,7 @@ config INITRAMFS_COMPRESSION_BZIP2
134 depends on RD_BZIP2 134 depends on RD_BZIP2
135 help 135 help
136 Its compression ratio and speed is intermediate. 136 Its compression ratio and speed is intermediate.
137 Decompression speed is slowest among the four. The initramfs 137 Decompression speed is slowest among the choices. The initramfs
138 size is about 10% smaller with bzip2, in comparison to gzip. 138 size is about 10% smaller with bzip2, in comparison to gzip.
139 Bzip2 uses a large amount of memory. For modern kernels you 139 Bzip2 uses a large amount of memory. For modern kernels you
140 will need at least 8MB RAM or more for booting. 140 will need at least 8MB RAM or more for booting.
@@ -143,9 +143,9 @@ config INITRAMFS_COMPRESSION_LZMA
143 bool "LZMA" 143 bool "LZMA"
144 depends on RD_LZMA 144 depends on RD_LZMA
145 help 145 help
146 The most recent compression algorithm. 146 This algorithm's compression ratio is best.
147 Its ratio is best, decompression speed is between the other 147 Decompression speed is between the other choices.
148 three. Compression is slowest. The initramfs size is about 33% 148 Compression is slowest. The initramfs size is about 33%
149 smaller with LZMA in comparison to gzip. 149 smaller with LZMA in comparison to gzip.
150 150
151config INITRAMFS_COMPRESSION_XZ 151config INITRAMFS_COMPRESSION_XZ
@@ -161,7 +161,7 @@ config INITRAMFS_COMPRESSION_LZO
161 bool "LZO" 161 bool "LZO"
162 depends on RD_LZO 162 depends on RD_LZO
163 help 163 help
164 Its compression ratio is the poorest among the four. The kernel 164 Its compression ratio is the poorest among the choices. The kernel
165 size is about 10% bigger than gzip; however its speed 165 size is about 10% bigger than gzip; however its speed
166 (both compression and decompression) is the fastest. 166 (both compression and decompression) is the fastest.
167 167